Repository navigation
refactor(mobile): put the branch-compare leg on the lifecycle owner, with a currency probe (step 5) - #21299
Conversation
…step 5) The compare kept three hand-rolled guards for one reply, combined in an `isCurrentLoad()` the four exit points each had to remember to call: `branchCompareGenerationRef` (latest-wins), `currentBranchCompareIdentityRef` (the route identity, written in render) and `mountedRef`. The owner replaces the first two. An attempt now `reset()`s and then `load`s, so the newest attempt is the only one holding a live lease, and the reply is published only through `commit(lease, value)`. What retires a compare is named at the call site: this host, this route identity, this workspace. A compare is a refresh, so neither of the owner's other two mechanisms applies here and the `reset()` before each `load` is what says so: nothing it holds is reusable, and no attempt may share its predecessor's reply. Dropping that line makes the second attempt join the first's request and publish a base ref the user already navigated away from. The identity retire moves into the render-phase adjust-on-prop-change block, where the identity ref was written. Leaving it to the next load's scope is not the same thing: that load only starts once the fresh `git.status` returns, and an in-flight compare would publish the old worktree's commits first. `mountedRef` stays. A detached route has no screen to publish to, which is a fact about the view, not about which reply is current. The three decision points that used to write state mid-flight — no base ref, a refused capability, an unreadable reply — are a returned `BranchCompareOutcome` now, so the loader body writes nothing and the screen is written in one place. That also puts this file under the loader-write source fence. No golden moves: the recording suites reproduce byte for byte. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…reads it The pilot's wording named two scope consumers; the compare leg has only `load`. What the scope still adds over the render-phase retire is the structural half: a scope the owner has not seen retires on its own. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
A loader that spans two round trips had no way to ask whether its scope had moved, so a superseded attempt sent its second request and was only refused at commit. The probe answers exactly the question commit asks and carries nothing to publish with, so the owner's publish fence is unchanged: a loader that stops on it returns null, which the owner already reads as no value. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Restores request-count parity with main for the one path the migration changed: an attempt superseded while it resolved its base ref used to stop before sending git.branchCompare, and under the owner it sent one and was refused at commit. It now stops on the owner's currency probe between the two legs, so the screen is unchanged and so is the request count. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe change adds a read-only Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to A concurrent route update can leave source-control status or branch comparison stale or stuck because an abandoned render cancels the committed route's load. This should be fixed before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives detailed migration rationale, implementation details, testing evidence, and review notes. However, it does not follow the repository template completely: it omits explicit ELI5, Linked Issue, Visual Proof, AI Disclosure, Agent skill upstream boundary, Notes, and Checklist sections. It also does not clearly state whether UI proof is not applicable. Resolution Add the missing template sections. Include the linked issue explicitly, state
✨ 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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: bc9a3f62-1140-4db4-992e-0ebe69d967b9
📒 Files selected for processing (5)
mobile/src/source-control/use-mobile-source-control-loaders.test.tsmobile/src/source-control/use-mobile-source-control-loaders.tsmobile/src/transport/generation-scoped-lease-compile-fence.tsmobile/src/transport/generation-scoped-request-owner.tsmobile/src/transport/lifecycle-owner.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
| lastResetIdentityRef.current = statusIdentityKey | ||
| // Retire here rather than leaving it to the next load's scope: that load only starts once the | ||
| // fresh status returns, and an in-flight compare would publish the old worktree's commits first. | ||
| branchCompare.reset() |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,245p' mobile/src/source-control/use-mobile-source-control-loaders.ts
sed -n '1,230p' mobile/src/transport/generation-scoped-request-owner.ts
rg -n -C 3 'loadBranchCompare|statusIdentityKey|branchCompareState|setRootRef' mobile/src/source-control/use-mobile-source-control-loaders.tsRepository: stablyai/orca
Length of output: 23460
🏁 Script executed:
sed -n '230,350p' mobile/src/source-control/use-mobile-source-control-loaders.ts
rg -n -C 6 'useMobileSourceControlLoaders|loadStatus\(' mobile/src --glob '*.ts' --glob '*.tsx'Repository: stablyai/orca
Length of output: 28664
🏁 Script executed:
rg -n -C 8 'useMobileSourceControlLoaders|loadStatus\(' mobile/srcRepository: stablyai/orca
Length of output: 30988
Move the identity-change reset out of render.
branchCompare is a persistent GenerationScopedRequestOwner. An abandoned render can call reset(), increment its generation, and clear the in-flight request for the still-committed identity. When that request resolves, commit() refuses its lease. The abandoned render starts no replacement useEffect load, so the screen can retain stale compare data or remain loading.
Move the identity-change reset block to a useLayoutEffect keyed by statusIdentityKey. The reset will occur only after the new identity commits and before the existing passive loadStatus effect starts, while preserving stale-result protection.
Stripping the directive gives TS2339, a member that does not exist, not a privacy error: the probe has no generation to keep private. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The detach reset() was the only thing retiring an attempt after the route went away, and deleting it left the suite green. This schedule detaches mid base-ref lookup and asserts nothing reaches git.branchCompare; without the reset() it fails with one request sent. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
statusIdentityKey is `${hostId}\0${worktreeId}`, so listing worktreeId
beside it read as a third fence when it fences nothing new.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The outcome union, the attempt and the screen mapping are the compare leg's own protocol, not the hook's: nothing in them reaches React. Moved verbatim to mobile-branch-compare-outcome.ts with a unit pin for the mapping, which only the hook's schedules covered before. The hook drops from 283 to 230 lines against a 300 limit. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Branch-compare leg moved onto the lifecycle owner —
use-mobile-source-control-loaders.tsnow loads throughGenerationScopedRequestOwner; the hand-rolledbranchCompareGenerationRef/currentBranchCompareIdentityRef/isCurrentLoad()closure is deleted. - One write point for the screen —
readBranchCompareOutcomereturns a totalBranchCompareOutcome | null(null = superseded) andnextBranchCompareStateprojects it, so the loader body writes nothing and publication is single-sited pastbranchCompare.commit. - Owner gains a read-only currency probe —
load'sfnreceivesRequestCurrency, built once per physical request from the lease's own state; the compile fence pins that the probe cannot publish and its generation is unreadable. - New coverage — hook schedules for newest-wins, supersede-mid-base-ref request parity, and identity-move refusal, plus three probe schedules in
lifecycle-owner.test.ts. Theracemutant anchor inoperation-mutations.ts:23still matches the unchangedcommitblock. - Verification this run — both changed test files pass (17 tests); the recording mutant suites pass (84 passed, 3 skipped,
b1: kills racegreen).
ℹ️ The render-phase retire also fires on an identity round trip, where main published
No action requested — this is a deliberate consequence of the owner's A→B→A retire, and it self-heals. It only means the PR's "wire identical" claim is not exact in this one window: on a reused route that goes A→B→A while A's base-ref round trip is still out, main left branchCompareGenerationRef untouched and rewrote the identity ref back to A, so A's in-flight compare published; the new render-phase reset() retires it, sending one fewer git.branchCompare and leaving the compare list idle until the fresh A status load resolves. That load always runs (the identity-change effect re-fires), so the end state is the same.
Technical details
# Identity round trip A → B → A retires an in-flight compare that main published
## Affected sites
- `mobile/src/source-control/use-mobile-source-control-loaders.ts:152` — render-phase `branchCompare.reset()` bumps the owner generation on every identity change.
- `mobile/src/source-control/use-mobile-source-control-loaders.ts:65` — the probe stops the attempt once that generation moved.
- `mobile/src/transport/generation-scoped-request-owner.ts:129-132` — `reset()` bumps even when the scope returns to where it started, by design.
## Why the divergence exists
`loadBranchCompare` only runs from `loadStatus`'s success path, and B's status load is skipped by `isCurrentLoad()` once the route is back on A, so no attempt ever enters B's scope. Main's `isCurrentLoad()` for A's attempt still matched (`branchCompareGenerationRef` was never bumped by a render; `currentBranchCompareIdentityRef` was rewritten to A unconditionally), so it published. The owner cannot match that: the render-phase reset retired it and `commit`/the probe answer the same generation question.
## Required outcome
None — the retire is intentional and the fresh A load always runs, so the compare list refills. Surfaced only so the "wire identical" wording can be read precisely.
## Open questions for the human (optional)
- If exact wire parity in this window matters, a one-line note in the PR description would cover it; otherwise no code change is needed.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior pullfrog review at 43583f95b9)
- Compare protocol split into its own React-free module —
mobile-branch-compare-outcome.tsnow holdsBranchCompareOutcome,readBranchCompareOutcomeandnextBranchCompareState; the hook imports them and no longer importsrefusedRpcMessageOrFallback,gitBranchCompareRead,resolveMobileBranchCompareBaseRefor the reply type directly. Imports are clean (no duplicates, no unused). - Owner scope reduced to
[client, statusIdentityKey]— safe: the only production caller buildsstatusIdentityKey = ${hostId}\0${worktreeId}(use-mobile-source-control-state.ts:79), so the workspace is still in the key, and the hook already treats that key as the identity for its render-phase reset and status guard. - New detach schedule —
use-mobile-source-control-loaders.test.tsnow pins that an attempt the route detached under sends no compare, which is exactly what the detachreset()(not the mount latch) provides; without it the probe would stay current and the compare would go out. - New pure-mapping tests —
mobile-branch-compare-outcome.test.tscovers ready-over-any-prior, preserve-ready only when asked, and unavailable-vs-failed. - Fence comment corrected — the probe exposes no generation at all, and the compile fence's
@ts-expect-errornow says so. - PR description updated — the A→B→A flap from the prior review is now disclosed under "One schedule differs, disclosed", and the loader-write fence's scope limitation is stated. No further action needed on either.
Verification this run — vitest run on the changed test files at b4eb13c3ac (21 passed); the recording mutant suites (84 passed, 3 skipped, b1: kills race green); oxlint on the changed files (0 warnings, 0 errors).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ender A joiner never receives the probe: its fn is never invoked, it awaits the originating request's promise, and retire() clears inFlight so none can join across a generation bump. The compare attempt takes the operation sender the convention names rather than a whole RpcClient, which it only ever used as that. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…with a currency probe (step 5) (stablyai#21299) * refactor(mobile): put the branch-compare leg on the lifecycle owner (step 5) The compare kept three hand-rolled guards for one reply, combined in an `isCurrentLoad()` the four exit points each had to remember to call: `branchCompareGenerationRef` (latest-wins), `currentBranchCompareIdentityRef` (the route identity, written in render) and `mountedRef`. The owner replaces the first two. An attempt now `reset()`s and then `load`s, so the newest attempt is the only one holding a live lease, and the reply is published only through `commit(lease, value)`. What retires a compare is named at the call site: this host, this route identity, this workspace. A compare is a refresh, so neither of the owner's other two mechanisms applies here and the `reset()` before each `load` is what says so: nothing it holds is reusable, and no attempt may share its predecessor's reply. Dropping that line makes the second attempt join the first's request and publish a base ref the user already navigated away from. The identity retire moves into the render-phase adjust-on-prop-change block, where the identity ref was written. Leaving it to the next load's scope is not the same thing: that load only starts once the fresh `git.status` returns, and an in-flight compare would publish the old worktree's commits first. `mountedRef` stays. A detached route has no screen to publish to, which is a fact about the view, not about which reply is current. The three decision points that used to write state mid-flight — no base ref, a refused capability, an unreadable reply — are a returned `BranchCompareOutcome` now, so the loader body writes nothing and the screen is written in one place. That also puts this file under the loader-write source fence. No golden moves: the recording suites reproduce byte for byte. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * docs(mobile): correct the compare scope comment to the one call that reads it The pilot's wording named two scope consumers; the compare leg has only `load`. What the scope still adds over the render-phase retire is the structural half: a scope the owner has not seen retires on its own. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * feat(mobile): give the lifecycle owner's loader a currency probe A loader that spans two round trips had no way to ask whether its scope had moved, so a superseded attempt sent its second request and was only refused at commit. The probe answers exactly the question commit asks and carries nothing to publish with, so the owner's publish fence is unchanged: a loader that stops on it returns null, which the owner already reads as no value. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * fix(mobile): keep a superseded branch compare off the wire Restores request-count parity with main for the one path the migration changed: an attempt superseded while it resolved its base ref used to stop before sending git.branchCompare, and under the owner it sent one and was refused at commit. It now stops on the owner's currency probe between the two legs, so the screen is unchanged and so is the request count. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * docs(mobile): say what the probe's missing generation actually is Stripping the directive gives TS2339, a member that does not exist, not a privacy error: the probe has no generation to keep private. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(mobile): pin that a detached route sends no compare The detach reset() was the only thing retiring an attempt after the route went away, and deleting it left the suite green. This schedule detaches mid base-ref lookup and asserts nothing reaches git.branchCompare; without the reset() it fails with one request sent. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * refactor(mobile): drop the scope member the identity key already carries statusIdentityKey is `${hostId}\0${worktreeId}`, so listing worktreeId beside it read as a third fence when it fences nothing new. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * refactor(mobile): split the compare protocol out of the loaders hook The outcome union, the attempt and the screen mapping are the compare leg's own protocol, not the hook's: nothing in them reaches React. Moved verbatim to mobile-branch-compare-outcome.ts with a unit pin for the mapping, which only the hook's schedules covered before. The hook drops from 283 to 230 lines against a 300 limit. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * refactor(mobile): correct the joiner comment and narrow the compare sender A joiner never receives the probe: its fn is never invoked, it awaits the originating request's promise, and retire() clears inFlight so none can join across a generation bump. The compare attempt takes the operation sender the convention names rather than a whole RpcClient, which it only ever used as that. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

