Repository navigation
fix(mobile): push the materialized handle to a pending-handle terminal (STA-4256) - #15355
brennanb2025 wants to merge 4 commits into
Conversation
…l (STA-4256) A terminal tab published as `pending-handle` promises the client that the host will say something else later. Nothing kept that promise when the tab was published before its PTY existed: `touchMobileSessionSnapshotsForPty` matches on a ptyId the snapshot does not name yet, and no other path re-emits. That was survivable while mobile polled indefinitely. #14916 (STA-4407) bounded the client's pending-handle recovery to 5 attempts ~2s apart, so a client stops asking ~10s after the tab appears. Past that the pane is stranded on the spinner with `activeHandle: null`, which disables the terminal composer AND native chat — starting a new agent session is the flow that crosses it. Record which worktrees we published as `pending-handle`, and re-emit them when a PTY registers. The push carries a bumped snapshotVersion, which is what a client accepts; a re-emit at the same version is dropped by its monotonic gate. Fixes clients that are already shipped and cannot be patched (mobile 0.0.44).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe runtime detects when PTY registration makes a matching pending mobile terminal addressable. It republishes the affected worktree only when addressability changes. Tests verify freshness filtering, ready terminal publication, snapshot version and epoch behavior, duplicate and unrelated registrations, PTY identity mismatches, worktree scoping, reconnects, and deleted worktrees. Merge Risk: 🔵 Low · up to The change restores mobile terminal composition by publishing a ready handle when a pending pane becomes addressable. It is mergeable with owner awareness because the addressability logic is duplicated and could drift in future changes, so follow-up consolidation is advisable. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c4ccbb66-0712-4e97-ae92-52f9dff6ced2
📒 Files selected for processing (2)
src/main/runtime/mobile-pending-handle-materialization.test.tssrc/main/runtime/orca-runtime.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)
7923-7944: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider sharing the "resolved published ptyId for a tab" formula with
findPtyForMobileTerminalTab.Line 7937 recomputes
tab.ptyId ?? tab.parentLayout?.ptyIdsByLeafId?.[tab.leafId] ?? null. This is the same formula thatfindPtyForMobileTerminalTabuses forsnapshotPtyIdelsewhere in this file. Both formulas answer the same question: which PTY does this tab currently reference.Extract the formula into a small private helper, for example
getMobileTerminalSnapshotPtyId(tab), and call it from both sites. If the two copies drift apart later, the drift can reintroduce a variant of the exact stuck pending-handle bug this method exists to fix.♻️ Proposed extraction
+ private getMobileTerminalSnapshotPtyId(tab: RuntimeMobileSessionTerminalTab): string | null { + return tab.ptyId ?? tab.parentLayout?.ptyIdsByLeafId?.[tab.leafId] ?? null + } + private touchMobileSessionTabsForMaterializedPty(pty: RuntimePtyWorktreeRecord): void { ... const matches = snapshot?.tabs.some((tab) => { if (tab.type !== 'terminal' || tab.parentTabId !== pane.tabId || tab.leafId !== pane.leafId) { return false } - const publishedPtyId = tab.ptyId ?? tab.parentLayout?.ptyIdsByLeafId?.[tab.leafId] ?? null + const publishedPtyId = this.getMobileTerminalSnapshotPtyId(tab) return publishedPtyId === null || publishedPtyId === pty.ptyId }) ... }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2554a41e-3a74-49f7-8f64-f9c50a398928
📒 Files selected for processing (2)
src/main/runtime/mobile-pending-handle-materialization.test.tssrc/main/runtime/orca-runtime.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Final review status: LANDReviewed and improved on pushed commit Review outcome
Verification
Compatibility and performance
Visual QAThe existing genuine before-state and healthy-send screenshots remain attached in the PR description. An independent Grok Electron/native-mobile run verified the correct isolated worktree and loaded the native development build, but its pairing setup violated the mobile workspace-protection rule. I stopped the worker immediately, rejected all evidence from that run, cleaned its processes/profile/temporary data, and did not attach its screenshots. Native after-path visual QA is therefore blocked, not claimed; the exact transition is covered at the real The PR description has been updated to match the final targeted implementation and this limitation. No further code changes are recommended before landing. |
The host has no timer and must not acquire one. These pin that the publication is driven by the addressability transition, at each position relative to the client's 5-attempt ~2s recovery budget (#14916): - before: PTY addressable first, so the tab publishes ready and nothing is owed — asserts no spurious materialization push - during: registration inside the window still publishes - after: registration 30s later still publishes, and beats the newest frame the client took rather than the first one, because intervening title/status churn bumps the version meanwhile Also covers reconnect — `paneWasAddressable` must not latch, so a pane that dies and comes back is owed the same publication — and old-client compatibility, via the same-epoch monotonic freshness gate every mirrored client applies. A push an old client cannot accept is a push that never happened. 3 of the 4 go RED against pre-fix source; the `before` case is a guard.
…le-send-dead-0044
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Closing this. It was opened as the fix for the mobile "cannot send / spinner forever" P0, and it is not that fix. The actual P0 fix is #15463 (merged, Why this PR is being closed rather than kept as a smaller fix: I could never reach the Configurations tried, all
A correction to something I claimed earlier in this PR's discussion: I cited a So: the publication gap is real in code, and the tests here are honest (5 of 10 go RED against pre-fix source, driving the real What would justify reopening: a report of a pane stuck on a spinner with the composer still enabled — that is the |
ELI5
When you open a new agent session, the phone can be shown the tab before the terminal behind it exists. The phone asks "is it ready yet?" a bounded number of times and then stops asking. The desktop never volunteered the answer once the terminal did exist, so a pane that missed that window stayed on a spinner — and with no terminal to address, both the terminal composer and native chat had nothing to send to. This makes the desktop publish the moment the pane becomes addressable.
What Changed
touchMobileSessionTabsForMaterializedPty(pty): when a PTY becomes addressable, match its pane key against the published snapshot and re-emit only that worktree, and only when the published tab either names this ptyId or names none.onPtySpawnedandregisterPty— each guarded bypaneWasAddressableso a duplicate or repeat registration does not re-publish.touchMobileSessionTabsForWorktree, so it carries a bumpedsnapshotVersion— a re-emit at the same version is silently dropped by every client's monotonic gate.Host-side only. No wire shape changes, no new fields, no new opcodes.
Why
toMobileSessionTabsResultpublishesstatus: 'pending-handle'whenever a terminal tab has no live PTY. That is a promise to say something else later, and nothing kept it for the case where the tab is published before its PTY exists:touchMobileSessionSnapshotsForPtymatches tabs on a ptyId the snapshot does not name yet, and no other path re-emits. PTY registration is the moment that resolves it, and it published nothing.That was survivable while mobile polled indefinitely. #14916 (STA-4407) bounded the client's pending-handle recovery to
PENDING_TERMINAL_HANDLE_RECOVERY_ATTEMPTS = 5at the reconciler's 2s cadence, so a client that misses that window stops asking. Past that the pane is stranded:activeHandlestaysnull,resolveMobileTerminalInputGatereturnscanCompose: false, and there is no composer on either surface.This is why the fix is host-side. The bound shipped in mobile 0.0.44, which is in App Store review and cannot be patched. Publishing the handle when the pane becomes addressable removes the client's dependence on polling at all, and it fixes every already-installed 0.0.44 client.
What this PR does NOT claim
Linked Issue
Fixes #
Visual Proof
Reproduced live on a paired iOS Simulator running the shipped 0.0.44 client (built from
64de8dd637) against an isolated Electron host atorigin/main. A new Claude session, stranded with no composer at all:Client diagnostics at that moment:
pendingTerminalCount: 1,activeHandle: null. Host-side, the projection was asked for the handle exactly 5 times — at 1.6s, 3.4s, 5.4s, 7.4s, 9.4s — and then never again. That cadence is the client's 5-attempt budget expiring; it is not a measurement of how long a real PTY takes. Tapping Retry (retryPendingTerminalRecovery, which resets the budget) recovered instantly toactiveHandle: "1f117a01",pendingTerminalCount: 0— proving the handle was available and only the missing publication left the pane stuck.Healthy path on the same rig for contrast — mobile sends reaching the PTY (each line was typed on the phone):
Limitations, stated plainly: the rig materialized handles immediately, so the pending window was artificially induced by withholding the handle in the host. The stranding and the missing publication are real; the duration in that repro is synthetic. There is no live "after" — the rig registers PTYs through a path that bypasses
registerPty, so no genuine pending window could be constructed with the fix in place. The fix is proven at the exact seam by the tests below instead, which drive the realOrcaRuntimeServicethroughonPtySpawned/registerPty.Testing
src/main/runtime/mobile-pending-handle-materialization.test.tsdrives the realOrcaRuntimeService: publish a tab whose PTY has not registered, assert the client is toldpending-handle, then take the pane through the lifecycle with no graph sync and no renderer republication at all.Cases (10 total). The host has no timer and must not acquire one, so these pin that the publication is driven by the addressability transition, at each position relative to the client's 5-attempt ~2s budget:
Timing-relative
readyand nothing is owed. Asserts no spurious materialization push.Lifecycle
4. Reconnect —
paneWasAddressablemust not latch: a pane that dies (onPtyExit) and comes back is owed the same publication.5.
onPtySpawnedalone publishes nothing — the trigger is the registration that makes the pane addressable.6. No push for an unrelated worktree once nothing is pending.
7. No bump on duplicate registration.
8. No push when the renderer published a different PTY identity (stale ptyId).
9. No touch of an unrelated parked pending pane in another worktree —
touchMobileSessionTabsForWorktreecalled exactly once, with the right worktree.10. No retention of deleted pending worktrees in the registration path.
Old-client compatibility is asserted inside case 3 via the same-epoch monotonic freshness gate every mirrored client applies (copied as a literal — a main-process test must not import a renderer/mobile module). A client that predates the #14916 bound still gates on exactly this, so a push it cannot accept is a push that never happened.
5 of the 10 go RED against pre-fix source — cases 1(after)/2(during)/4(reconnect) plus the original repro and the parked-pane isolation case:
undefinedbecause pre-fix no event is emitted at all — which is the bug. The remaining five assert absence and pass pre-fix by construction; they are guards on the fix, not repros.Regression runs (macOS): this file plus
graph-sync-mobile-snapshot-gating.test.ts,client-session-tab-selection.test.ts, andorca-runtime.test.ts— 1228 passed, 1 skipped;tests/e2e/cross-version-wire/cross-version-terminal-wire.unit.test.ts— 5 passed;oxlint— 0 warnings, 0 errors.Platforms: exercised on macOS with a local PTY, direct (LAN) mobile transport. Not exercised on Windows/Linux, SSH, or Relay — the change sits above the PTY provider and keys only on pane key + worktree id, but it is untested there.
AI Disclosure
Claude Opus 4.5 (Claude Code) did the investigation, live repro, and tests.
Review
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
docs/reference/remote-wire-compatibility.md. Clients that still poll are unaffected; clients that stopped now get told.paneWasAddressable, so a repeat registration costs nothing and an unrelated spawn costs a failed pane-key match. The emit is coalesced, not immediate.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)oxlintand the targeted vitest suites were run locally and pass (see Testing). A fullpnpm typecheck/pnpm buildwas deliberately not run — leaving those to CI.Author