Conversation
🦋 Changeset detectedLatest commit: 4c100ce The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe SDK now persists stopped-turn boundaries, recovery input sequences, abandoned-turn state, and transcript-reload state. Stop and abort handling preserves successor output and limits state changes to the active session and stream. Message, action, steering, and reconnect operations remain blocked until valid transcript recovery. Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to Concurrent chat sends can resume streaming while stopped-turn recovery is required, risking an incorrectly correlated transcript. Recheck readiness after correlation before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 8 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Preserve indeterminate recovery state after a transient stream error. · chat.ts:2593-2595
packages/trigger-sdk/src/v3/chat.ts:2593-2595
🩺 Stability & Availability | 🟠 Major | ⚡ Quick winPreserve indeterminate recovery state after a transient stream error.
prepareTranscriptRecoverysetsisStreamingtoundefinedwhile accepted output can still be pending. A connection or read error then sets it tofalse. The nextreconnectToStreamcall returnsnull, so the client cannot recover that output.Keep
isStreamingundefined when a recovery stream fails before it receives a record. Set it to false only after a settled response or turn completion.Proposed fix
if (this.activeStreams.get(chatId) === internalAbort) { - state.isStreaming = false; + if (!(state.skipSettledPeek && state.isStreaming === undefined)) { + state.isStreaming = false; + } this.notifySessionChange(chatId, state); }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: d00b5b24-65ec-4cde-a80c-1031a1b722a7
📒 Files selected for processing (7)
.changeset/chat-stop-successor-boundary.mdpackages/trigger-sdk/src/v3/chat-react.tspackages/trigger-sdk/src/v3/chat-stop.test.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/test/chat-turn-correlation.test.tspackages/trigger-sdk/test/use-load-transcript.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- .changeset/chat-stop-successor-boundary.md
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📜 Review details
⏰ Context from checks skipped due to timeout. (38)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (11, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (22, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (16, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (15, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (19, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (20, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (13, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (18, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (12, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (24, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (23, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (21, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (14, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (17, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 24)
- GitHub Check: sdk-compat / Bun Runtime
- GitHub Check: sdk-compat / Node.js 26.4 (warp-ubuntu-latest-x64-4x)
- GitHub Check: internal / 🧪 Unit Tests: Internal (1)
- GitHub Check: packages / 🧪 Unit Tests: Packages (1, 3)
- GitHub Check: internal / 🧪 Unit Tests: Internal (2)
- GitHub Check: packages / 🧪 Unit Tests: Packages (3, 3)
- GitHub Check: packages / 🧪 Unit Tests: Packages (2, 3)
- GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (2, 2)
- GitHub Check: sdk-compat / Deno Runtime
- GitHub Check: sdk-compat / Cloudflare Workers
- GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (1, 2)
- GitHub Check: fk-cascade-guard / fk-cascade-guard
- GitHub Check: code-quality / code-quality
- GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
📓 Path-based instructions (7)
**Public packages** (`packages/*`): Use `build`.
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/trigger-sdk/test/chat-turn-correlation.test.tspackages/trigger-sdk/src/v3/chat-react.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/test/use-load-transcript.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
Always import from `@trigger.dev/sdk`.
📄 CodeRabbit inference engine (packages/trigger-sdk/CLAUDE.md)
Files:
packages/trigger-sdk/test/chat-turn-correlation.test.tspackages/trigger-sdk/src/v3/chat-react.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/test/use-load-transcript.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
In the Trigger.dev SDK (packages/trigger-sdk), prefer isomorphic code like fetch and ReadableStream instead of Node.js-specific code
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/test/chat-turn-correlation.test.tspackages/trigger-sdk/src/v3/chat-react.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/test/use-load-transcript.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
Use vitest for all tests in the Trigger.dev repository
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/test/chat-turn-correlation.test.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/test/use-load-transcript.test.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
Use function declarations instead of default exports
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/test/chat-turn-correlation.test.tspackages/trigger-sdk/src/v3/chat-react.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/test/use-load-transcript.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
Use types over interfaces for TypeScript Avoid using enums; prefer string unions or const objects instead
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/test/chat-turn-correlation.test.tspackages/trigger-sdk/src/v3/chat-react.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/test/use-load-transcript.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs Do not use high-cardinality attributes in OTEL metr...
📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)
Files:
packages/trigger-sdk/test/chat-turn-correlation.test.tspackages/trigger-sdk/src/v3/chat-react.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/test/use-load-transcript.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
🧠 Learnings (1)
📚 Learning: 2026-06-23T13:04:21.413Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4023
File: apps/webapp/app/services/upsertBranch.server.ts:14-18
Timestamp: 2026-06-23T13:04:21.413Z
Learning: In TypeScript, it’s valid to `import { type X }` and then use `typeof X` in a type-only position, e.g. `type Alias = z.infer<typeof X>`. The `type` modifier suppresses the runtime import, but the type checker still has the full exported type so `z.infer<typeof X>` can resolve correctly. In code reviews, don’t flag this as a TypeScript compile error as long as `typeof X` is used in a type context (e.g., with `z.infer`, `type` aliases, generics), not as a runtime value.
Applied to files:
packages/trigger-sdk/test/use-load-transcript.test.ts
🔇 Additional comments (5)
packages/trigger-sdk/test/chat-turn-correlation.test.ts (1)
123-124: LGTM!packages/trigger-sdk/src/v3/chat.test.ts (1)
1441-1444: LGTM!packages/trigger-sdk/src/v3/chat-stop.test.ts (1)
59-70: LGTM!Also applies to: 77-77, 82-83, 112-112, 117-118, 137-156, 199-216, 266-288, 290-303, 305-318, 320-339, 511-522, 524-553, 555-580, 582-608, 610-636, 638-652, 654-680
packages/trigger-sdk/test/use-load-transcript.test.ts (1)
2-2: LGTM!Also applies to: 59-172
packages/trigger-sdk/src/v3/chat-react.ts (1)
68-69: LGTM!Also applies to: 82-83, 88-89, 92-92, 138-138, 147-157, 175-175
| if ( | ||
| !state.outstandingTurnAbandoned && | ||
| (state.isStreaming || state.activeInputSeq !== undefined) | ||
| (state.isStreaming !== false || state.activeInputSeq !== undefined) | ||
| ) { | ||
| state.skipToTurnComplete = true; | ||
| state.supersededInputSeq = state.activeInputSeq; | ||
| this.armStoppedBoundary(state); | ||
| } | ||
| const stoppedBoundary = state.skipToTurnComplete | ||
| ? (state.stoppedBoundary ??= Symbol("stopped-boundary")) | ||
| : undefined; |
There was a problem hiding this comment.
🟡 Stopped boundary is lost across tabs
After one tab stops, stopGeneration keeps the discard boundary only in that tab. ChatTabCoordinator shares only cursors, so another tab can claim the chat and render stopped output.
Learn more
Each browser tab owns a separate TriggerChatTransport and session map. stopGeneration arms the stopped-output boundary locally, then releases the chat claim. The session message carries only lastEventId, so another tab never receives skipToTurnComplete, supersededInputSeq, or the reload guard. That tab can claim the released chat and subscribe from its old cursor without filtering the stopped turn's remaining output.
Example: Tab A and Tab B both open chat c1 with multiTab: true. Tab A receives part of a tool call, stops, and releases its claim. Tab B sends the next prompt. Its local session has no stopped boundary, so the old tool output is delivered as part of the new response.
Recommended fix: Broadcast the persisted stopped-boundary state before releasing the claim, and merge it into peer sessions. Include every field needed to preserve the gate and transcript-recovery guard, not only lastEventId. Add a two-transport regression test covering stop in one tab followed by send in the other.
Was this helpful? React with 👍 or 👎 to provide feedback.
| ); | ||
| } | ||
|
|
||
| describe("Stop with a successor response", () => { |
| (state.isStreaming === true || | ||
| state.activeInputSeq !== undefined || | ||
| (state.isStreaming === undefined && | ||
| ((state.pendingInputCount ?? 0) > 0 || | ||
| state.resumedUnknownTurn === true || | ||
| state.skipSettledPeek === true))) |
There was a problem hiding this comment.
🟡 Pending idle sends escape Stop
When a known-idle append is pending, hasOutstandingTurn ignores its positive pendingInputCount. Stop leaves the boundary unarmed, so unread stopped output can enter the next subscription.
Learn more
A completed turn persists isStreaming: false. The next message increments pendingInputCount before awaiting its append acknowledgment, but this condition only consults that counter when isStreaming is undefined. If Stop arrives during that wait, it posts the Stop after the message without recording a discard boundary. The accepted message can still produce output, and the following subscription does not filter it.
Example: Turn one completes and leaves isStreaming: false. Turn two's append is accepted but its HTTP response is delayed. Stop arrives during that delay, then turn two begins producing output. The transport subscribes without skipToTurnComplete, so turn two's stopped tail is delivered instead of discarded.
Recommended fix: Treat any positive pendingInputCount as an outstanding turn, regardless of isStreaming. Keep resumedUnknownTurn and skipSettledPeek restricted to the unknown-state branch.
| (state.isStreaming === true || | |
| state.activeInputSeq !== undefined || | |
| (state.isStreaming === undefined && | |
| ((state.pendingInputCount ?? 0) > 0 || | |
| state.resumedUnknownTurn === true || | |
| state.skipSettledPeek === true))) | |
| (state.isStreaming === true || | |
| state.activeInputSeq !== undefined || | |
| (state.pendingInputCount ?? 0) > 0 || | |
| (state.isStreaming === undefined && | |
| (state.resumedUnknownTurn === true || state.skipSettledPeek === true))) |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 0d004d65-95e4-47ba-a78a-795d81c5e395
📒 Files selected for processing (4)
.changeset/chat-stop-successor-boundary.mdpackages/trigger-sdk/src/v3/chat-stop.test.tspackages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- .changeset/chat-stop-successor-boundary.md
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📜 Review details
⏰ Context from checks skipped due to timeout. (37)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (20, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (24, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (21, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (14, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (16, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (19, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (17, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (15, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (13, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (18, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (23, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (12, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 24)
- GitHub Check: webapp / 🧪 Unit Tests: Webapp (11, 24)
- GitHub Check: sdk-compat / Cloudflare Workers
- GitHub Check: sdk-compat / Node.js 24.18 (warp-ubuntu-latest-x64-4x)
- GitHub Check: sdk-compat / Bun Runtime
- GitHub Check: packages / 🧪 Unit Tests: Packages (3, 3)
- GitHub Check: e2e / 🧪 CLI v3 tests (warp-windows-latest-x64-8x - pnpm)
- GitHub Check: packages / 🧪 Unit Tests: Packages (2, 3)
- GitHub Check: internal / 🧪 Unit Tests: Internal (1)
- GitHub Check: internal / 🧪 Unit Tests: Internal (2)
- GitHub Check: packages / 🧪 Unit Tests: Packages (1, 3)
- GitHub Check: e2e / 🧪 CLI v3 tests (warp-windows-latest-x64-8x - npm)
- GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (2, 2)
- GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (1, 2)
- GitHub Check: runops-guard / runops-guard
- GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
📓 Path-based instructions (7)
**Public packages** (`packages/*`): Use `build`.
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
Always import from `@trigger.dev/sdk`.
📄 CodeRabbit inference engine (packages/trigger-sdk/CLAUDE.md)
Files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
In the Trigger.dev SDK (packages/trigger-sdk), prefer isomorphic code like fetch and ReadableStream instead of Node.js-specific code
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
Use vitest for all tests in the Trigger.dev repository
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
Use function declarations instead of default exports
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
Use types over interfaces for TypeScript Avoid using enums; prefer string unions or const objects instead
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs Do not use high-cardinality attributes in OTEL metr...
📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)
Files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
🧠 Learnings (1)
📚 Learning: 2026-06-16T09:19:47.637Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3960
File: apps/webapp/test/prismaInfrastructureErrorCapture.test.ts:0-0
Timestamp: 2026-06-16T09:19:47.637Z
Learning: In this repo’s Vitest setup, `vitest.config.ts` uses `globals: true`, so identifiers like `vi`, `describe`, `it`, and `expect` are available as globals in Vitest test files. During code review, do not flag missing `vi`/`describe`/`it`/`expect` imports as a runtime error or correctness issue when they’re used in `*.test.ts/tsx` or `*.spec.ts/tsx` files. Explicit imports are still preferred for consistency, but they’re not required for runtime behavior.
Applied to files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat-stop.test.ts
| sinceInSeq: inSeq, | ||
| sendStopOnAbort: true, | ||
| state.activeInputSeq = inSeq; | ||
| this.requireStoppedTurnCorrelation(chatId, state, inSeq); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '925,995p' packages/trigger-sdk/src/v3/chat.ts
sed -n '1395,1470p' packages/trigger-sdk/src/v3/chat.ts
sed -n '1720,1810p' packages/trigger-sdk/src/v3/chat.ts
rg -n "sequence-free|includeSequence|overlap|concurrent|requiresTranscriptReload" packages/trigger-sdk/src/v3/chat-stop.test.ts packages/trigger-sdk/test/chat-transport-events.test.tsRepository: triggerdotdev/trigger.dev
Length of output: 10706
🏁 Script executed:
rg -n "sendWithEvents|appendInputChunk|requireStoppedTurnCorrelation|requiresTranscriptReload|sendMessages|sendAction" packages/trigger-sdk/src/v3/chat.ts packages/trigger-sdk/src/v3/chat-stop.test.ts
sed -n '995,1165p' packages/trigger-sdk/src/v3/chat.ts
sed -n '1470,1645p' packages/trigger-sdk/src/v3/chat.ts
sed -n '1860,2045p' packages/trigger-sdk/src/v3/chat.ts
sed -n '380,470p' packages/trigger-sdk/src/v3/chat-stop.test.ts
sed -n '680,840p' packages/trigger-sdk/src/v3/chat-stop.test.tsRepository: triggerdotdev/trigger.dev
Length of output: 36501
🏁 Script executed:
sed -n '1840,2045p' packages/trigger-sdk/src/v3/chat.ts; sed -n '1,140p' packages/trigger-sdk/src/v3/chat.ts; rg -n -A35 -B15 "requireStoppedTurnCorrelation|sendWithEvents|appendInputChunk" packages/trigger-sdk/src/v3/chat.tsRepository: triggerdotdev/trigger.dev
Length of output: 34075
Recheck transcript readiness after correlation.
When skipToTurnComplete is active, an accepted sequence-free append causes requireStoppedTurnCorrelation() to set requiresTranscriptReload and throw. A concurrent send can pass its initial assertTranscriptReady() check before that state change. If its append returns a sequence, requireStoppedTurnCorrelation() returns without checking the reload flag, and the send reaches subscribeToSessionStream().
Apply this ordering in both sendMessages and sendAction:
Proposed ordering
- state.activeInputSeq = inSeq;
this.requireStoppedTurnCorrelation(chatId, state, inSeq);
+ this.assertTranscriptReady(chatId, state);
+ state.activeInputSeq = inSeq;Add a regression test with overlapping appends.
Stop acknowledgments can close a later response, and lost Stop state can replay old tool output after a reload.
The SDK now records Stop before the request and retains stopped and abandoned state through hydration.
Accepted responses without sequence correlation block further sends until
useLoadTranscriptloads a saved transcript that covers the stopped input.Stop on an idle hydrated session leaves the next response intact. Early resumes retain Stop protection after passive cancellation.
✅ Checklist
Testing
RedisCacheStoreConfig, in unchangedinternal-packages/cache/src/stores/redis.ts:7setSession, plus an already-aborted reconnectChangelog
New chat responses remain intact after Stop, including slow acknowledgments and page reloads.
Stop on an idle hydrated session no longer discards the next response.
Transcript recovery reports missing evidence and empty output polls. An empty poll permits reconnect without another input append.
The internal state shares the persisted type and one field projection.
The recovery callback accepts one cursor object.
seedTranscriptCursorretains its three-argument API.The resume marker and pending-input count remain runtime-only. The idle Stop correction adds no public parameters or persisted fields.
Risk
lastInEventIdandlastOutEventIdfor automatic recovery. Missing evidence reports an error and keeps sends blocked.