Qwen Code adds epoch tokens to stop stale SSE cursors after daemon restarts

doudouOUC · ghdev · 2026-07-22

Qwen Code adds epoch tokens to fix stale SSE cursors across daemon restarts

This Qwen Code PR hardens the daemon’s event replay and reconnect path in three ways.

1) Stale cursor detection now uses an epoch token

Every session event bus now generates a random epoch token. That token is returned in session load/resume/create responses, in the non-blocking prompt envelope, and in an X-Qwen-Event-Epoch header on both SSE surfaces.

Clients echo the epoch back on reconnect alongside Last-Event-ID. If the token does not match the current bus epoch, the daemon forces a resync instead of trusting event-id arithmetic. A new detail: 'epochmismatch' marker makes the trigger explicit.

2) Replay compaction keeps correct turn attribution

The compaction engine now preserves turn attribution more carefully:

3) Replay failures are surfaced instead of hidden

If ingest/seed fails, the bus now latches a degraded flag. Replay snapshots built afterward are marked degraded, session-load responses expose replayDegraded, and the daemon logs an operator breadcrumb plus a warning when /acp serves a degraded initial replay.

The TypeScript SDK also learns the epoch, stores it next to the cursor, and sends it on every reconnect, including the subscribe path used inside prompt().

Original post →

More from coding & agent

coding & agent channel →