Skip to content

fix(sdk): preserve stopped chat boundaries across successor sends - #4955

Open
gtremper wants to merge 5 commits into
triggerdotdev:mainfrom
gtremper:fix/chat-stop-successor-boundary
Open

gtremper wants to merge 5 commits into
triggerdotdev:mainfrom
gtremper:fix/chat-stop-successor-boundary

Conversation

@gtremper

@gtremper gtremper commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

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 useLoadTranscript loads 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

  • The PR title follows the contribution convention.
  • The changes include regression tests and a patch changeset.
  • The local SDK tests and build pass.
  • Maintainer CI and reference-project validation.

Testing

  • HTTP transport: 69 Stop and recovery tests pass with SSE parsing and the AI SDK reader
  • Transcript recovery: 32 cursor and state tests pass
  • Mounted React hooks: six permanent tests pass with real ReactDOM and jsdom, including Strict Mode, replacement, cancellation, and missing evidence
  • Full SDK suite: 828 tests pass across 82 files on the pinned Node 24.18.0
  • Core and SDK builds, repository formatting, and lint pass
  • Knip: one existing unused export, RedisCacheStoreConfig, in unchanged internal-packages/cache/src/stores/redis.ts:7
  • Independent correctness and security reviews: no remaining findings
  • Coverage: early Stop before resumed output, delayed acknowledgments, failed Stop, reloads, passive abort, repeated Stop, missing boundaries, session recreation, and blocked messages, actions, and steering
  • Idle hydration: token-only and cursor-only sessions through the constructor and setSession, plus an already-aborted reconnect
  • Pending appends: unknown state, overlapping requests, acknowledgment callbacks, failed requests, and unchanged known-idle and abandoned behavior
  • Recovery: both hydration paths, stale loads, input cursors, delayed output, and explicit errors after empty polls
  • Lifecycle: abort and Stop close quietly, settled responses complete, and watch subscriptions reconnect after empty output
  • Compatibility: sequence-free responses without a stopped boundary

Changelog

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. seedTranscriptCursor retains 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

  • Failed Stop: the local reader closes, but the remote run can continue
  • Persisted state: three existing internal fields become optional persisted fields. Three new fields track transcript recovery.
  • Custom transcript storage must return numeric lastInEventId and lastOutEventId for automatic recovery. Missing evidence reports an error and keeps sends blocked.
  • Recovered sessions use a non-peek poll of at most 30 seconds while streaming state is unknown
  • Empty recovery polls report an error and retain unknown state for an explicit reconnect
  • Reference-project validation: not run locally

@changeset-bot

changeset-bot Bot commented Sep 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4c100ce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@trigger.dev/sdk Patch
@trigger.dev/python Patch
@internal/dashboard-agent Patch
@trigger.dev/build Patch
trigger.dev Patch
@trigger.dev/core Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@trigger.dev/rbac Patch
@trigger.dev/sso Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/metrics-pipeline Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/run-store Patch
@internal/schedule-engine Patch
@internal/tracing Patch
@internal/webhook-engine Patch
@internal/webhook-sources Patch
@internal/testcontainers Patch
@internal/cache Patch

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

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The 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. prepareTranscriptRecovery now requires newer output and input cursors. React transcript loading delegates recovery to the current transport. Tests cover fresh, resumed, hydrated, failed-stop, and watch-mode flows.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 4c100

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: preserving stopped chat boundaries across successor sends.
Description check ✅ Passed The description explains the change, testing, changelog, risks, and pending validation. It does not include a Closes issue reference or screenshots, but these omissions are non-critical because the de…
Full details: Docstring Coverage

Explanation

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

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]

This comment was marked as resolved.

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 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 win

Preserve indeterminate recovery state after a transient stream error.

prepareTranscriptRecovery sets isStreaming to undefined while accepted output can still be pending. A connection or read error then sets it to false. The next reconnectToStream call returns null, so the client cannot recover that output.

Keep isStreaming undefined 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ca683d and 92b6a91.

📒 Files selected for processing (7)
  • .changeset/chat-stop-successor-boundary.md
  • packages/trigger-sdk/src/v3/chat-react.ts
  • packages/trigger-sdk/src/v3/chat-stop.test.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/trigger-sdk/test/chat-turn-correlation.test.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat-react.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat-react.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat-react.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat-react.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat-react.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat-react.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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

@gtremper
gtremper marked this pull request as ready for review September 19, 2026 04:25
devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration Bot 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.

Note

This report is out of date. Scroll down for Devin Review's latest report on this PR.

Devin Review found 2 new potential issues.

Devin Review

Comment thread packages/trigger-sdk/src/v3/chat.ts Outdated
Comment on lines +1315 to +1323
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;

@devin-ai-integration devin-ai-integration Bot Sep 19, 2026

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.

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

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

);
}

describe("Stop with a successor response", () => {

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.

🔍 Mock-heavy tests conflict with guidance

The new suites simulate HTTP and transcript loading despite the repository’s no-mocks rule. Review whether integration coverage or an exception is required.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 1 new potential issue.

Devin Review

Comment on lines +1748 to +1753
(state.isStreaming === true ||
state.activeInputSeq !== undefined ||
(state.isStreaming === undefined &&
((state.pendingInputCount ?? 0) > 0 ||
state.resumedUnknownTurn === true ||
state.skipSettledPeek === true)))

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.

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

Suggested change
(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)))

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0d004d65-95e4-47ba-a78a-795d81c5e395

📥 Commits

Reviewing files that changed from the base of the PR and between 75ec579 and 4c100ce.

📒 Files selected for processing (4)
  • .changeset/chat-stop-successor-boundary.md
  • packages/trigger-sdk/src/v3/chat-stop.test.ts
  • packages/trigger-sdk/src/v3/chat.test.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/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.ts
  • packages/trigger-sdk/src/v3/chat-stop.test.ts

sinceInSeq: inSeq,
sendStopOnAbort: true,
state.activeInputSeq = inSeq;
this.requireStoppedTurnCorrelation(chatId, state, inSeq);

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.

🎯 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.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:

Proposed ordering
-      state.activeInputSeq = inSeq;
       this.requireStoppedTurnCorrelation(chatId, state, inSeq);
+      this.assertTranscriptReady(chatId, state);
+      state.activeInputSeq = inSeq;

Add a regression test with overlapping appends.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant