Repository navigation
fix(runtime): drain pending session-tabs notify before a new subscriber joins - #11022
Merged
Merged
Conversation
…er joins
The 50ms session-tabs notify coalescer races listener registration. A notify
armed before a subscriber existed (e.g. by seedSessionTabs -> syncWindowGraph)
fires after that subscriber registers but before the next mutation is handled,
delivering an `updated` frame carrying pre-subscribe state — state the
subscriber's initial snapshot already folded in.
Flush the coalescer at the top of onMobileSessionTabsChanged, before the
listener joins, mirroring the flushAll its own unsubscribe closure performs.
Draining rather than cancelling keeps existing subscribers whole.
This is the root cause of the intermittent CI failure in
multi-client-navigation-isolation.integration.test.ts ("routes explicit host
and paired-client follow intent without changing the default"), which taxed
unrelated PRs. Measured by sweeping the flush window across the race boundary
(12 delays x 2 reps): clean main 5/24 failed, with the fix 0/24.
The regression test is deterministic (fake timers, no wall-clock dependency)
and two-sided: it fails without the fix, and also fails if the flush is
swapped for a cancel that would drop the update for existing subscribers.
Contributor
|
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)
📝 WalkthroughWalkthroughThe runtime now flushes pending coalesced mobile session tab notifications before registering a listener. A new test verifies that a pending notification is delivered to the existing subscriber and is not replayed to a subscriber added during the coalescing window. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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 |
brennanb2025
added a commit
that referenced
this pull request
Jul 28, 2026
…ble (#10805) Closes #10793. When Orca could not verify the originating Codex session file it either threw — a red per-pane toast and a failed spawn, reported as constant spam on #10757 — or returned null. Returning null did NOT start a fresh session: the renderer had already baked ['codex','resume',<id>] into the command and pty.ts never rewrote it, so CODEX_HOME simply fell through to whichever account was selected. The resume argv is now dropped so a plain `codex` launches, with a banner telling the user. The invariant — never run `codex resume <id>` under an account that does not own that rollout — is now satisfied by construction rather than by refusing to spawn. A verified resume is unchanged and still pins CODEX_HOME to the originating home. Reviewed over two adversarial rounds; seven defects found and fixed, including a HIGH where local-provider (non-daemon) spawns still carried ORCA_SEQUENCED_STARTUP_COMMAND with `resume <id>` — the wrong account behind a banner claiming it started fresh. `env` is now declared after the strip so no point in the handler can reach the pre-strip value. Live-validated in a real Orca dev build: all five cases proven on the SPAWNED PROCESS, including a real rollout under an untrusted home (the only shape that discriminates) and the local-provider path forced by stopping the daemon. An earlier CI failure on multi-client-navigation-isolation.integration.test.ts was investigated and is a PRE-EXISTING flake — a ~4ms race in the session-tabs notify coalescer that fails 5-8/24 on clean main, more often than on this branch. Fixed separately in #11022. Not verified: no Windows execution — its POSIX-only tests skip there and the #10757 reporter is on Windows. SSH is partial: no spurious banner or drop observed against a real target, but headless spawn does not deliver startup commands so the remote argv could not be read. The relay/mobile notice channel deliberately has no banner; the argv drop does happen there, so the invariant holds.
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…ble (stablyai#10805) Closes stablyai#10793. When Orca could not verify the originating Codex session file it either threw — a red per-pane toast and a failed spawn, reported as constant spam on stablyai#10757 — or returned null. Returning null did NOT start a fresh session: the renderer had already baked ['codex','resume',<id>] into the command and pty.ts never rewrote it, so CODEX_HOME simply fell through to whichever account was selected. The resume argv is now dropped so a plain `codex` launches, with a banner telling the user. The invariant — never run `codex resume <id>` under an account that does not own that rollout — is now satisfied by construction rather than by refusing to spawn. A verified resume is unchanged and still pins CODEX_HOME to the originating home. Reviewed over two adversarial rounds; seven defects found and fixed, including a HIGH where local-provider (non-daemon) spawns still carried ORCA_SEQUENCED_STARTUP_COMMAND with `resume <id>` — the wrong account behind a banner claiming it started fresh. `env` is now declared after the strip so no point in the handler can reach the pre-strip value. Live-validated in a real Orca dev build: all five cases proven on the SPAWNED PROCESS, including a real rollout under an untrusted home (the only shape that discriminates) and the local-provider path forced by stopping the daemon. An earlier CI failure on multi-client-navigation-isolation.integration.test.ts was investigated and is a PRE-EXISTING flake — a ~4ms race in the session-tabs notify coalescer that fails 5-8/24 on clean main, more often than on this branch. Fixed separately in stablyai#11022. Not verified: no Windows execution — its POSIX-only tests skip there and the stablyai#10757 reporter is on Windows. SSH is partial: no spurious banner or drop observed against a real target, but headless spawn does not deliver startup commands so the remote argv could not be read. The relay/mobile notice channel deliberately has no banner; the argv drop does happen there, so the invariant holds.
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…ibes (stablyai#11022) multi-client-navigation-isolation.integration.test.ts fails intermittently on clean main — measured at 4-8/24 with a flush-window sweep — and has been taxing unrelated PRs across the repo. Mechanism, confirmed by instrumented trace (schedule t=23412, listener REGISTER 23460/23461, coalescer fire 23462): a ~4ms race between the 50ms session-tabs notify coalescer and listener registration in onMobileSessionTabsChanged. When the pending timer fires after the listener registers but before session.tabs.activate is handled, it emits a stale {type:'updated', activeTabId:'host-tab'} that the test consumes. flushAll() at the top of onMobileSessionTabsChanged, before the listener joins the set — mirroring the flushAll() its own unsubscribe closure already performs. DRAINING rather than cancelling is load-bearing: cancel/dispose has no emit, so it would silence the stale frame but DELETE the pending update for subscribers already registered, leaving them stale until an unrelated next schedule(). That would trade a flaky test for a real lost-update bug. The newcomer cannot miss an update by having it drained — listMobileSessionTabs and the coalesced emit read the same mobileSessionTabsByWorktree map, and snapshot-read to listener-add is macrotask-atomic. Sweep: 4-5/24 before, 0/24 after. The regression test uses fake timers and is two-sided — it fails if flushAll is removed (stale frame delivered) and fails if flush is swapped for dispose (nothing drained), on different assertions, so it pins the specific choice rather than merely the presence of a change. Reviewed independently and returned clean with both mutations re-run by the reviewer. A latent flushAll re-entrancy double-emit exists in principle — fire() does not re-check pending.has the way flush() does — but is unreachable: both production callers' listeners only invoke the dispatcher reply, a shape that has shipped since stablyai#8141 on the symmetric unsubscribe flush. Not verified: live paired-device mobile/relay behaviour (no device available); the mobile conclusion rests on a code trace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The flake
src/main/runtime/multi-client-navigation-isolation.integration.test.ts→ "routes explicit host and paired-client follow intent without changing the default" fails intermittently on CI for unrelated PRs. It is not caused by any particular PR — cleanmainfails it on its own.Mechanism
A race between the 50ms session-tabs notify coalescer and listener registration.
seedSessionTabs→syncWindowGraph(orca-runtime.ts), on the 50ms trailing-edge window inmobile-session-tabs-notify-coalescer.ts.session.tabs.subscribereads its initial snapshot, emits it, then registers a listener viaonMobileSessionTabsChanged.session.tabs.activate) is handled, it delivers a stale{ type: 'updated', activeTabId: 'host-tab' }— state the subscriber's initial snapshot had already folded in.The test consumes that frame at
multi-client-navigation-isolation.integration.test.ts:515, producing the CI assertion:Instrumented trace on a failing run, showing the ~2ms margin:
The fix
One line:
flushAll()the coalescer at the top ofonMobileSessionTabsChanged, before the listener joins the set — mirroring theflushAll()its own unsubscribe closure already performs.Draining rather than cancelling matters: a
cancel/disposewould silence the stale frame but drop the update for subscribers that were already listening.flushAlldelivers it to them and simply excludes the newcomer, whose initial snapshot already covers it.Measurement
Reproduced and verified by sweeping the coalescer flush window across the race boundary (12 delays × 2 reps, single test):
main(6943638)Both observed failure modes were the same stale frame, one step apart:
expected 'host-tab' to be 'client-a-tab'expected [ 'client-a-tab', 'host-tab' ] to deeply equal [ 'client-b-tab', 'client-b-tab' ]Full file at the real 50ms default: 5/5 pass.
Regression test
graph-sync-mobile-snapshot-gating.test.ts— deterministic, on fake timers, no wall-clock dependency. It arms a notify, advances 20ms into the window, subscribes late, then runs the clock out.It is two-sided, and I verified both directions:
expected [ {…} ] to deeply equal []— the late subscriber got the stale frame)dispose/cancel → fails onexpected +0 to be 1(an existing subscriber lost the update)Verification
src/main/runtimefull suite: 2885 passed, 5 skipped, 0 failed (181 files)tsc --noEmit× 3 (node / cli / web,--composite false, tsbuildinfo cleared first): cleanoxlint: exit 0, no warnings in either touched filecheck:max-lines-ratchet: OK, no new bypassesoxfmt: no changesScope is this race only — the coalescer and the session-tabs RPC are untouched, and the failing test was not weakened, skipped, retried, or deleted.