Skip to content

fix(examples): preserve background stream resume cursors - #2671

Merged
HAYDEN-OAI merged 1 commit into
mainfrom
codex/background-example-resume-cursor
Sep 7, 2026
Merged

fix(examples): preserve background stream resume cursors#2671
HAYDEN-OAI merged 1 commit into
mainfrom
codex/background-example-resume-cursor

Conversation

@HAYDEN-OAI

Copy link
Copy Markdown
Contributor

Summary

  • Resume the background-streaming example after the last event actually observed, matching the existing streaming guide, instead of always using starting_after: 10.
  • Keep the deliberate interruption at event 10, completion handling, failure exit codes, request counts, and final response behavior unchanged.
  • Strengthen the existing test fixture to check complete, ordered, duplicate-free event output. No SDK, generated code, parser, model, dependency, or documentation changes.

Reproduction

When the first connection ends cleanly after event 3 and the replay contains events 0–12, the current example prints events 0, 1, 2, 3, 11, 12. Its hard-coded cursor suppresses unseen text deltas 4–10. An interruption immediately after response.created similarly skips events 1–10.

The SDK still replays all events internally and produces a complete final response. This is an example-level event-continuity bug, not lost final-response data or a problem with the SDK accumulator. Tracking the last observed sequence uses the same small pattern already documented in docs/streaming.md.

Validation

  • Before the source change, three early-EOF example regressions fail while 31 existing controls pass. All 34 cases pass afterward on exact Node 22.0.0, Node 24.19.0, and Node 26.7.0.
  • The first response now ends before both its final text delta and terminal event, so a complete final snapshot alone cannot make the regression pass. The test also checks exact event order and absence of duplicates.
  • Execute the actual example against the built public SDK in nine loopback scenarios on each runtime: 27 checks pass. Early interruption, the intentional cutoff, completion before/at the cutoff, and initial/resumed failure cases retain their expected requests, exit codes, and complete successful final snapshots.
  • Independent adversarial review verifies empty-stream/missing-ID behavior and finds no remaining issues. Its forced-color test exposed a fixture assumption; clearing inherited FORCE_COLOR in the child makes all 34 cases pass with a forced-color parent without adding an ANSI parser.
  • Full canonical handwritten suite: 7,884 tests pass across 208 files. CJS/ESM build and imports, formatting/lint, pinned TypeScript 6, and whitespace checks pass.

The generated suite and remaining ecosystem/packaging checks run in CI. This is separate from the completion-reuse and final-status fixes in #2557 and #2600.

@HAYDEN-OAI
HAYDEN-OAI requested a review from a team as a code owner September 7, 2026 00:56
@openai-sdks

openai-sdks Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

237/237 SDK tests passed in 10.358s for Node SDK PR #2671.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 144ms
tests/chat-completions-create.test.ts ✅ Passed 262ms
tests/chat-completions-stream.test.ts ✅ Passed 163ms
tests/files-content-binary.test.ts ✅ Passed 134ms
tests/files-create-multipart.test.ts ✅ Passed 172ms
tests/files-list-pagination.test.ts ✅ Passed 162ms
tests/initialize-config.test.ts ✅ Passed 170ms
tests/instance-isolation.test.ts ✅ Passed 98ms
tests/models-list.test.ts ✅ Passed 138ms
tests/responses-background-lifecycle.test.ts ✅ Passed 224ms
tests/responses-body-method-errors.test.ts ✅ Passed 284ms
tests/responses-cancel-timeout.test.ts ✅ Passed 221ms
tests/responses-cancel.test.ts ✅ Passed 288ms
tests/responses-compact-retries.test.ts ✅ Passed 286ms
tests/responses-compact.test.ts ✅ Passed 280ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 108ms
tests/responses-create-advanced.test.ts ✅ Passed 192ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.138s
tests/responses-create-errors.test.ts ✅ Passed 203ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 132ms
tests/responses-create-retries.test.ts ✅ Passed 251ms
tests/responses-create-stream-failures.test.ts ✅ Passed 193ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.163s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.491s
tests/responses-create-stream.test.ts ✅ Passed 88ms
tests/responses-create-terminal-states.test.ts ✅ Passed 262ms
tests/responses-create-timeout.test.ts ✅ Passed 216ms
tests/responses-create.test.ts ✅ Passed 184ms
tests/responses-delete.test.ts ✅ Passed 187ms
tests/responses-input-items-errors.test.ts ✅ Passed 163ms
tests/responses-input-items-list.test.ts ✅ Passed 175ms
tests/responses-input-items-options.test.ts ✅ Passed 123ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 238ms
tests/responses-input-tokens-count.test.ts ✅ Passed 196ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.171s
tests/responses-not-found-errors.test.ts ✅ Passed 238ms
tests/responses-parse.test.ts ✅ Passed 245ms
tests/responses-retrieve-retries.test.ts ✅ Passed 273ms
tests/responses-retrieve.test.ts ✅ Passed 249ms
tests/responses-stored-method-errors.test.ts ✅ Passed 545ms
tests/retry-behavior.test.ts ✅ Passed 3.108s
tests/sdk-error-shape.test.ts ✅ Passed 270ms

