Skip to content

feat(sdk): run tail recovery for every chat.agent and let a transcript storage own the model's context - #4895

Open
ericallam wants to merge 1 commit into
feat/transcript-storage-changesets-tri-13667from
feat/transcript-storage-gate-split-tri-13667
Open

feat(sdk): run tail recovery for every chat.agent and let a transcript storage own the model's context#4895
ericallam wants to merge 1 commit into
feat/transcript-storage-changesets-tri-13667from
feat/transcript-storage-gate-split-tri-13667

Conversation

@ericallam

Copy link
Copy Markdown
Member

Summary

Crash recovery now runs for every chat.agent, and a transcript storage can own the model's context through loadContext, which replaces the deprecated hydrateMessages hook.

One condition used to decide three things at boot: whether to read the persisted transcript, whether to replay the session's output tail, and whether to replay unacknowledged input. Registering hydrateMessages switched all three off, so an app that owned its own context also lost recovery of a half-written answer and of the messages the dead run never acknowledged, which no application can rebuild from its own rows because the tail is exactly what never got persisted. The replays and onRecoveryBoot now run for every agent; only the transcript read is skipped for hydrateMessages, whose store is the source of truth.

Design

A storage may declare loadContext(scope, event). When present, the runtime calls it on every turn and action, with the same event hydrateMessages received, and uses what it returns as the model's context, while save keeps receiving every change. hydrateMessages keeps working with a one-time warning at definition. Setting it together with a storage that has loadContext is an error.

For hydrateMessages agents this is the behaviour-changing PR: they regain tail recovery. Runtime writes stay off for them, as documented on the actions page.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d627683

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The SDK adds an optional TranscriptStorage.loadContext method with a per-turn event type. Runtime context loading now uses either hydrateMessages or storage loadContext, while preventing both from being configured together. Recovery and transcript saving continue when external context loading is active. hydrateMessages emits a one-time deprecation warning. Tests cover recovery, storage context loading, head-start handling, validation, and warning behavior.

Merge Risk: 🟡 Moderate · up to d6276

Recovered agents can resume without persisted injected context at a compaction boundary. Resolve this context-loss risk before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the design and behavior changes in detail, but it does not follow most required template sections. It omits the issue reference, checklist, Testing section, Changelog section,… Add the required "Closes #" line, complete the checklist, document testing steps under "## Testing", add a short entry under "## Changelog", and include screenshots or state that screenshots are not applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two primary changes: universal tail recovery and transcript-owned model context. It is specific and related to the changeset.
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.
Full details: Description check

Explanation

The description explains the design and behavior changes in detail, but it does not follow most required template sections. It omits the issue reference, checklist, Testing section, Changelog section, and Screenshots section.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1 too large.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/transcript-storage-gate-split-tri-13667

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.

@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from c5e1f5d to bac2a16 Compare September 5, 2026 20:29
@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

npm i https://pkg.pr.new/@trigger.dev/build@d627683

trigger.dev

npm i https://pkg.pr.new/trigger.dev@d627683

@trigger.dev/core

npm i https://pkg.pr.new/@trigger.dev/core@d627683

@trigger.dev/python

npm i https://pkg.pr.new/@trigger.dev/python@d627683

@trigger.dev/react-hooks

npm i https://pkg.pr.new/@trigger.dev/react-hooks@d627683

@trigger.dev/redis-worker

npm i https://pkg.pr.new/@trigger.dev/redis-worker@d627683

@trigger.dev/rsc

npm i https://pkg.pr.new/@trigger.dev/rsc@d627683

@trigger.dev/schema-to-json

npm i https://pkg.pr.new/@trigger.dev/schema-to-json@d627683

@trigger.dev/sdk

npm i https://pkg.pr.new/@trigger.dev/sdk@d627683

commit: d627683

