Skip to content

fix(web-session-tabs): repair retired live renderer epoch after headless takeover - #21932

Closed
shahidbeig-a11y wants to merge 14 commits into
stablyai:mainfrom
shahidbeig-a11y:cursor/fix-web-session-tabs-retired-epoch-repair-21928
Closed

shahidbeig-a11y wants to merge 14 commits into
stablyai:mainfrom
shahidbeig-a11y:cursor/fix-web-session-tabs-retired-epoch-repair-21928

Conversation

@shahidbeig-a11y

Copy link
Copy Markdown
Contributor

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 authoritative session.tabs.list census names the epoch current.

What Changed

  • Rejected retired-epoch frames on the remote/web path schedule a bounded, host-scoped authoritative refresh (retired-epoch-repair.ts), enabled when the web session-tabs mirror mounts.
  • recordReceivedWebSessionTabsSnapshot, shouldApplyRecoveredWebSessionTabsSnapshot, and decideWebSessionTabsSnapshot accept authoritative: true to revive the named publication lineage (not every retired epoch) before applying.
  • refreshWebRuntimeSessionTabsSnapshot passes that flag through so eager list results can repair the poisoned history.
  • Regression test: renderer R → temporary headless H → returning R; new tabs and removals apply after authoritative confirmation; delayed H frames stay rejected.

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.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e431ad34-af08-46af-8618-5708eee1f198

📥 Commits

Reviewing files that changed from the base of the PR and between 21a3254 and a97653a.

📒 Files selected for processing (1)
  • src/renderer/src/runtime/web-session-tabs-sync/load-initial.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.48% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the session-tab fix and the retired live renderer epoch repair. It is concise and matches the primary change.
Description check ✅ Passed The description covers the core user impact, implementation, rationale, linked issue, and visual-proof requirement. It is mostly complete, although it omits the template's Testing, Review, Notes, and …
Linked Issues check ✅ Passed Issue [#21928] requires bounded, host-scoped repair for retired remote session-tab epochs. retired-epoch-repair.ts provides coalescing, attempt limits, backoff, generation checks, and lifecycle clea…
Out of Scope Changes check ✅ Passed The changes remain within [#21928]. Repair scheduling, authoritative metadata propagation, lifecycle cleanup, runtime activation, and focused regression tests directly support remote session-tab recov…
  • Fix all pre-merge checks with AI

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 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 win

Clear retired-epoch repair state when clearing the environment.

The generation change invalidates pending timers, but it does not remove a RepairState whose timer is already null. 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 trimmedEnvironmentId during this cleanup.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 8dce7595-d7d3-4be1-8aaf-85c71f97efdd

📥 Commits

Reviewing files that changed from the base of the PR and between afb618f and 4a8a22b.

📒 Files selected for processing (8)
  • src/renderer/src/runtime/web-runtime-session-snapshot.ts
  • src/renderer/src/runtime/web-session-tabs-retired-epoch-repair.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/publisher-identity-fences.ts
  • src/renderer/src/runtime/web-session-tabs-sync/retired-epoch-repair.ts
  • src/renderer/src/runtime/web-session-tabs-sync/tracking-decisions.ts
  • src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts
  • src/renderer/src/runtime/web-session-tabs-sync/tracking.ts
  • src/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — authoritative threaded through recordReceivedWebSessionTabsSnapshot, shouldApplyRecoveredWebSessionTabsSnapshot, decideWebSessionTabsSnapshot, and refreshWebRuntimeSessionTabsSnapshot.
  • Retired-epoch repair scheduler — new retired-epoch-repair.ts schedules a bounded, decaying session.tabs.list after a retired-epoch frame is dropped, enabled when the mirror mounts.
  • Lineage revival — reviveRetiredSessionTabsPublicationEpoch un-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.ts covering 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 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 win

Forward 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a8a22b and 5ecb992.

📒 Files selected for processing (8)
  • src/renderer/src/runtime/web-session-tabs-retired-epoch-repair.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/global-session-inventory-event.ts
  • src/renderer/src/runtime/web-session-tabs-sync/load-initial.ts
  • src/renderer/src/runtime/web-session-tabs-sync/retired-epoch-repair.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/retired-epoch-repair.ts
  • src/renderer/src/runtime/web-session-tabs-sync/tracking-decisions.ts
  • src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts
  • src/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts exercises coalescing, the attempt cap and 60s decay, the tracking-generation fence, transient-failure retry, and cancel-on-forget.
  • Revival moved behind the ordering gates — reviveRetiredSessionTabsPublicationEpoch now runs only inside hostSnapshotAffirmsWorktreeContents on the accepted decide path, and noteSessionTabsPublicationEpoch is 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 listAll paths call forgetWebRetiredEpochRepairsOutside, 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 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 win

Keep repairs until the bootstrap inventory is current.

A stream frame can arrive after requestReceivedFrame and supersede this listAll response. This code removes repairs for omitted worktrees before initialInventorySuperseded and initialInventoryStillCurrent reject 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5ecb992 and ea28b32.

📒 Files selected for processing (3)
  • src/renderer/src/runtime/web-session-tabs-retired-epoch-repair.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/global-session-inventory-event.ts
  • src/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Forwarded authoritative inventory metadata — the global snapshots inventory event now passes authoritative: event.authoritative === true into recordReceivedWebSessionTabsSnapshot, shouldApplyRecoveredWebSessionTabsSnapshot, and decideWebSessionTabsSnapshot, 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.listAll result threads result.authoritative === true through the same three gates, matching the local structured-session path.
  • Changed-code quality gate fixed — sessionTabsFreshnessKey is folded into the existing ./web-session-tabs-sync/tracking import and every flagged assertion in the fence suite now carries a SAFETY: suppression; pnpm run check:code-quality:changed reports 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Preserved repair state across a stale bootstrap census — the forgetWebRetiredEpochRepairsOutside prune in load-initial.ts moved behind the existing initialInventoryStillCurrent guard, so a session.tabs.listAll response 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

nwparker commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded — the linked issue (#21928) has been resolved on main by #27093 (33d90bb066), #27094 (f1a09aa9c2), #27098 (b9abfa9116). Thanks for the contribution!

@nwparker nwparker closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Remote tab mirror rejects its live renderer publisher after a headless epoch, hiding new tabs and retaining closed tabs

2 participants