Repository navigation
Conversation
Greptile SummaryThe PR adds conservative pruning for stale null-PTY remote-tab mirrors and routes catalog-gap closes using environment-qualified live PTY ownership.
Confidence Score: 4/5The PR is not yet safe to merge because a failed or sufficiently delayed host close can restore a remote tab that was already removed locally. The renderer still prunes the local mirror before the host close succeeds, while snapshot suppression expires before the RPC timeout and is cleared on failure, allowing unchanged authoritative host state to rematerialize the tab. Files Needing Attention: src/renderer/src/components/terminal/terminal-tab-actions.ts, src/renderer/src/runtime/web-session-close-intent.ts, src/renderer/src/runtime/web-runtime-session-tab-lifecycle.ts
|
| Filename | Overview |
|---|---|
| src/renderer/src/components/terminal/terminal-tab-actions.ts | Adds live-PTY owner routing for catalog gaps, but the previously reported failed-close restoration path remains. |
| src/renderer/src/components/terminal/terminal-tab-runtime-environment.ts | Conservatively resolves one environment-qualified PTY owner and reports conflicting ownership. |
| src/renderer/src/runtime/web-session-tabs-sync.ts | Adds age-, authority-, ownership-, and reconnect-gated pruning for stale null-PTY mirror tabs. |
| src/renderer/src/components/terminal/terminal-tab-runtime-close-routing.test.ts | Covers agreeing catalog-gap ownership, conflicts, and persisted-layout-only evidence. |
| src/renderer/src/runtime/web-session-tabs-sync.test.ts | Adds extensive regression coverage for stale ghost pruning and preservation guards. |
| config/reliability-gates.jsonc | Registers the new close-routing and reconciliation contracts in the terminal reliability gate. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Remote terminal tab] --> B{Live PTY owners agree?}
B -->|No conflict| C{Runtime owner available?}
B -->|Conflict| X[Cancel close]
C -->|Yes| D[Prune local mirror]
D --> E[Send close to owning host]
C -->|No route or owner| X
F[Authoritative host inventory] --> G{Null PTY older than grace period?}
G -->|No| H[Retain placeholder]
G -->|Yes| I{Owner matches and no reconnect evidence?}
I -->|Yes| J[Prune stale viewer ghost]
I -->|No| H
Reviews (4): Last reviewed commit: "fix(terminal): preserve pending host mir..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 40f060f15f5925b8bfe67a499acfd55ace38f01e and ef39f9c. 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe renderer now resolves terminal runtime ownership from live PTY bindings and routes catalog-gap closes to the owning remote runtime. Conflicting or layout-only evidence cancels the close. Web session synchronization now uses host authority, runtime ownership, reconnect evidence, and grace periods when retaining or pruning null-PTY terminal tabs. Snapshot APIs and the test harness accept the expanded synchronization state. Tests cover runtime resolution, close routing, and terminal-tab reconciliation cases. Merge Risk: 🔵 Low · up to This change removes stale remote terminal tabs only after authoritative ownership and grace-period checks, and improves close routing during catalog gaps without terminating host processes. A bounded stale-message history could still allow an unusually delayed snapshot to remove a current viewer tab after many runtime rotations, so merge is reasonable with explicit owner awareness and follow-up. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description follows the required template and explains the problem, changes, rationale, linked issue, visual impact, testing, review, compatibility considerations, and checklist status. Automated validation is documented in detail. Full details: Linked Issues checkExplanation The implementation addresses issue Full details: Out of Scope Changes checkExplanation The production changes, focused tests, test harness update, and reliability-gate updates support the stale terminal ghost and close-routing objectives. No unrelated feature, UI, or remote-wire changes are evident.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
40f060f to
db340b7
Compare
There was a problem hiding this comment.
Caution
This PR breaks an existing unit test (src/renderer/src/runtime/web-session-tabs-sync-terminal-mirroring.test.ts → "removes a null-pty pending activation tab when the host publishes the initial terminal") and reintroduces a duplicate-tab regression whenever a worktree's explicit runtime owner is not yet resolved — the same catalog-hydration gap this PR is meant to handle safely.
Reviewed changes
- Ghost pruning —
shouldReplaceTerminalTabnow prunes an aged (>= 30s) null-PTY placeholder when the host snapshot affirms worktree contents, the worktree's explicit owner matches the publishing environment, and no reconnect evidence remains; a newnullPtyTabHasRetentionEvidencehelper coversunverifiedPtyLossTabIdsand the reconnect maps. - Close routing — a new
resolveTerminalTabRuntimeEnvironmentresolves a tab's remote owner from live PTY bindings (none/runtime/conflict), andcloseTerminalTabroutes explicit close to that live owner during a worktree-catalog gap, failing closed on conflicting or unresolved ownership. - State/type widening —
applyWebSessionTabsSnapshot*now acceptWebSessionTabsSyncState & WorktreeRuntimeOwnerState, with four reconnect maps added to the partial pick. - Tests & gates — new focused suites for pruning and close routing, plus reliability-gate invariant/oracle text and command-list updates.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
The new test models a resolved worktree owner, but it does not address the production regression it was red for. When the owner is unresolved — the catalog-hydration gap this PR otherwise handles — shouldReplaceTerminalTab still retains a pendingActivationSpawn null-PTY placeholder alongside the host-published mirror, producing a duplicate tab that main removed.
Reviewed changes
web-session-tabs-sync-terminal-mirroring.test.ts— the previously failing "removes a null-pty pending activation tab when the host publishes the initial terminal" test now suppliesrepos/worktreesByReposogetExplicitRuntimeEnvironmentIdForWorktreeresolves to the publishing environment, makingtabBelongsToEnvironmenttrue again.- No production code changed in this commit — the
tabBelongsToEnvironmentguard on thependingActivationSpawnreplacement branch remains as first reviewed.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Since the prior review (db340b7), one commit landed that resolves the placeholder-parity regression during unresolved worktree ownership.
shouldReplaceTerminalTabnow replaces on a missing worktree route — thependingActivationSpawnbranch acceptstabBelongsToEnvironment || worktreeOwnerIsMissing, whereworktreeOwnerIsMissingisresolveWorktreeOperationRouteResult(state, worktreeId).kind === 'missing', so a catalog-hydration gap no longer strands a null-PTY placeholder next to the host-published mirror.- Ambiguous ownership still fails closed — the new "keeps a pending activation tab when worktree ownership is ambiguous" test pins conflicting detected hosts to the retain path.
- Reverted the test-only workaround — the
repos/worktreesByRepofixtures previously added toweb-session-tabs-sync-terminal-mirroring.test.tsare removed; the original minimal-state test now passes through the production guard.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

