Skip to content

fix(sdk): preserve chat Stop boundaries and delivery outcomes - #4955

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

gtremper wants to merge 8 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. Lost Stop state can replay old
tool output after a reload. A canceled message can also append after session
creation or token renewal.

The SDK records Stop before its request and preserves the stopped boundary through
hydration. Pending messages and actions retain protection, including idle and
abandoned sessions. Concurrent sends cannot bypass a required transcript reload.
Cancellation prevents later input appends after session creation or token renewal.
Stop renews expired tokens but does not recreate a missing session after HTTP 404.

stopGeneration(chatId, { throwOnError: true }) rejects delivery failures with the
original error and HTTP status. The default call retains its existing false
result for delivery failures. A missing local session returns false in both
modes. The local reader stays closed after a failed Stop request.

✅ Checklist

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

Testing

  • Full SDK suite: 926 tests pass across 84 files on Node 24.18.0.
  • Stop and recovery: 82 tests use HTTP, SSE parsing, and the AI SDK reader.
  • Delivery and cancellation: 40 tests use HTTP and real BroadcastChannel state.
  • Transcript recovery: 32 cursor and state tests pass.
  • Mounted React hooks: six tests cover Strict Mode, replacement, cancellation,
    and missing evidence.
  • Core and SDK builds, SDK type checks, repository formatting, lint, and Knip pass.
  • Independent correctness and security reviews found no remaining defects.
  • Coverage includes delayed Stop acknowledgments, failed delivery, pending
    appends, overlapping sends, token renewal, HTTP 404, and successor ownership.
  • Definite rejection can clear a provisional boundary. Accepted inputs, uncertain
    failures, and discarded output retain recovery protection.
  • Both the default Stop result and opt-in error behavior have regression tests.

Changelog

New responses remain intact after Stop, including slow acknowledgments and page
reloads. Canceled messages and actions do not append after session creation or
token renewal. Stop reports delivery errors through an optional parameter and
does not recreate missing sessions.

Transcript recovery reports missing evidence and empty output polls. A fresh
transcript restores a blocked session only after its cursors cover the stopped
input. An empty poll permits reconnect without another input append.

Risk

  • A failed Stop closes the local reader, but the remote run can continue.
  • An accepted Stop append does not prove that backend cancellation completed.
  • Delayed Stop ordering on the server remains outside this change.
  • Three existing internal fields become optional persisted fields. Three new
    fields track transcript recovery. Pending-input tokens remain runtime-only.
  • Custom transcript storage must return numeric lastInEventId and
    lastOutEventId for automatic recovery. Missing evidence keeps sends blocked.
  • Recovered sessions use a non-peek poll of at most 30 seconds while stream state
    is unknown. Empty polls report an error and permit an explicit reconnect.
  • Reference-project validation did not run locally.

@changeset-bot

changeset-bot Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e3a440e

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 identifies the SDK fix and its two main outcomes: preserving chat Stop boundaries and delivery results.
Description check ✅ Passed The description is detailed and covers the implementation, testing, changelog, risks, and remaining validation. It does not include an issue-closing reference, the full template checklist, or screensh…
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.)

✨ 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[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.

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

Comment thread packages/trigger-sdk/src/v3/chat.ts Outdated
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.

@gtremper gtremper changed the title fix(sdk): preserve stopped chat boundaries across successor sends fix(sdk): preserve chat Stop boundaries and delivery outcomes Sep 23, 2026

This branch has not been deployed

No deployments
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