bug: chat transport `watch: true` duplicates the previous assistant message when a turn starts out-of-band, and `useChat` status never returns to ready
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- typescript
Línea de trabajo
Start in packages/trigger-sdk/src/v3/chat.ts, especially the “Re-arm per-turn events” branch, and trace how watch mode handles turn completion with useChat. Compare that behavior with the AI SDK’s single-message-per-request stream processing. Done means out-of-band turns render without duplicating or corrupting the previous assistant message, useChat returns to ready, and an idle session does not reconnect indefinitely.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Provide environment information
System:
OS: macOS 26.6
CPU: (14) arm64 Apple M4 Pro
Memory: 294.73 MB / 48.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.14.0
Yarn: 1.22.22
npm: 11.9.0
pnpm: 10.25.0
bun: 1.3.5
trigger.dev CLI 4.5.4, @trigger.dev/sdk 4.5.4
ai 7.0.31, @ai-sdk/react 4.0.34, next 16.2.10
Describe the bug
I am building on chat.agent() with durable sessions, and background tasks wake a conversation by appending a user message to session.in (a data load finishing, a scheduled heartbeat). To render those wake turns live in open tabs I turned on watch: true on useTriggerChatTransport. When the wake turn streams in, the tab shows the previous assistant message twice, and the new turn's content renders inside a message that also contains the previous turn's parts. A refresh shows the conversation correctly, so persistence is fine; it is the live view that corrupts.
I dug in and I am fairly confident about the mechanism. Watch mode keeps one useChat response stream open across turns: on turn-complete the transport re-arms and continues instead of closing (packages/trigger-sdk/src/v3/chat.ts, the "Re-arm per-turn events" branch). But the AI SDK's stream processing is single-message per request: createStreamingUIMessageState seeds one in-progress message, and a start chunk only renames it (state.message.id = chunk.messageId) rather than beginning a new one. So the second turn's start renames the first turn's still-referenced message object and keeps appending parts into it. useChat's write path replaces the last message only when ids match, and after the rename they do not, so the renamed message (old parts plus new parts) is pushed alongside the stale snapshot of the first one. Two copies, and a structurally wrong message.
I verified the wire is innocent: replaying the session's .out stream from seq 0 shows each turn's chunks exactly once. The duplicate is manufactured client-side by the interaction above, which I think means any watch: true consumer rendering through useChat hits this on every out-of-band turn.
Two side effects of the same root, for completeness: because the stream never closes, useChat status never returns to "ready" after a watched turn (composers stay disabled, onFinish never fires), and once the session goes idle the subscription reconnects on its 60s stall timer forever.
Reproduction repo
The project is a hackathon submission that goes public at https://github.com/mcheemaa/rendi in the next couple of days. The three steps below reproduce on any chat.agent() project with useChat, and I am happy to put together a minimal public repro if that helps.
To reproduce
- Any
chat.agent()task plususeTriggerChatTransport({ watch: true })anduseChat. Send a message, let the turn complete, keep the tab open. - From a task or a script, append a user message to the same session out-of-band:
sessions.open(chatId).in.send({ kind: "message", payload: { chatId, trigger: "submit-message", messageId, message } }). - Watch the open tab as the new turn streams: the previous assistant message duplicates, the new content lands under the renamed message, and the composer stays on its streaming state indefinitely.
Additional information
Possibly related, while debugging this I noticed the dashboard's session view has its own trouble with these out-of-band messages: on first load it renders the injected user message directly under the conversation's first user message, before the previous turn's output, and toggling Raw and Rendered a couple of times re-sorts it into the correct position (easy to see on any session that has one of these injected messages). Different surface, but it looks like the same underlying edge: a session.in message that no browser sent, which rendering layers do not expect between turns. Happy to file that separately if that is more useful for triage.
The workaround I shipped, in case it helps others: drop watch: true; while idle, poll persisted messages and adopt new rows by id; when the adopted tail is a user-role message, set the session state's isStreaming back to true and call resumeStream(). reconnectToStream then attaches from the stored cursor, and because the last message is user-role the AI SDK seeds a fresh assistant message, so the wake turn streams in live and correctly.
On a fix direction: it seems like the transport is the right place, since the AI SDK's one-message-per-request model is its documented contract. If watch mode ended the useChat request at each turn-complete and surfaced the next turn as something the client attaches to (an event plus resumeStream, or an auto-reattach), each turn would get its own request and a fresh message.
- Lenguaje dominante
- TypeScript
- Estrellas
- 16.5k
- Forks
- 1.5k
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 17
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de triggerdotdev/trigger.dev
-
bug: retry.fetch ignores the caller's abort signal and retries aborted requestsQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
triggerdotdev/trigger.dev#5116 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug: Chat transport crashes on Safari < 17.4: AbortSignal.any is not a functionQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
triggerdotdev/trigger.dev#5098 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug: Side menu items lose their active state on detail pagesQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
triggerdotdev/trigger.dev#5088 ·
Los mantenedores suelen responder en 1 día
-
bug: RBAC loader logs "plugin found but failed to load" when @triggerdotdev/plugins is simply not installedQuizá libre de nuevo @itsfaryal la tomó hace 17 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
triggerdotdev/trigger.dev#5083 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
triggerdotdev/trigger.dev#5072 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de triggerdotdev/trigger.dev
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
bug platform-android
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Termix-SSH/Mobile#146 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
devswha/herdr-web-ui#3875 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
-
area: runtime chore cli consistency dependencies developer-experience difficulty: easy discovery documentation enhancement good first issue help wanted hygiene json-output packaging priority: P3 tests version
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día