Repository navigation
fix(mobile): keep terminal input working when reopening worktrees - #22505
brennanb2025 merged 1 commit into
Conversation
Capture the subscription registration version before RPC dispatch yields so an older unsubscribe cannot retire a replacement on the same connection. Bind cleanup completion and retries to their registration, including when callback functions are reused. Cover the live-trace ordering across unary and streaming dispatch, binary and lease-only subscriptions, and legacy unsubscribe IDs.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR fences a delayed terminal.unsubscribe so it cannot retire a subscription registered after the request was admitted, fixing the mobile case where returning to a worktree left Live typing and Send dead until the terminal tab was tapped.
- Registry entries carry a monotonic version —
RuntimeSubscriptionRegistry.cleanupsnow stores{ cleanup, version },getRegistrationVersion()is exposed on the command surface, and ownership (registerOwned/cleanupOwned, in-flight joins) is keyed by entry identity instead of the cleanup function reference. - Version captured at admission — both
RpcDispatcher.dispatchandRpcStreamingDispatcher.dispatchsnapshotsubscriptionRegistrationVersionforterminal.unsubscribebefore any middleware/handler await, plumbed throughRpcContext. - Fence in cleanup —
cleanupIfOwnedByConnection(id, connectionId?, throughVersion?)returnsfalsewhen the current entry's version is newer thanthroughVersion; the connection check is nowconnectionId && …, preserving the unconditional-teardown path for falsyconnectionId. retryAfterpinned to its registration — no longer retries a replacement that reused the same callback.- Tests — new
runtime-subscription-registry.test.ts, plus a race regression and a malformed-params test interminal-subscribe-ownership.test.ts; the shared test double mirrors the production changes.
I verified the fence direction and admission points against both dispatchers, traced the reused-callback and retry paths through the existing mobile-creation-and-orchestration.spec.ts cases, and ran the two focused test files (27 tests passing). The regression test fails without the fix: the delayed handler would otherwise clean the replacement and report unsubscribed: true. The request format and wire contract are unchanged, so no coordinated mobile release is needed.
ℹ️ Fixed-build phone validation is still outstanding
The failure and the header-tap recovery were established from host logpoints, and the fix is covered by unit tests, but the author notes the fixed build has not yet been exercised on a phone. That is the one remaining end-to-end check for a user-facing mobile regression; nothing in the diff blocks it.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 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 (9)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe subscription registry now assigns a version to each registration and uses it to guard cleanup, ownership release, and retry behavior. Unary and streaming RPC dispatch capture the current registration version for Merge Risk: ⚪ Minimal · up to No identified issue blocks this change from merging after normal checks. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the user impact, root cause, implementation, tests, limitations, and compatibility considerations. However, the required linked issue is not provided in the expected Fixes format, and the required visual proof for this interaction change is missing. Resolution Add the issue reference using the repository's required Fixes # format. Attach before-and-after screenshots or a video showing the interaction change. Also document CI coverage or update the checklist after the required validation completes if local checks remain blocked by dependencies or plugins.
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 |
|
Thanks for checking the PR. A few clarifications on the metadata and documentation requests:
This bug was reported directly, without a GitHub issue number. #16239 is the related earlier PR, not an issue this change should close. I’ve kept the neutral
I’m following the repository’s concise, non-obvious-comments policy. The important requirement—capturing the subscription version before dispatch can yield—is already documented at the dispatch site and in
The Testing section already records the 78 passing focused tests and the local dependency blockers, and the full-validation checkboxes remain unchecked. The current |
|
Thanks @shaharmor. I reviewed and tested this, and it's good to go as-is. I didn't need to push any changes. Review
Testing: I paired an iOS simulator with a host built from this branch and ran 13 leave-and-return cycles: going back, switching worktrees, and relaunching the app. In each cycle I sent a line with Send and a line with Live typing right after returning, without tapping the terminal tab. Every line reached the desktop terminal, and no send errors appeared. The simulator's fast local connection never hit the race even with the fix reverted, so the proof of the fix itself comes from your device trace plus the tests. The simulator runs show no regressions. Send works right after going back to the worktree and returning: Send and Live typing across the final return cycles: Possible follow-ups, not blocking and not caused by this PR:
|



ELI5
Returning to a worktree on mobile could leave both Live typing and the regular Send button unusable until you tapped the terminal tab. This prevents an older terminal disconnect request from closing the subscription that just replaced it.
What Changed
The host captures the current subscription version before request processing can pause. An unsubscribe cannot remove a subscription registered after that point, even when both use the same connection. Cleanup completion and retries also stay attached to their own registration, including when a callback is reused.
Why
A live trace from mobile 0.0.51 connected to the macOS host established the actual failure:
mobile_input_floor_unavailable.Fixing ownership on the host addresses the cause rather than adding another focus workaround or delaying mobile sends. The request format is unchanged, so this does not require a coordinated mobile update.
Linked Issue
Reported directly; no issue number was supplied.
Related: #16239
Visual Proof
No screenshots or video were captured. The user reproduced the failure and header-tap recovery while temporary, non-pausing host logpoints recorded anonymous subscription metadata. The capture recorded no terminal text or credentials, and the debugger was closed afterward. This is evidence of the original failure, not a claim of fixed-build phone validation; that remains outstanding.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
The initial regression failed for both normal terminal and lease-only subscriptions before the fix.
Focused Vitest selection: 15 files passed, 78 tests passed on macOS using the cached repository dependency versions.
The regression exercises the real subscription registry across unary/streaming dispatch and both current and legacy unsubscribe IDs. Other cases cover malformed requests, missing targets, different connections, unrelated registrations, and reused cleanup callbacks.
Focused registry typecheck, formatting,
git diff --check, and the max-lines ratchet passed.Code quality, casting, focused plugins, type-aware lint, and React Doctor scans reported zero new findings.
Full node typecheck and broader runtime/mobile integration suites were blocked by the incomplete local dependency install, including Electron,
@streamparser/json, andtldts. The complete changed-code gate was blocked by the missing@shadcn/lintplugin. Full build and fixed-build phone validation were not run.Core regression command after installing dependencies:
pnpm test src/main/runtime/rpc/terminal-subscribe-ownership.test.ts src/main/runtime/runtime-subscription-registry.test.tsAI Disclosure
GPT-6 Astra through the Pi coding-agent harness assisted with diagnosis, implementation, tests, and manual diff review. The user performed the live phone reproduction.
Review
Manually reviewed request ordering, connection ownership, cleanup/retry lifetime, and old-client compatibility. The fix adds no new wire fields or client-controlled authority. Independent model review was not run.
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
The version check is host-local and constant-time. No OS-specific behavior or SSH execution routing changes; folder workspaces and git worktrees use the same path. Linux, Windows, and SSH were considered but not exercised locally. The running installed app was not patched or replaced.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)