Skip to content

feat(sdk,core,webapp): transcript storage for chat.agent - #4896

Open
ericallam wants to merge 5 commits into
feat/transcript-storage-gate-split-tri-13667from
feat/transcript-storage-tri-13667
Open

feat(sdk,core,webapp): transcript storage for chat.agent#4896
ericallam wants to merge 5 commits into
feat/transcript-storage-gate-split-tri-13667from
feat/transcript-storage-tri-13667

Conversation

@ericallam

Copy link
Copy Markdown
Member

Summary

The public surface for transcript storage: chat.agent({ storage }), the exported types and factories, a read path that works for any storage, a conformance suite, and the docs.

import { chat, defaultStorage } from "@trigger.dev/sdk/ai";

export const myChat = chat.agent({ id: "my-chat", storage: myTranscriptStorage, run });

// app server
export const loadTranscript = chat.createLoadTranscriptAction(defaultStorage, { limit: 50 });

// browser
const { messages, isLoading } = useLoadTranscript(chatId, loadTranscript, { transport });

load on the storage is the one read for every backend. chat.createLoadTranscriptAction wraps it for the app server and useLoadTranscript renders the result and seeds the transport's resume cursor. A new secret-key endpoint, GET /api/v1/sessions/:id/transcript?limit=&before=, pages the platform snapshot server-side so rendering the last page of a long conversation does not download all of it; the default storage uses it for paged reads and falls back to the whole blob.

runTranscriptStorageTests from @trigger.dev/sdk/ai/test is the contract a storage has to meet: appends and in-place replacement, idempotent remove and truncateAfter, state round-trips, cursors, replaying a changeset, paging, and chat isolation. It runs here against memoryTranscriptStorage(), the default snapshot storage, and a row-per-message adapter over the dashboard agent's own tables, which is the real-schema target and adds two nullable columns to its chats table.

hydrateMessages is documented as deprecated, with loadContext on a storage as the replacement. The changeset in this PR is the release note for the whole feature.

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

Adds a TranscriptStorage adapter for chat.agent, including default and custom storage, incremental changesets, transcript state, cursors, and context loading. Adds paginated transcript APIs, server and React loading helpers, and storage conformance tests. Adds dashboard-agent database persistence with migrations. Updates snapshot handling, crash recovery, injection and compaction persistence, deprecates hydrateMessages, and documents the new APIs and migration path.

Merge Risk: 🟡 Moderate · up to 3ddfb

