Skip to content

fix(security): stop delayed and additional tool callbacks after cancellation - #2430

Open
HAYDEN-OAI wants to merge 1 commit into
mainfrom
autoimprove/runtools-cancelled-callbacks-20260820-0311-856743
Open

fix(security): stop delayed and additional tool callbacks after cancellation#2430
HAYDEN-OAI wants to merge 1 commit into
mainfrom
autoimprove/runtools-cancelled-callbacks-20260820-0311-856743

Conversation

@HAYDEN-OAI

Copy link
Copy Markdown
Contributor

Summary

  • Prevent chat.completions.runTools() from starting a privileged parsed tool callback after cancellation occurs during asynchronous argument parsing.
  • Prevent cancellation from starting the next sequential or later parallel tool callback, for both non-streaming and streaming runners and both external abort signals and runner.abort().
  • Surface the existing public APIUserAbortError, wait for callbacks that were already running, and retain results/messages for callbacks that began before cancellation.
  • Preserve the SDK's documented completed-buffered-turn compatibility contract: when a completed response is already buffered as cancellation becomes visible, its first immediate, non-parsing callback may still run. This exception is consumed once, never permits an asynchronously parsed callback, and never permits a second callback.

Regression-first proof

Before the change, the new real-public-client suite produced 10 failing security cases and 6 passing compatibility controls: synthetic privileged transfer callbacks ran with the runner signal already aborted. The final 20-case suite covers non-streaming and streaming public clients, external abort signals and direct runner cancellation, delayed parsers, sequential callbacks, in-flight parallel callback completion, one-shot buffered-turn compatibility, context, parser feedback, and afterCompletion.

Verification

  • Focused public runner coverage: 58 tests passed (20 new security/compatibility cases plus all 38 existing runner cases).
  • Complete handwritten suite: 127 files / 4,064 tests passed.
  • Complete generated suite against an isolated private-port Steady server: 82 suites / 559 tests passed.
  • Repository formatting and all 415 lint rules passed.
  • Strict source TypeScript checking and the complete CJS/ESM package build passed.
  • Published-source type checking passed with TypeScript 4.9 and TypeScript 6.
  • publint passed with only the pre-existing vendor-export warning.
  • Packed artifact checks passed across 1,216 source maps and 267 browser-safe mapped sources.
  • Built-distribution public smoke checks passed for non-streaming and streaming runners, covering both delayed parsing and cancellation between sequential callbacks.

@HAYDEN-OAI
HAYDEN-OAI requested a review from a team as a code owner August 20, 2026 03:16
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-20T03:19:02.179625Z 20219f5 PR opened
🔒 Security Review Completed 2026-08-20T03:18:34.683736Z 20219f5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openai-sdks

openai-sdks Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

237/237 SDK tests passed in 11.362s for Node SDK PR #2430.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 180ms
tests/chat-completions-create.test.ts ✅ Passed 288ms
tests/chat-completions-stream.test.ts ✅ Passed 226ms
tests/files-content-binary.test.ts ✅ Passed 211ms
tests/files-create-multipart.test.ts ✅ Passed 193ms
tests/files-list-pagination.test.ts ✅ Passed 151ms
tests/initialize-config.test.ts ✅ Passed 166ms
tests/instance-isolation.test.ts ✅ Passed 122ms
tests/models-list.test.ts ✅ Passed 152ms
tests/responses-background-lifecycle.test.ts ✅ Passed 280ms
tests/responses-body-method-errors.test.ts ✅ Passed 390ms
tests/responses-cancel-timeout.test.ts ✅ Passed 239ms
tests/responses-cancel.test.ts ✅ Passed 243ms
tests/responses-compact-retries.test.ts ✅ Passed 323ms
tests/responses-compact.test.ts ✅ Passed 265ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 168ms
tests/responses-create-advanced.test.ts ✅ Passed 195ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.112s
tests/responses-create-errors.test.ts ✅ Passed 297ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 188ms
tests/responses-create-retries.test.ts ✅ Passed 313ms
tests/responses-create-stream-failures.test.ts ✅ Passed 196ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.165s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.569s
tests/responses-create-stream.test.ts ✅ Passed 119ms
tests/responses-create-terminal-states.test.ts ✅ Passed 379ms
tests/responses-create-timeout.test.ts ✅ Passed 275ms
tests/responses-create.test.ts ✅ Passed 284ms
tests/responses-delete.test.ts ✅ Passed 251ms
tests/responses-input-items-errors.test.ts ✅ Passed 217ms
tests/responses-input-items-list.test.ts ✅ Passed 175ms
tests/responses-input-items-options.test.ts ✅ Passed 196ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 261ms
tests/responses-input-tokens-count.test.ts ✅ Passed 319ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.182s
tests/responses-not-found-errors.test.ts ✅ Passed 327ms
tests/responses-parse.test.ts ✅ Passed 295ms
tests/responses-retrieve-retries.test.ts ✅ Passed 312ms
tests/responses-retrieve.test.ts ✅ Passed 286ms
tests/responses-stored-method-errors.test.ts ✅ Passed 712ms
tests/retry-behavior.test.ts ✅ Passed 2.981s
tests/sdk-error-shape.test.ts ✅ Passed 363ms

