fix(terminal): stop repeated history refresh replays - #342
Open
tailong-wu wants to merge 2 commits into
Open
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.