What this is
Step 5 of the mobile RPC contract foundation on its next site after the pilot (#20914): the source-control branch-compare leg moves off hand-rolled generation refs onto
GenerationScopedRequestOwner. Pure refactor: no wire change, zero goldens moved.The other site the plan named, the terminal list, is reported rather than forced:
MobileTerminalInventoryRequestshares one execute run across joiners, upgrades an in-flightallowEmptyLoadedflag, and exposes the joiner'sstartedAtfor the certified-sweep cadence; the owner has no expression for any of the three, and its loader-write fence rejects the body's ref writes. That matches the pilot's own next-sites note. Making it fit means widening the owner with joiner-visible request state, which is a design ticket, not this PR.The migration
isCurrentLoad()was a closure over three refs (branchCompareGenerationRef,currentBranchCompareIdentityRef,mountedRef) that each of four exit points had to remember to call. The first two are deleted. An attempt now callsreset()and thenload(), so only the newest holds a live lease and a reply publishes only throughcommit. The three mid-flight decision points that used to write state (no base ref, refused capability, unreadable reply) are a returnedBranchCompareOutcome, so the loader body writes nothing and the screen is written in one place. (The pilot's loader-write source fence does include this hook and parses the inline arrow passed toload; it finds nothing because the body delegates one level toreadBranchCompareOutcome, so the no-write property of that function is held by construction and by the tests, not by the fence.)mountedRefstays: a detached route has no screen to publish to, which is a fact about the view, not about which reply is current.Two design points:
reset()before every load is what keeps the wire identical (a compare is a refresh, so neither the cache nor in-flight coalescing applies; without it a second attempt would join the first's request and publish a base ref the user had left). And the identity retire sits in the render-phase adjust-on-prop-change block rather than relying on the scope, because the next load starts only after the freshgit.statusreturns, leaving a window where an in-flight compare could publish the old worktree's commits.One schedule differs, disclosed
Round 1 built the before/after table for eight schedules: normal load, refresh while in flight, identity change while in flight, unmount while in flight, superseded between base-ref resolution and the compare send, refused capability, unreadable reply, no base ref. Same requests and same published state on all of them, five pinned byte-for-byte by unmoved goldens. The one exception is an A-to-B-to-A identity flap while a base-ref lookup is out: main wrote its identity ref back to A, so the stale attempt's currency check went true again and it sent its compare; the render-phase
reset()is monotonic, so this branch drops that attempt and the second A attempt starts its own load. One fewer request on that flap, no stuck state, and no golden drives it.The owner grew a currency probe
Main checked currency between resolving the base ref and sending the compare. A loader inside the owner had no way to ask, so the first cut sent one extra
git.branchComparefor a superseded attempt, which is a wire change. Fixed at the owner boundary:load'sfnnow receivesRequestCurrency = { readonly isCurrent: () => boolean }, one probe per physical request built from the lease's own state (joiners share it as they share the reply), answering the same comparisoncommitmakes. No generation number and no lease brand are exposed, and the compile fence pins that a probe cannot be passed tocommitand that its generation is unreadable. The loader checks it after the base-ref round trip and before the compare, exactly where main checked, and returns null (whichloadalready reads as no value). A superseded attempt now sends nothing.Tests
lifecycle-owner.test.ts: three probe schedules (flips under a reset mid-flight; flips when a load enters an unseen scope; a loader that stops on it publishes nothing while the live attempt commits).use-mobile-source-control-loaders.test.ts(new; the hook had none): two schedules for what the migration rests on, plus request-count parity for the superseded-mid-base-ref case: zerogit.branchComparefor the superseded attempt, exactly one for the live one.isCurrent()fails the four probe cases and, since the detach schedule landed, the fifth (lead reproduced the four before that schedule existed).Gates (on
43583f95b9)Mobile
tsc0 · full mobilevitest run632 files, 6227 passed, 6 skipped · recording suites with mutants 22 files, 965 passed, 3 skipped · zero goldens moved ·oxfmt --checkandoxlintclean on the five changed files ·check-changed-code-quality0 findings in every category. The race mutant'sbeforetext still matches the commit block once; no re-anchor.Review
Round 1 (adversarial, before/after table rebuilt from main's
isCurrentLoad()code): ship as-is. Probe confirmed read-only (closure returning a boolean, no publish path, no generation reachable; both compile-fence directives fire for the stated reason). Thereset()-before-load claim holds (deleting it fails both overlap cases; the compare never read the cache on main). Render-phase reset: round 2 corrected round 1's premise here. expo-router wraps every screen inReact.Suspenseand callsReact.startTransition, so a discarded render can advance the identity guard while dropping bothsetStatecalls and leave the old worktree'sreadycompare on screen. Main has the identical exposure through its identical render-phase identity-ref write, so this is not a regression and not a blocker; it is a pre-existing hazard worth its own ticket. Four low items folded: a compile-fence comment that claimed the probe carries a generation; the detachreset()was correct but unpinned (now a schedule);worktreeIddropped from the scope becausestatusIdentityKeyalready embeds it; the compare protocol split out of the loaders hook into its own module.Round 2 (fresh reviewer): ship as-is. Rebuilt the before/after table from main's
isCurrentLoad()independently; identical on every schedule except the disclosed flap, and named two equivalences (the early-return guard narrowing tomountedRefis safe because the only caller sits behindisCurrentLoad()with no intervening await; the empty-refusal message parity is pinned bymatrix-git.changes-load-git.branchcompare-1). All five mutations confirmed by reading; both compile-fence directives fire for their stated reason; the split is byte-identical bodies. Two low items folded: the "joiners share it" wording (joiners never see a probe; they await the same promise), and the split module's parameter narrowed fromRpcClientto the sender type perrpc-operation-sender.ts.