View OkTest run #34071411342

SDK merge (1e8b54228bff) · head (bcb1378d7f87) · base (fdb038e21509) · OkTest (2b1bdfd25e98)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 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-09-07T00:58:37.478958Z bcb1378 PR opened
🔒 Security Review Completed 2026-09-07T01:00:23.811194Z bcb1378 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.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

32 mixed files remain; 0 existing customizations changed.

Compared fdb038e21509bcb1378d7f87. Generated baselines verified.

32 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/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 34071425990 --repo openai/openai-node \
  --name castiron-custom-code-34071425990-1 --dir /tmp/castiron-custom-code-34071425990-1
git apply --stat /tmp/castiron-custom-code-34071425990-1/custom-code.patch
cat /tmp/castiron-custom-code-34071425990-1/custom-code.patch

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

git fetch --no-tags origin fdb038e21509264bcdf81741a40988dd694188b1 bcb1378d7f8722ecb7530797865c40fddbf730a3
python3 scripts/castiron/custom_code_report.py report \
  --base fdb038e21509264bcdf81741a40988dd694188b1 \
  --head bcb1378d7f8722ecb7530797865c40fddbf730a3 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-bcb1378d7f87
cat /tmp/castiron-custom-code-bcb1378d7f87/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

@markstuart-oai markstuart-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.

Reviewed bcb1378 against fdb038e. No substantive correctness or maintainability findings.

The caller-owned cursor matches docs/streaming.md and records consumed events rather than SDK read-ahead. Independently reproduced the distinction: after EOF at event 3, the base example prints 0,1,2,3,11,12 while this head prints 0–12; both retain complete final text because the helper accumulates the full replay before filtering emission. The direct cursor update is the simplest fit here, without new branches or abstractions.

Validation I executed: 185 focused example/ResponseStream/accumulator tests; all 34 fixture cases again with FORCE_COLOR=1; 38 independent base/head loopback checks on each of Node 22.0.0, 24.20.0, and 26.7.0. These cover cutoff/early EOF, ordered duplicate-free events, completion reuse, final snapshots, request counts, failed/incomplete responses, empty/missing-ID streams, SSE errors, and socket failures. CJS/ESM build/imports, repository lint/format, TypeScript 6, and diff whitespace checks passed.

Validation limits: registry installation failed, so checks used an isolated dependency copy from a checkout with an identical lockfile. No live API, full generated suite, or ecosystem matrix was run.

@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.

Reviewed exact head bcb1378. Tracking the last sequence number actually delivered to the caller and resuming after it fixes the hard-coded cursor gap without changing terminal handling or final response accumulation. The regression now disconnects before the final delta and asserts the complete ordered sequence set; CI is green and there are no unresolved threads. No in-scope findings.

@HAYDEN-OAI
HAYDEN-OAI added this pull request to the merge queue Sep 7, 2026
Merged via the queue into main with commit b7398e3 Sep 7, 2026
38 checks passed
@HAYDEN-OAI
HAYDEN-OAI deleted the codex/background-example-resume-cursor branch September 7, 2026 18:08
@openai-sdks openai-sdks Bot mentioned this pull request Sep 7, 2026
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.

3 participants