fix(terminal): stop repeated history refresh replays - #342
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Add per-request generation or token validation to prevent stale refresh responses from mutating the active terminal.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This pull request prevents repeated terminal history replays by routing refreshes correctly, suppressing duplicate SSE recovery, and coalescing refresh cycles.
Changes:
- Scope refresh events to the active session.
- Avoid redundant SSE recovery when WebSocket output is complete.
- Add concurrency and browser regression coverage.
File summaries
| File | Summary |
|---|---|
test/terminal-scroll-intent.test.ts | Updates refresh-path assertions. |
test/terminal-refresh-routing.test.ts | Adds routing and coalescing tests. |
test/opencode-resize.test.ts | Adds browser regression coverage. |
src/web/public/app.js | Implements refresh routing and replay locking; a critical stale in-flight request race remains unresolved. |
Review details
Suppressed comments (1)
src/web/public/app.js:1869
_wsReadyonly says that the current socket is open; it does not prove it received the output that was dropped while a previous socket was reconnecting. During that gap SSE is the fallback, and its anonymous drain frame can arrive afteronopenflips_wsReady; returning here then discards the only history-recovery signal, while_connectWs()only sends a resize and does not reload history. Track WS continuity/fallback state (or force one recovery after reconnect) so a drain covering a WS gap is still honored, and add a reconnect-gap regression test.
if (this._wsReady && this._wsSessionId === this.activeSessionId) return;
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Uh oh!
There was an error while loading. Please reload this page.
Ark0N
commented
Aug 27, 2026
Thanks for this, and particularly for the regression harness. All three failure modes you describe were real. They were also fixed on master a few hours before you opened this, by #339, which merged on 2026-08-24 and shipped in 1.23.0. Your branch is based on 9cfd8e8, which predates that merge, and that is where the conflict in
So the routing and the coalescing are both already in. The one piece of yours with no equivalent on master is the WebSocket-reopen recovery: Closing as superseded. If you still see the replay loop on 1.23.1 please reopen with what you are seeing, and if you want to pursue the reconnect-gap recovery, a small PR against current master making the case for it would be very welcome. |
Summary
session:needsRefreshSSE frames to the active sessionReproduction
The new regression harness failed in three independent ways on
master:_onSessionNeedsRefreshfor the active tabTogether, sustained terminal output can backpressure the duplicate SSE stream, whose drain signal makes the browser fetch, clear, and replay history. That replay can cause more backpressure and visibly loop old terminal history.
Verification
npm test(312 files passed, 6097 tests passed)npm run typechecknpm run lintnpm run format:checknpm run check:frontend-syntaxnpm run test:browser -- test/opencode-resize.test.ts -t "does not replay history"The Playwright regression dispatches both a background-session refresh and an anonymous SSE backpressure refresh with an active terminal WebSocket, then verifies that the page makes zero
/terminalhistory requests.