Repository navigation
fix(runtime): keep a superseded lease-only subscribe from releasing live mobile presence - #14993
brennanb2025 wants to merge 1 commit into
Conversation
…ive mobile presence The lease-only terminal.subscribe branch releases mobile presence when its awaited handleMobileSubscribe resumes to find the stream closed. But `closed` is exactly the post-rebind state, presence is keyed by (ptyId, clientId) with no refcount, and both generations share that key — so a superseded handler deleted the replacement subscriber's presence instead of its own. Gate the release on the registration still owning the subscription. Distinct from the STA-4510 freeze this stacks on: output keeps flowing, but the live subscriber loses phone-fit and remote-view presence.
5dcc791 to
d9d1910
Compare
|
Consolidating this into #14992 rather than shipping it stacked. Code review on #14992 found that it introduced The one-line guard and its regression test now live in #14992 ( Review verdict on this change was approve, no findings. It also corrected something in this PR's description: the documented "known limitation" about a late Closing as consolidated, not abandoned. |
ELI5
A phone that reconnects gets a fresh terminal subscription, but the old one may still be mid-
await. When that old handler wakes up and sees "my stream is closed", it releases the phone's presence — except presence is filed under(pty, phone), which the new subscription now uses too. So the dead handler deletes the live one's presence on its way out.What Changed
One guard: the lease-only branch releases mobile presence only if its registration still owns the subscription.
Why
handleMobileUnsubscribeis a keyedinner.delete(clientId)with no refcount (orca-runtime.ts:16108-16119), and both generations share an identical(ptyId, clientId). The resume-after-await atterminal.ts:2977fires whenclosed || signal?.aborted— andclosed === trueis exactly the post-rebind state, because the rebind runs the old generation's cleanup synchronously insideregisterSubscriptionCleanup. So the superseded handler reliably deletes the live subscriber's presence.Distinct from the freeze in the parent PR: output keeps flowing. What is lost is phone-fit and remote-view presence, so the terminal stops auto-fitting to the phone's viewport. Same defect family — a stale generation acting on a shared key — which is why it uses the same ownership handle.
Linked Issue
Refs #14843 (found while investigating; not the reported freeze)
Fixes #
Visual Proof
N/A— no rendered surface changes in this diff. The observable effect is that a reconnected phone keeps its server-side auto-fit ownership.Testing
terminal-subscribe-lease-presence.test.tsdrives a lease-only subscribe, leaveshandleMobileSubscribepending, rebinds the id on a second connection, then resolves the first.Because both generations share
(ptyId, clientId), arguments alone cannot distinguish the rebind's own legitimate release from a stale one — so the test snapshots the call count immediately after the rebind and asserts it does not increase.Mutation-verified: removing the
isCurrent()guard turns it red (expected 2 to be 1).Targeted suites: 22 files / 99 tests pass.
pnpm tcexit 0;oxfmt+oxlintclean.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
registerOwnedSubscriptionCleanup.handleMobileSubscribecan resolve late and write into the same presence entry (orca-runtime.ts:16069-16077), clobbering the live generation's viewport baseline. It cannot delete presence, so it cannot cause a freeze — value corruption only. Named here so it is not rediscovered as a missed case.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author