View OkTest run #32327621883

SDK merge (f87dd41a2eda) · head (20219f5f6136) · base (a0d68cc53125) · OkTest (2b1bdfd25e98)

@github-actions

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

34 mixed files remain; 0 existing customizations changed.

Compared a0d68cc5312520219f5f6136. Generated baselines verified.

34 existing customizations unchanged
  • api.md
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py
  • src/client.ts
  • src/resources/audio/transcriptions.ts
  • src/resources/audio/translations.ts
  • src/resources/beta/assistants.ts
  • src/resources/beta/beta.ts
  • src/resources/beta/index.ts
  • src/resources/beta/responses/internal-base.ts
  • src/resources/beta/responses/responses.ts
  • src/resources/beta/threads/index.ts
  • src/resources/beta/threads/runs/index.ts
  • src/resources/beta/threads/runs/runs.ts
  • src/resources/beta/threads/threads.ts
  • src/resources/chat/completions/completions.ts
  • src/resources/chat/completions/index.ts
  • src/resources/conversations/index.ts
  • src/resources/embeddings.ts
  • src/resources/files.ts
  • src/resources/fine-tuning/checkpoints/permissions.ts
  • src/resources/images.ts
  • src/resources/responses/internal-base.ts
  • src/resources/responses/responses.ts
  • src/resources/skills/skills.ts
  • src/resources/skills/versions/versions.ts
  • src/resources/vector-stores/file-batches.ts
  • src/resources/vector-stores/files.ts
  • src/resources/webhooks/index.ts
  • src/resources/webhooks/webhooks.ts
  • tests/api-resources/embeddings.test.ts
  • tests/api-resources/responses/responses.test.ts
  • tests/lib/data-residency.test.ts

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 32327620158 --repo openai/openai-node \
  --name castiron-custom-code-32327620158-1 --dir /tmp/castiron-custom-code-32327620158-1
git apply --stat /tmp/castiron-custom-code-32327620158-1/custom-code.patch
cat /tmp/castiron-custom-code-32327620158-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin a0d68cc53125c2cb82eab31271b8984b8d65d4b2 20219f5f6136a804a776a49a29ce8e31092092a6
python3 scripts/castiron/custom_code_report.py report \
  --base a0d68cc53125c2cb82eab31271b8984b8d65d4b2 \
  --head 20219f5f6136a804a776a49a29ce8e31092092a6 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-20219f5f6136
cat /tmp/castiron-custom-code-20219f5f6136/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 20219f5f61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +482 to +483
if (this.controller.signal.aborted) {
throw new APIUserAbortError();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check cancellation before returning parser errors

When an asynchronous fn.parse() rejects after the runner is aborted, the catch returns ordinary tool feedback before reaching this abort check. With maxChatCompletions: 1, the loop then exhausts normally (and can invoke afterCompletion), so runner.done() resolves and runner.aborted remains false despite cancellation. Check the signal in the rejection path before converting the parser error into a tool message.

AGENTS.md reference: AGENTS.md:L109-L113

Useful? React with 👍 / 👎.

Comment on lines +508 to +510
// A completed buffered turn retains its first immediate callback for
// compatibility; delayed parsed callbacks never inherit this exception.
allowBufferedToolCall = this.controller.signal.aborted;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not treat post-abort responses as buffered

If a supported custom fetch transport ignores its signal and returns a response after cancellation, this assignment still enables the buffered-turn exception solely because the signal is now aborted. The first immediate tool function then runs after cancellation even though its response was not completed before the abort. Track the actual completion-versus-abort ordering rather than inferring that every completion observed with an aborted signal was already buffered.

AGENTS.md reference: AGENTS.md:L109-L113

Useful? React with 👍 / 👎.

Comment on lines +487 to +489
if (this.controller.signal.aborted && !bufferedToolCall) {
throw new APIUserAbortError();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Surface aborts that occur during the final callback

This guard only observes cancellation before invoking the tool. If cancellation occurs while an already-started callback is pending and the callback then resolves, a forced single-function tool_choice takes the functionCalled early-return path (and the final maxChatCompletions iteration behaves similarly), causing afterCompletion to run and runner.done() to resolve with runner.aborted === false. Retain the completed callback result as intended, but recheck the signal before any successful loop termination.

AGENTS.md reference: AGENTS.md:L109-L113

Useful? React with 👍 / 👎.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent two-pass security review validates the three existing cancellation findings, including a High post-abort callback bypass, and identifies one additional Medium result-preservation regression documented inline.

return { message: { role, tool_call_id, content }, functionCalled: false };
}
if (this.controller.signal.aborted) {
throw new APIUserAbortError();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] Preserve already-completed parallel tool results before propagating cancellation. This new abort rejection makes the parallel Promise.allSettled path throw on its rejected result before appending fulfilled callbacks' messages. Consequently a callback that already performed an irreversible side effect disappears from runner.messages, violating the stated preservation guarantee for both streaming and non-streaming runners. Record completed results in input order before surfacing the abort, and extend the parallel-cancellation regression to assert the completed tool result remains visible without starting further callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants