Skip to content

Commit 2dd9f37

Browse files
authored
fix(core,cli): stop chat.agent uncaught exception on mid-stream abort (#3792)
## Summary A `chat.agent` turn that gets aborted mid-stream (stop generation, idle suspend, cancellation) could surface a `TASK_RUN_UNCAUGHT_EXCEPTION` — `TypeError: Invalid state: Unable to enqueue` — in the dashboard. The run kept working, but the exceptions were loud and confusing. ## Root cause The realtime stream writer batches chunks through `@s2-dev/streamstore`'s `BatchTransform`, which holds them for a short linger window before flushing. When the turn's abort signal fires while a record is still buffered, the stream's writable is aborted and the transform's readable controller is closed — but the pending linger `setTimeout` still fires and calls `controller.enqueue()` on the dead controller, throwing from a timer callback where nothing can catch it. Fixed upstream in `@s2-dev/streamstore@0.22.10`, which wraps the linger flush in a try/catch that discards the closed-controller error. This bumps the dependency across core, the CLI, and the webapp, and adds a regression test against the real `BatchTransform`. Verified end-to-end: a mid-stream stop that previously failed the run with `TASK_RUN_UNCAUGHT_EXCEPTION` now leaves the run healthy.
1 parent e9e2ec1 commit 2dd9f37

5 files changed

Lines changed: 23 additions & 17 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@trigger.dev/core": patch
3+
"trigger.dev": patch
4+
---
5+
6+
Bump `@s2-dev/streamstore` to `0.22.10` to fix a `TASK_RUN_UNCAUGHT_EXCEPTION` ("Invalid state: Unable to enqueue") when a `chat.agent` turn is aborted mid-stream.

apps/webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"@remix-run/serve": "2.17.4",
113113
"@remix-run/server-runtime": "2.17.4",
114114
"@remix-run/v1-meta": "^0.1.3",
115-
"@s2-dev/streamstore": "^0.22.5",
115+
"@s2-dev/streamstore": "^0.22.10",
116116
"@sentry/remix": "9.46.0",
117117
"@slack/web-api": "7.9.1",
118118
"@socket.io/redis-adapter": "^8.3.0",

packages/cli-v3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"@opentelemetry/resources": "2.0.1",
9595
"@opentelemetry/sdk-trace-node": "2.0.1",
9696
"@opentelemetry/semantic-conventions": "1.36.0",
97-
"@s2-dev/streamstore": "^0.22.5",
97+
"@s2-dev/streamstore": "^0.22.10",
9898
"@trigger.dev/build": "workspace:4.5.0-rc.3",
9999
"@trigger.dev/core": "workspace:4.5.0-rc.3",
100100
"@trigger.dev/schema-to-json": "workspace:4.5.0-rc.3",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
"@opentelemetry/sdk-trace-base": "2.0.1",
207207
"@opentelemetry/sdk-trace-node": "2.0.1",
208208
"@opentelemetry/semantic-conventions": "1.36.0",
209-
"@s2-dev/streamstore": "0.22.5",
209+
"@s2-dev/streamstore": "0.22.10",
210210
"dequal": "^2.0.3",
211211
"eventsource": "^3.0.5",
212212
"eventsource-parser": "^3.0.0",

pnpm-lock.yaml

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)