GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(sdk): preserve chat Stop boundaries and delivery outcomes by gtremper · Pull Request #4955 · triggerdotdev/trigger.dev Conversation
|
🦋 Changeset detectedLatest commit: e3a440e 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
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); }
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: d00b5b24-65ec-4cde-a80c-1031a1b722a7
.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.tsIncluded review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📄 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📄 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📄 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📄 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📄 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📄 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📄 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.tsLearnt 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.tspackages/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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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 an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟡 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.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ); | ||
| } | ||
|
|
||
| describe("Stop with a successor response", () => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 0d004d65-95e4-47ba-a78a-795d81c5e395
.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.tsIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📄 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📄 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📄 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📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
packages/trigger-sdk/src/v3/chat.test.tspackages/trigger-sdk/src/v3/chat-stop.test.ts📄 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📄 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📄 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.tsLearnt 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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| sinceInSeq: inSeq, | ||
| sendStopOnAbort: true, | ||
| state.activeInputSeq = inSeq; | ||
| this.requireStoppedTurnCorrelation(chatId, state, inSeq); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🏁 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.ts
Repository: 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.ts
Repository: 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.ts
Repository: 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:
- state.activeInputSeq = inSeq; this.requireStoppedTurnCorrelation(chatId, state, inSeq); + this.assertTranscriptReady(chatId, state); + state.activeInputSeq = inSeq;
Add a regression test with overlapping appends.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.