This change adds persisted chat transcripts, loading, paging, and recovery behavior. The remaining documentation issues could cause users to implement incompatible action handling or incomplete recovery flows, so they should be corrected before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a detailed and relevant summary, but it does not follow the repository template. It omits the issue reference, checklist, Testing section, Changelog section, and Screenshots s… Add the required template sections. Include the issue reference, complete the checklist, describe the test steps, add a short changelog entry, and state whether screenshots are applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 47.06% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 17 files. (2 skipped:… 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 and concisely describes the main change: adding transcript storage for chat.agent across the SDK, core, and webapp.
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 provides a detailed and relevant summary, but it does not follow the repository template. It omits the issue reference, checklist, Testing section, Changelog section, and Screenshots section.

Full details: Docstring Coverage

Explanation

Docstring coverage is 47.06% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 17 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ 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-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.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3ddfb85

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 Minor
@trigger.dev/core Minor
@trigger.dev/python Minor
@internal/dashboard-agent Patch
@trigger.dev/build Minor
trigger.dev Minor
@trigger.dev/redis-worker Minor
@trigger.dev/schema-to-json Minor
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/metrics-pipeline Patch
@trigger.dev/rbac Minor
@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/cache Patch
@trigger.dev/react-hooks Minor
@trigger.dev/rsc Minor
@trigger.dev/database Minor
@trigger.dev/otlp-importer Minor
@trigger.dev/sso Minor
@internal/testcontainers 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

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Observability map

As of 3ddfb85.

20/100 over 455 measured of 473 entry points (base 20, no change)

What this PR changed

route base head now failing
/api/v1/sessions/:sessionId/transcript new 50 request-context

FIX FIRST

  • /api/v1/projects/:projectRef/envvars (sensitive) - auth-boundary, request-context
  • /auth/sso (sensitive) - auth-boundary, request-context
  • /_app/orgs/:organizationSlug/settings/team (sensitive) - error-classification, auth-scope, request-context

AUDIT 3 of 50 sensitive mutations record an actor. 47 without one.
CONTEXT 23 of 455 entry points name a tenant on a failure path. 352 appear only here, 39 of them sensitive, in the JSON rather than the fix list.

What the score is made of
CHECKS
  error-classification  186 applicable, 107 pass,   0 sole, global without it 12
  auth-boundary          62 applicable,  57 pass,   0 sole, global without it 16
  auth-scope             19 applicable,  17 pass,   0 sole, global without it 19
  request-context       455 applicable,  23 pass, 247 sole, global without it 64
  audit-trail            50 applicable,   3 pass,   0 sole, not in the score

The score and findings here are report-only and never gate the merge. Separately, a required test suite keeps this tool's symbol and route lists in sync with the code they name, and can fail a pull request that renames or removes a symbol they reference, or that adds the first route with a segment they anticipate. Each failure names the list to edit. The rules and their reasons: internal-packages/observability-map/README.md.

@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from 2b2ea99 to be72173 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@3ddfb85

trigger.dev

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

@trigger.dev/core

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

@trigger.dev/python

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

@trigger.dev/react-hooks

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

@trigger.dev/redis-worker

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

@trigger.dev/rsc

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

@trigger.dev/schema-to-json

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

@trigger.dev/sdk

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

commit: 3ddfb85

@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from be72173 to 5dc4365 Compare September 5, 2026 20:38
@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from 5dc4365 to 3bdfd45 Compare September 6, 2026 05:42
@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from 3bdfd45 to db561bb Compare September 6, 2026 05:55
@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from db561bb to 185360a Compare September 6, 2026 06:17
@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from 185360a to 461a6d2 Compare September 6, 2026 06:18
@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from 461a6d2 to 1a3b477 Compare September 6, 2026 06:39
@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from 1a3b477 to d06408f Compare September 6, 2026 08:06
@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from d06408f to a4f1bfe Compare September 6, 2026 08:43
@ericallam
ericallam marked this pull request as ready for review September 6, 2026 16:36
devin-ai-integration[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch 6 times, most recently from 39a00da to bf8496f Compare September 7, 2026 07:48
coderabbitai[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from bf8496f to 84643b8 Compare September 7, 2026 08:16
coderabbitai[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from 84643b8 to 7a6c3fd Compare September 7, 2026 10:09
…nformance suite

chat.agent takes a storage option, with the platform snapshot as the default and the TranscriptStorage types, defaultStorage, snapshotTranscriptStorage, memoryTranscriptStorage and reduceTranscriptChanges exported from @trigger.dev/sdk/ai. chat.createLoadTranscriptAction(storage) reads a conversation on the server for any storage, and useLoadTranscript renders it in the browser and seeds the transport's resume cursor. runTranscriptStorageTests from @trigger.dev/sdk/ai/test is the contract a storage implementation has to meet.

A new secret-key endpoint, GET /api/v1/sessions/:id/transcript, pages the platform snapshot server-side so rendering the last page of a long conversation does not download all of it; the default storage uses it for paged reads and falls back to the whole blob.
… message rows

The real-schema conformance target for the storage contract: one row per message in chat_messages, with the runtime's state and cursors in two new nullable columns on chats. Paging is by position in SQL. The agent itself still persists through its hooks.
coderabbitai[bot]

This comment was marked as resolved.

Treat a non-positive page limit as no limit instead of an empty page a
caller cannot tell apart from the end of the transcript. Hold a seeded
resume cursor until the session exists, so a transcript load that resolves
before the session is created still opens the live stream past the
persisted history instead of replaying it.
@ericallam
ericallam force-pushed the feat/transcript-storage-tri-13667 branch from 7a6c3fd to 0a10002 Compare September 7, 2026 10:22
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

Consume a pending resume cursor in setSession() and stop seedResumeCursor
from moving an existing session's cursor backward, so a transcript load that
resolves around session creation, or after the live stream already advanced,
does not replay persisted events. Add conformance coverage for a partial
answer's non-final status, and drive the resume-cursor unit tests through a
real transport. Docs: loadContext also fires on actions, a custom storage is
not limited to row-per-message backends, and the bring-your-own example
imports anthropic.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 5c082b34-a976-44c1-b79c-0ca1b61f248d

📥 Commits

Reviewing files that changed from the base of the PR and between 0a10002 and 3ddfb85.

📒 Files selected for processing (5)
  • docs/ai-chat/reference.mdx
  • docs/ai-chat/transcript-storage.mdx
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/trigger-sdk/src/v3/test/transcript-storage-tests.ts
  • packages/trigger-sdk/test/use-load-transcript.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • docs/ai-chat/reference.mdx
  • docs/ai-chat/transcript-storage.mdx

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. (49)
  • GitHub Check: report
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (23, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (21, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (19, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (22, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (15, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (20, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (16, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (12, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (11, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (24, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (13, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (18, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (17, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (14, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 24)
  • GitHub Check: sdk-compat / Cloudflare Workers
  • GitHub Check: sdk-compat / Node.js 22.23 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: e2e / 🧪 CLI v3 tests (warp-windows-latest-x64-8x - npm)
  • GitHub Check: sdk-compat / Node.js 26.4 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: e2e / 🧪 CLI v3 tests (warp-windows-latest-x64-8x - pnpm)
  • GitHub Check: sdk-compat / Node.js 24.18 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: obsmap / 🧪 Unit Tests: Observability Map
  • GitHub Check: e2e / 🧪 CLI v3 tests (warp-ubuntu-latest-x64-4x - npm)
  • GitHub Check: sdk-compat / Bun Runtime
  • GitHub Check: e2e / 🧪 CLI v3 tests (warp-ubuntu-latest-x64-4x - pnpm)
  • GitHub Check: sdk-compat / Deno Runtime
  • GitHub Check: packages / 🧪 Unit Tests: Packages (3, 3)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (1, 3)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (2, 3)
  • GitHub Check: internal / 🧪 Unit Tests: Internal
  • GitHub Check: fk-cascade-guard / fk-cascade-guard
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (2, 2)
  • GitHub Check: runops-guard / runops-guard
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (1, 2)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: code-quality / code-quality
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: 🛡️ E2E Auth Tests (full)
  • GitHub Check: Build and publish previews
🧰 Additional context used
📓 Path-based instructions (9)
Always import from `@trigger.dev/sdk`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/test/transcript-storage-tests.ts
  • packages/trigger-sdk/src/v3/chat.ts
We use vitest exclusively.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

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

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/test/transcript-storage-tests.ts
  • packages/trigger-sdk/src/v3/chat.ts
Add crumbs as you write code — not just when debugging.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

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

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

Files:

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

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

Files:

  • packages/trigger-sdk/test/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/test/transcript-storage-tests.ts
  • packages/trigger-sdk/src/v3/chat.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/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/test/transcript-storage-tests.ts
  • packages/trigger-sdk/src/v3/chat.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/use-load-transcript.test.ts
  • packages/trigger-sdk/src/v3/test/transcript-storage-tests.ts
  • packages/trigger-sdk/src/v3/chat.ts

Comment on lines +1401 to +1406
this.applyPendingResumeCursor(chatId, {
publicAccessToken: session.publicAccessToken,
lastEventId: session.lastEventId,
activeInputSeq: session.activeInputSeq,
isStreaming: session.isStreaming,
})

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add required crumbs for the new behavior.

  • packages/trigger-sdk/src/v3/chat.ts#L1401-L1406: Add crumbs for pending resume-cursor application.
  • packages/trigger-sdk/src/v3/test/transcript-storage-tests.ts#L242-L267: Add crumbs for partial-answer persistence checks.
  • packages/trigger-sdk/test/use-load-transcript.test.ts#L41-L48: Add crumbs for deferred cursor application through setSession().

As per coding guidelines: “Add crumbs as you write code — not just when debugging.”

📍 Affects 3 files
  • packages/trigger-sdk/src/v3/chat.ts#L1401-L1406 (this comment)
  • packages/trigger-sdk/src/v3/test/transcript-storage-tests.ts#L242-L267
  • packages/trigger-sdk/test/use-load-transcript.test.ts#L41-L48

Source: Coding guidelines

});
}

describe("seedTranscriptCursor + TriggerChatTransport resume cursor", () => {

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Move this test next to its source file.

This suite tests seedTranscriptCursor, which is defined in packages/trigger-sdk/src/v3/chat-react.ts. Move the suite next to that source file.

As per coding guidelines: “Test files go next to source files.”

Source: Coding guidelines

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