ELI5
A paired viewer could keep blank terminal tabs after the owning host had stopped publishing them. This waits through a short create window, then removes only viewer-side ghosts when a published host inventory and explicit worktree owner agree. Closing a real remote tab can also reach its host during a catalog hydration gap, but ambiguous ownership fails closed.
What Changed
Why
Current
origin/mainreproduced both failures deterministically: an aged null-PTY viewer placeholder survived an authoritative omission, and a catalog-gap close dispatched no host call. Pruning belongs in renderer mirror reconciliation and must never infer PTY death; explicit close routing belongs at the live PTY ownership boundary.Linked Issue
Fixes #11800
Related: #17767. Supersedes #11801; the implementations should not be combined.
Visual Proof
N/A — this changes renderer state reconciliation and close routing without adding or changing UI.
Testing
Deterministic oracle:
origin/main(f8a3f2c7c0when reproduced): stale ghost remained; catalog-gap close issued zero host callsgit diff HEADemptyValidation:
pnpm tcpnpm tc:weboxlint --deny-warningspnpm run check:code-quality:changedpnpm run check:max-lines-ratchetpnpm run check:reliability-gatespnpm run build:electron-vitegit diff --checkAI Disclosure
Review
Three fresh
gpt-5.6-lunaCodex reviewers independently assessed the ownership boundary, product/compatibility decisions, and regression risk. Valid initial findings were reproduced and fixed; all three final bounded reviews returnedCLEAN.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)