coderabbitai[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from bac2a16 to bb1acb8 Compare September 5, 2026 20:38
@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from bb1acb8 to 8bb1a1c Compare September 6, 2026 05:42
@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from 8bb1a1c to 10a1d68 Compare September 6, 2026 05:55
@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from 10a1d68 to f2a1179 Compare September 6, 2026 06:17
@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch 2 times, most recently from 860969d to 0b4aa77 Compare September 6, 2026 06:39
@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from 0b4aa77 to b12a0b7 Compare September 6, 2026 08:05
@ericallam
ericallam marked this pull request as ready for review September 6, 2026 08:30
devin-ai-integration[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from b12a0b7 to dce7b9b Compare September 6, 2026 08:43
@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from dce7b9b to 7ea075f Compare September 7, 2026 07:48

@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: 2

Caution

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

⚠️ Outside diff range comments (2)
packages/trigger-sdk/src/v3/transcriptStorage.ts (2)

486-486: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Restore injections at the compaction boundary.

If an injection follows the message identified by throughId, idx equals start - 1. This filter removes that injection. A recovered model lane can then omit persisted chat.inject context.

Track whether compaction already contains a boundary injection, or invalidate compaction when a new boundary injection is added. Do not exclude the injection only because its anchor is the final compacted message.


142-173: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add crumb markers to the new transcript state paths.

Add // @Crumbs markers or approved `// `#region` `@crumbs blocks around state reduction, persistence, runtime-state parsing, and model-lane restoration. Do not invent a namespace before approval.

As per coding guidelines, “Add crumbs as you write code” and “Do not invent new namespaces — pick from this table or ask first.”

Also applies to: 296-304, 365-369, 395-425, 458-501

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 382fdf9d-0477-4ab4-8c00-1a86837b708e

📥 Commits

Reviewing files that changed from the base of the PR and between c5e1f5d and 7ea075f.

📒 Files selected for processing (3)
  • packages/trigger-sdk/src/v3/ai.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/test/transcript-gate-split.test.ts
💤 Files with no reviewable changes (1)
  • packages/trigger-sdk/src/v3/ai.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

📜 Review details
⏰ Context from checks skipped due to timeout. (5)
  • GitHub Check: All PR Checks
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: audit
  • GitHub Check: audit
🧰 Additional context used
📓 Path-based instructions (9)
Always import from `@trigger.dev/sdk`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/transcript-gate-split.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
We use vitest exclusively.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/transcript-gate-split.test.ts
**Prefer static imports over dynamic imports.**

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/transcript-gate-split.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
Add crumbs as you write code — not just when debugging.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/transcript-gate-split.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.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/transcript-gate-split.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
Use vitest for all tests in the Trigger.dev repository

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/trigger-sdk/test/transcript-gate-split.test.ts
Use function declarations instead of default exports

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/trigger-sdk/test/transcript-gate-split.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.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/transcript-gate-split.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.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/transcript-gate-split.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
🧠 Learnings (3)
📚 Learning: 2026-05-19T22:37:47.286Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3671
File: packages/trigger-sdk/test/recovery-boot.test.ts:456-457
Timestamp: 2026-05-19T22:37:47.286Z
Learning: In `packages/trigger-sdk` (Trigger.dev SDK), `logger.warn` (and other SDK logger methods) should route to the Trigger.dev structured logger sink, not to `console.warn`. In SDK tests, `vi.spyOn(console, "warn")` (or similar console spies) should only be used to suppress stray console output; reviewers should not suggest asserting on `console.warn` spies to verify SDK-internal warning/fallback log behavior. Use the SDK’s structured-logger outputs/capture approach instead of console spies.

Applied to files:

  • packages/trigger-sdk/test/transcript-gate-split.test.ts
📚 Learning: 2026-08-16T18:36:58.179Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 4537
File: packages/trigger-sdk/test/normalizeKeyString.test.ts:1-2
Timestamp: 2026-08-16T18:36:58.179Z
Learning: For related SDK `chat.agent` tests in the Trigger.dev repository—including chat channels, handover, snapshot, and transport-event coverage—keep new test files under `packages/trigger-sdk/test/` rather than colocating them with the `packages/trigger-sdk/src/v3/` source files.

Applied to files:

  • packages/trigger-sdk/test/transcript-gate-split.test.ts
📚 Learning: 2026-06-04T18:16:35.386Z
Learnt from: nicktrn
Repo: triggerdotdev/trigger.dev PR: 3836
File: apps/supervisor/src/backpressure/backpressureMonitor.ts:3-5
Timestamp: 2026-06-04T18:16:35.386Z
Learning: When reviewing TypeScript in this repo, apply the rule “prefer type aliases over interfaces” only to data/object shapes and union/intersection type modeling. If an interface is being used as a behavioral contract for collaborators to implement (e.g., method-shape interfaces that define required behavior, such as `BackpressureLogger` / `BackpressureSignalSource` in `apps/supervisor/src/backpressure/backpressureMonitor.ts`), keep it as an `interface` and do not flag it as a type-alias-vs-interface violation.

Applied to files:

  • packages/trigger-sdk/src/v3/transcriptStorage.ts

Comment thread packages/trigger-sdk/test/transcript-gate-split.test.ts
Comment thread packages/trigger-sdk/test/transcript-gate-split.test.ts
@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from 7ea075f to 1e23c34 Compare September 7, 2026 08:16
…t storage own the model's context

One condition used to decide three things at boot: whether to read the persisted transcript, whether to replay the session's output tail, and whether to replay unacknowledged input. Registering hydrateMessages switched all three off, so an app that owned its own context also lost crash recovery, and no application can rebuild the tail its dead run had already emitted. The replays and onRecoveryBoot now run for every agent; only the transcript read is skipped for hydrateMessages.

The storage can now declare loadContext, which the runtime calls on every turn and action in place of the accumulated transcript, the role hydrateMessages played, while save keeps receiving every change. hydrateMessages is deprecated with a one-time warning, and configuring it together with a storage that has loadContext is an error.
@ericallam
ericallam force-pushed the feat/transcript-storage-gate-split-tri-13667 branch from 1e23c34 to d627683 Compare September 7, 2026 10:22
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.

2 participants