Title: chat.headStart relay ends the first turn after one empty session.out long-poll window (SDK 4.7.7) · Issue #5056 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: chat.headStart relay ends the first turn after one empty session.out long-poll window (SDK 4.7.7) · Issue #5056 · triggerdotdev/trigger.dev
X Title: chat.headStart relay ends the first turn after one empty session.out long-poll window (SDK 4.7.7) · Issue #5056 · triggerdotdev/trigger.dev
Description: chat.headStart relay ends the first turn after one empty session.out long-poll window SDK: @trigger.dev/sdk 4.7.7 (also present in 0.0.0-rc-4-8-0-20261021151928 and 4.8.0-webhooks.20261020092920) What happens On a head-start first turn, ...
Open Graph Description: chat.headStart relay ends the first turn after one empty session.out long-poll window SDK: @trigger.dev/sdk 4.7.7 (also present in 0.0.0-rc-4-8-0-20261021151928 and 4.8.0-webhooks.20261020092920) W...
X Description: chat.headStart relay ends the first turn after one empty session.out long-poll window SDK: @trigger.dev/sdk 4.7.7 (also present in 0.0.0-rc-4-8-0-20261021151928 and 4.8.0-webhooks.20261020092920) W...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/issues/5056
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"chat.headStart relay ends the first turn after one empty session.out long-poll window (SDK 4.7.7)","articleBody":"### `chat.headStart` relay ends the first turn after one empty `session.out` long-poll window\n\n**SDK:** `@trigger.dev/sdk` 4.7.7 (also present in `0.0.0-rc-4-8-0-20261021151928` and `4.8.0-webhooks.20261020092920`)\n\n**What happens**\n\nOn a head-start first turn, `stitchHandoverStream` (`dist/esm/v3/chat-server.js`) reads the agent's `session.out` once with `apiClient.subscribeToSessionStream`. When a tool runs for more than ~60 s without writing a record, the long-poll window closes empty, the `for await` loop ends, the relay writes `trigger:session-state` and closes the response — without `trigger:turn-complete`. The browser transport's `sendMessagesViaHandover` then clears `isStreaming`, so the UI treats the turn as finished while the agent run keeps going and later completes normally.\n\nMeasured in a browser: the `/api/chat` body ended 59,994 ms and 60,003 ms after the last chunk, both times with `trigger:session-state` and no `turn-complete`.\n\n**Why it looks like a bug**\n\n`docs/ai-chat/client-protocol.mdx` § Stream timeout: \"If nothing arrives by the deadline, the server sends `data: [DONE]` and closes. Reconnect with `Last-Event-ID` to continue.\" The browser transport does this (`resumeAfterEof`); the head-start relay does not.\n\n**Repro**\n\n1. `chat.headStart` route + `chat.agent` with a tool that sleeps 90 s without writing to the stream.\n2. Send the first message of a new chat through the transport's `headStart` option.\n3. The response ends ~60 s into the tool; the run finishes the turn later.\n\n**Fix we are running (patch on 4.7.7)**\n\nLoop the `session.out` read until `turn-complete` or abort, resuming from the last seen record, with `waitBeforeEofResubscribe` between empty windows:\n\n```js\nlet emptyWindows = 0;\nwhile (!turnComplete && !subscriptionSignal.aborted) {\n if (emptyWindows > 0) await waitBeforeEofResubscribe(emptyWindows, subscriptionSignal);\n let windowHadRecords = false;\n const resumeFrom = latestEventId ?? customerLastEventId;\n const agentStream = await apiClient.subscribeToSessionStream(chatId, \"out\", {\n ...(resumeFrom != null ? { lastEventId: resumeFrom } : {}),\n signal: subscriptionSignal,\n onPart: (part) => { windowHadRecords = true; if (part.id) latestEventId = part.id; },\n onControl,\n });\n // existing for-await / AbortError handling\n emptyWindows = windowHadRecords ? 0 : emptyWindows + 1;\n}\n```\n\nRelated: `docs/ai-chat/fast-starts.mdx` says the handler keeps the response open for the whole first turn, so the serverless `maxDuration` must cover it. It may be worth noting that a first turn longer than the platform maximum still ends the relay, and that the transport does not fall back to `session.out` when the head-start response ends or errors before `turn-complete`.\n","author":{"url":"https://github.com/Axelj00","@type":"Person","name":"Axelj00"},"datePublished":"2026-10-23T11:05:41Z","url":"https://github.com/triggerdotdev/trigger.dev/issues/5056"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fb4bec0a-3e04-0b89-611f-7b82f96f45c9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D946:3F87F:10982C1:172DCE9:6AFAD88F |
| html-safe-nonce | f2478dc0ec414cafb6212c1091b17f1d68391e3175e3fd06fdb9f5d728552914 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTQ2OjNGODdGOjEwOTgyQzE6MTcyRENFOTo2QUZBRDg4RiIsInZpc2l0b3JfaWQiOiI2ODUxMjc4NzE2NTEzNDc0NzAzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3f608768a3f2d62f3fea23c7c74b0be364f8388c5a3fb76311139ad628b15ee7 |
| hovercard-subject-tag | issue:5996617595 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/triggerdotdev/trigger.dev/5056/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2bf41a25f5085326be5edf84fe14feca7db5b3e92d3820e7b6e48a8be8b47e64/triggerdotdev/trigger.dev/issues/5056 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2bf41a25f5085326be5edf84fe14feca7db5b3e92d3820e7b6e48a8be8b47e64/triggerdotdev/trigger.dev/issues/5056 |
| og:image:alt | chat.headStart relay ends the first turn after one empty session.out long-poll window SDK: @trigger.dev/sdk 4.7.7 (also present in 0.0.0-rc-4-8-0-20261021151928 and 4.8.0-webhooks.20261020092920) W... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Axelj00 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 02f4c00e74911c7cd779fc232c3130cee49eb39fd0ed4bfe3eea3b82c7c18084 |
| turbo-cache-control | no-preview |
| go-import | github.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git |
| octolytics-dimension-user_id | 95297378 |
| octolytics-dimension-user_login | triggerdotdev |
| octolytics-dimension-repository_id | 572570113 |
| octolytics-dimension-repository_nwo | triggerdotdev/trigger.dev |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 572570113 |
| octolytics-dimension-repository_network_root_nwo | triggerdotdev/trigger.dev |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 33c41e9d150e44415272934d676dc63c57d89c3b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width