Skip to content

fix(sdk,webapp): stop chat losing a message sent right after an action#4234

Merged
ericallam merged 1 commit into
mainfrom
feature/tri-11952-chatagent-transport-a-send-right-after-an-action-closes-its
Jul 11, 2026
Merged

fix(sdk,webapp): stop chat losing a message sent right after an action#4234
ericallam merged 1 commit into
mainfrom
feature/tri-11952-chatagent-transport-a-send-right-after-an-action-closes-its

Conversation

@ericallam

Copy link
Copy Markdown
Member

Summary

Sending a chat message immediately after an action (for example an undo) could make the message's response vanish from the UI. The transport opened a response stream that closed on the earlier turn's completion instead of waiting for the send's own turn. The agent still produced and persisted the answer, so it reappeared on refresh. Same "disappearing message" class as #4176, different cause.

Fix

A send's response stream had no way to tell whether a turn-complete belonged to its turn. POST /realtime/v1/sessions/:id/in/append now returns the appended record's sequence number, and the transport skips any turn-complete whose session-in-event-id (the agent's committed .in cursor) is below that seq, closing only on its own turn. Older webapps omit the seq, in which case the transport falls back to the previous behavior, so the SDK and server can ship independently.

Because the fix spans the SDK and the server, both a webapp deploy and an SDK release are needed for the full effect.

Verified end to end with the ai-chat reference app: undo-then-immediate-send loses the follow-up's answer before the fix and streams it inline after, with a revert-the-guard run reproducing the loss on the same script. Unit tests cover the skip and the no-seq fallback.

@changeset-bot

changeset-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 96e5ad3

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

This PR includes changesets to release 28 packages
Name Type
@trigger.dev/sdk Patch
@trigger.dev/python Patch
@internal/dashboard-agent Patch
@internal/sdk-compat-tests Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/plugins 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
trigger.dev Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/run-store Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql Patch
@internal/zod-worker 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 Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 72bdf324-ea55-4d62-adc1-218b5fbc32b9

📥 Commits

Reviewing files that changed from the base of the PR and between f8da664 and 96e5ad3.

📒 Files selected for processing (7)
  • .changeset/chat-turn-correlation.md
  • apps/webapp/app/routes/realtime.v1.sessions.$session.$io.append.ts
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.playground.realtime.v1.sessions.$session.$io.append.ts
  • apps/webapp/app/services/realtime/s2realtimeStreams.server.ts
  • docs/ai-chat/client-protocol.mdx
  • packages/trigger-sdk/src/v3/chat.ts
  • packages/trigger-sdk/test/chat-turn-correlation.test.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/chat-turn-correlation.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • apps/webapp/app/routes/realtime.v1.sessions.$session.$io.append.ts
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.playground.realtime.v1.sessions.$session.$io.append.ts
  • packages/trigger-sdk/test/chat-turn-correlation.test.ts
  • apps/webapp/app/services/realtime/s2realtimeStreams.server.ts
  • docs/ai-chat/client-protocol.mdx
  • packages/trigger-sdk/src/v3/chat.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (41)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 10)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (2, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (11, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (1, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (3, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (9, 12)
  • GitHub Check: sdk-compat / Node.js 26.4 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (7, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (10, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 10)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (4, 12)
  • GitHub Check: sdk-compat / Node.js 22.23 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: sdk-compat / Node.js 20.20 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (8, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (12, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (5, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 10)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (6, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 10)
  • GitHub Check: sdk-compat / Node.js 24.18 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 10)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 10)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 10)
  • GitHub Check: sdk-compat / Deno Runtime
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 10)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 10)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 10)
  • GitHub Check: sdk-compat / Cloudflare Workers
  • GitHub Check: sdk-compat / Bun Runtime
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp
  • GitHub Check: packages / 🧪 Unit Tests: Packages (2, 3)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (1, 3)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (3, 3)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: code-quality / code-quality
  • GitHub Check: audit
  • GitHub Check: 🛡️ E2E Auth Tests (full)
  • GitHub Check: audit
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Build and publish previews

Walkthrough

Realtime append methods now return the appended sequence number, and both append routes include it in successful responses. The chat SDK propagates this value through message and action sends, passes it to stream subscriptions, and skips earlier turn-complete records based on their input cursor. New tests cover correlated, matching, and legacy stream completion behavior. A changeset declares a patch release for the SDK.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change but omits required template sections like issue closure, checklist, testing, changelog, and screenshots. Add the missing template sections: Closes #issue, checklist, testing steps, changelog summary, and screenshots or a note that none are needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. 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 describes the main fix: preventing a chat message from being lost after an action.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/tri-11952-chatagent-transport-a-send-right-after-an-action-closes-its

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.

@ericallam ericallam force-pushed the feature/tri-11952-chatagent-transport-a-send-right-after-an-action-closes-its branch from 206e7f5 to 00dce9a Compare July 11, 2026 08:28
@pkg-pr-new

pkg-pr-new Bot commented Jul 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

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

trigger.dev

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

@trigger.dev/core

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

@trigger.dev/python

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

@trigger.dev/react-hooks

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

@trigger.dev/redis-worker

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

@trigger.dev/rsc

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

@trigger.dev/schema-to-json

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

@trigger.dev/sdk

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

commit: 96e5ad3

coderabbitai[bot]

This comment was marked as resolved.

@ericallam ericallam force-pushed the feature/tri-11952-chatagent-transport-a-send-right-after-an-action-closes-its branch from 00dce9a to f8da664 Compare July 11, 2026 08:32
@ericallam ericallam marked this pull request as ready for review July 11, 2026 08:38

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@ericallam ericallam force-pushed the feature/tri-11952-chatagent-transport-a-send-right-after-an-action-closes-its branch from f8da664 to 96e5ad3 Compare July 11, 2026 08:52
@ericallam ericallam merged commit 9b3a7bd into main Jul 11, 2026
59 checks passed
@ericallam ericallam deleted the feature/tri-11952-chatagent-transport-a-send-right-after-an-action-closes-its branch July 11, 2026 11:46
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