Repository navigation
fix(web-session-tabs): repair retired live renderer epoch after headless takeover - #21932
shahidbeig-a11y wants to merge 14 commits into
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds bounded repair for remote session-tab snapshots rejected because their publication epoch is retired. Non-authoritative receipts remain fenced and schedule a coalesced, generation-checked repair. An authoritative refresh can revive the confirmed epoch and continue through receipt, recovery, and decision gates. Synchronization lifecycle code enables and clears repair state. New tests cover returning renderer publishers, tab additions and removals, non-authoritative rejection, and delayed headless frames. Priority: ➖ Normal Severity of issue fixed: Medium 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Clear retired-epoch repair state when clearing the environment. · tracking-lifecycle.ts:190
src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts:190
🩺 Stability & Availability | 🟠 Major | ⚡ Quick winClear retired-epoch repair state when clearing the environment.
The generation change invalidates pending timers, but it does not remove a
RepairStatewhose timer is alreadynull. If the previous connection exhausted its attempts, a replacement connection with the same environment and worktree IDs inherits that budget and cannot schedule repair until the 60-second decay period.Delete all repair entries for
trimmedEnvironmentIdduring this cleanup.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 8dce7595-d7d3-4be1-8aaf-85c71f97efdd
📒 Files selected for processing (8)
src/renderer/src/runtime/web-runtime-session-snapshot.tssrc/renderer/src/runtime/web-session-tabs-retired-epoch-repair.test.tssrc/renderer/src/runtime/web-session-tabs-sync/publisher-identity-fences.tssrc/renderer/src/runtime/web-session-tabs-sync/retired-epoch-repair.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking-decisions.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking.tssrc/renderer/src/runtime/web-session-tabs-sync/use-web-session-tabs-sync.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
Important
The new regression suite does not pass on this head — running it with the repo's vitest config fails 3 of 6 tests, so CI will be red until the fixture is fixed. Separately, the authoritative revival is applied before the ordering gates that reject stale frames, which can reopen the fence for a superseded generation.
Reviewed changes
- Authoritative census flag —
authoritativethreaded throughrecordReceivedWebSessionTabsSnapshot,shouldApplyRecoveredWebSessionTabsSnapshot,decideWebSessionTabsSnapshot, andrefreshWebRuntimeSessionTabsSnapshot. - Retired-epoch repair scheduler — new
retired-epoch-repair.tsschedules a bounded, decayingsession.tabs.listafter a retired-epoch frame is dropped, enabled when the mirror mounts. - Lineage revival —
reviveRetiredSessionTabsPublicationEpochun-retires every retired epoch sharing publication lineage with the epoch the census names. - Lifecycle hooks — repair state dropped per worktree on retraction and reset alongside the freshness maps for tests.
- Regression test — new
web-session-tabs-retired-epoch-repair.test.tscovering renderer R → temporary headless H → returning R, with new tabs, removals, and delayed-H rejection.
ℹ️ The repair scheduler itself has no direct unit coverage
web-session-tabs-retired-epoch-repair.test.ts never imports retired-epoch-repair.ts; it calls recordReceivedWebSessionTabsSnapshot / shouldApplyRecoveredWebSessionTabsSnapshot / decideWebSessionTabsSnapshot directly. That leaves scheduling, coalescing of repeat drops, the attempt cap and its 60s decay, timer cancellation on worktree removal and environment teardown, and the success re-check all untested — the local counterpart's retired-epoch-repair.test.ts asserts cancellation for a vanished worktree, and this port's dropped prune (see the forgetWebRetiredEpochRepairsOutside comment) is exactly what that test would have caught.
Technical details
# Missing scheduler coverage
## Affected sites
- `src/renderer/src/runtime/web-session-tabs-sync/retired-epoch-repair.ts` — scheduling, coalescing, cap, decay, cancellation.
- `src/renderer/src/runtime/web-session-tabs-retired-epoch-repair.test.ts` — imports none of it.
## Required outcome
- Direct tests for `scheduleWebRetiredEpochRepair` (coalescing, cap + decay, generation fence) and `forgetWebRetiredEpochRepairsOutside` / `forgetWebRetiredEpochRepairsForWorktree`, mirroring `local-structured-session-tabs-sync/retired-epoch-repair.test.ts`.
## Suggested approach (optional)
- Inject a runner as the local module does, or call `enableWebRetiredEpochRepair()` in the test and use fake timers.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
- Fix test fixture parentTabId so mirrored tabs do not collapse - Revive retired epochs only on decide acceptance after ordering gates - Prune repair state on inventory known-set and environment clear - Retry transient repair failures within generation/budget - Add scheduler unit tests (coalesce, cap+decay, generation, forget)
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Forward authoritative inventory metadata to all snapshot… · global-session-inventory-event.ts:71-76
src/renderer/src/runtime/web-session-tabs-sync/global-session-inventory-event.ts:71-76
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winForward authoritative inventory metadata to all snapshot gates.
Both paths mark their inventory as authoritative but process each snapshot with default non-authoritative options. A census that confirms a returning renderer epoch then schedules repair and rejects the frame instead of reviving it.
src/renderer/src/runtime/web-session-tabs-sync/global-session-inventory-event.ts#L71-L76: pass{ authoritative: event.authoritative === true }to receipt, recovery, and decision calls.src/renderer/src/runtime/web-session-tabs-sync/load-initial.ts#L86-L93: pass{ authoritative: result.authoritative === true }to receipt, recovery, and decision calls.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f339d26e-e6db-4aba-815e-1aae6704d7d2
📒 Files selected for processing (8)
src/renderer/src/runtime/web-session-tabs-retired-epoch-repair.test.tssrc/renderer/src/runtime/web-session-tabs-sync/global-session-inventory-event.tssrc/renderer/src/runtime/web-session-tabs-sync/load-initial.tssrc/renderer/src/runtime/web-session-tabs-sync/retired-epoch-repair.test.tssrc/renderer/src/runtime/web-session-tabs-sync/retired-epoch-repair.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking-decisions.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/runtime/web-session-tabs-sync/retired-epoch-repair.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
Important
The regression suite is green now, but the PR still fails CI's changed-code quality gate — pnpm run check:code-quality:changed exits 1 on 8 new findings in the new fence suite. Details inline.
Reviewed changes
- Fixture fix — each mirrored terminal surface now gets its own
parentTabId, so the R→H→R suite lands new tabs and removals instead of collapsing both into one split tab (the three previously red tests now pass). - Scheduler coverage added — new
web-session-tabs-sync/retired-epoch-repair.test.tsexercises coalescing, the attempt cap and 60s decay, the tracking-generation fence, transient-failure retry, and cancel-on-forget. - Revival moved behind the ordering gates —
reviveRetiredSessionTabsPublicationEpochnow runs only insidehostSnapshotAffirmsWorktreeContentson the accepted decide path, andnoteSessionTabsPublicationEpochis skipped while the epoch is retired, so a stale or placeholder census can no longer un-fence a generation. - Repair-state pruning wired up — the global inventory and initial
listAllpaths callforgetWebRetiredEpochRepairsOutside, and environment teardown clears all repair entries. - Transient-failure retry — the repair lane re-schedules a bounded attempt from the catch path while its tracking generation is current.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Keep repairs until the bootstrap inventory is current. · load-initial.ts:82-85
src/renderer/src/runtime/web-session-tabs-sync/load-initial.ts:82-85
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winKeep repairs until the bootstrap inventory is current.
A stream frame can arrive after
requestReceivedFrameand supersede thislistAllresponse. This code removes repairs for omitted worktrees beforeinitialInventorySupersededandinitialInventoryStillCurrentreject that stale response. The affected worktree then has no pending authoritative refresh, so its retired epoch stays fenced and its remote tabs remain stale.Move this prune after the currentness check. Run it only when this inventory still owns the request boundary.
Proposed fix
- // Mirror local apply-time prune against the listAll census. - forgetWebRetiredEpochRepairsOutside( - environmentId, - new Set(result.snapshots.map((snapshot) => snapshot.worktree)) - ) const receivedFrames = result.snapshots.map((snapshot) => recordReceivedWebSessionTabsSnapshot( ... const initialInventoryStillCurrent = latestReceivedSessionTabsFrameByEnvironment.get(environmentId) === requestReceivedFrame && (latestReceivedSessionTabsInventoryFrameByEnvironment.get(environmentId) ?? 0) <= requestReceivedFrame + if (initialInventoryStillCurrent) { + forgetWebRetiredEpochRepairsOutside( + environmentId, + new Set(result.snapshots.map((snapshot) => snapshot.worktree)) + ) + }Based on learnings: scheduled and deferred state must not act on stale generation evidence.
Source: Learnings
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 99f9b107-3807-4209-9b3c-a43671d767f6
📒 Files selected for processing (3)
src/renderer/src/runtime/web-session-tabs-retired-epoch-repair.test.tssrc/renderer/src/runtime/web-session-tabs-sync/global-session-inventory-event.tssrc/renderer/src/runtime/web-session-tabs-sync/load-initial.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/runtime/web-session-tabs-retired-epoch-repair.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Forwarded authoritative inventory metadata — the global
snapshotsinventory event now passesauthoritative: event.authoritative === trueintorecordReceivedWebSessionTabsSnapshot,shouldApplyRecoveredWebSessionTabsSnapshot, anddecideWebSessionTabsSnapshot, so an authoritative host census that names a returning renderer epoch revives and applies it instead of scheduling another repair. - Forwarded bootstrap authority metadata — the initial
session.tabs.listAllresult threadsresult.authoritative === truethrough the same three gates, matching the local structured-session path. - Changed-code quality gate fixed —
sessionTabsFreshnessKeyis folded into the existing./web-session-tabs-sync/trackingimport and every flagged assertion in the fence suite now carries aSAFETY:suppression;pnpm run check:code-quality:changedreports 0 new findings.
Both new forwarding sites mirror the established local pattern (local-structured-session-tabs-sync/subscription.ts:99-103, inventory-refresh.ts:71-80), and incremental snapshot/updated subscription frames still omit the flag, so the fence itself stays closed to subscription traffic. Prior pullfrog threads (fixture collapse, missing scheduler coverage, revival escaping the ordering gates, duplicate import, assertion suppressions) are all addressed; the fence suite passes 290/290 and pnpm tc:web is clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Preserved repair state across a stale bootstrap census — the
forgetWebRetiredEpochRepairsOutsideprune inload-initial.tsmoved behind the existinginitialInventoryStillCurrentguard, so asession.tabs.listAllresponse that a newer stream frame has already superseded no longer cancels pending retired-epoch repairs for worktrees missing from its snapshot set.
The guard already gated the fullInventory metadata on the same condition, so the prune now shares a consistent notion of "this census still owns the request boundary". Both new commits touch only load-initial.ts; the full fence suite still passes 290/290 and the changed-code quality gate reports 0 new findings.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
After a temporary headless publisher owns a remote worktree, the live renderer epoch stays in
retired. Fresh host snapshots from that returning renderer are rejected, so new tabs stay hidden and closed tabs linger on the client. This mirrors the local structured-session repair from #18906: keep the fence for subscription frames, and revive only when an authoritativesession.tabs.listcensus names the epoch current.What Changed
retired-epoch-repair.ts), enabled when the web session-tabs mirror mounts.recordReceivedWebSessionTabsSnapshot,shouldApplyRecoveredWebSessionTabsSnapshot, anddecideWebSessionTabsSnapshotacceptauthoritative: trueto revive the named publication lineage (not every retired epoch) before applying.refreshWebRuntimeSessionTabsSnapshotpasses that flag through so eager list results can repair the poisoned history.Why
The release already repairs this for local structured sessions (
applyLocalStructuredSessionTabSnapshots+ #18906). The remote terminal mirror used the same fence without an authoritative repair lane, so a live renderer returning after a headless epoch stayed locked out of its own worktree.Linked Issue
Fixes #21928
Visual Proof
N/A — unit coverage of the fence/repair gates and tab apply path.