Repository navigation
fix(mobile): a same-build cache hit persists the fresh manifest (OTA phase D1) - #22139
Conversation
A route-grant edit on the desktop moves no asset, so the bundle is published under the build id it already had: the cached generation holds the right bytes under a manifest an edit behind, and that stored manifest is the whole of an unreachable host's verdict. The store gains one operation for it. Refused unless the manifest names exactly the bytes on disk — same build id, and the same asset list read through the contract's own serializer, which is the string the id is a digest of. Written beside and renamed over, so a write that fails leaves the manifest the assets were downloaded with. A refusal is a return value, never a throw: it costs freshness, never the generation. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The same-build hit in `onManifestRead` opens the cached generation and now also asks the store to rewrite the manifest beside it, and the generation the session holds carries the fresh routes from that point. Without it every offline verdict lagged a grant edit: `onCacheRead` reads the stored routes, and nothing on this path wrote them. The manifest travels whole on `manifest-read`, because the store compares its asset list and a projection rebuilt from the fields a transition reads would name other bytes. The fallback fixture that read a newer manifest under the cached build id now uses a build of its own, which is what makes the download it is about happen at all. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…ute verdict (round 1) A verdict about this route is not a verdict about the manifest. A fresh list that takes this screen native, or that names a bundle this shell cannot open, still grants or revokes the other routes the same assets serve — and what is stored beside those assets is the whole of the next offline verdict. Both returns left it unwritten, so an offline entry kept grants the desktop had already taken away. The same-build read is now taken before the route verdict: the native and wall returns carry the fresh routes on the generation they hold and emit the persist, exactly as the open does. The different-build arms are untouched, wall included, which still fetches nothing. `readMobileWebShellReachability` moves to `mobile-web-shell-reachability.ts`, the module its test was already named for: the reducer was one line under the 300-line cap and this fold needed the room. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
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 (10)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe change adds validated manifest replacement and recovery for active cached generations. It validates build IDs against serialized assets, preserves pending swaps after failures, and settles them during reads. Mobile web shell sessions preserve the fetched wire manifest, update matching cached routes, and emit a persistence effect. The session hook executes that effect and ignores write failures. Reachability logic moves to a separate module. Tests cover persistence failures, recovery, session behavior, offline routing, and manifest integrity. Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to The cache replacement can remove the active manifest when a move fails, making cached routes unavailable offline. This material availability risk should be fixed or explicitly accepted before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 3d17e074-f455-45c6-a9e5-80bcd31d4843
📒 Files selected for processing (15)
mobile/src/mobile-web-shell/generation-store-file-system.tsmobile/src/mobile-web-shell/generation-store.test.tsmobile/src/mobile-web-shell/generation-store.tsmobile/src/mobile-web-shell/manifest-persist-refusal.tsmobile/src/mobile-web-shell/mobile-web-shell-reachability.test.tsmobile/src/mobile-web-shell/mobile-web-shell-reachability.tsmobile/src/mobile-web-shell/mobile-web-shell-session-contract.tsmobile/src/mobile-web-shell/mobile-web-shell-session-effects.tsmobile/src/mobile-web-shell/mobile-web-shell-session-grants.test.tsmobile/src/mobile-web-shell/mobile-web-shell-session-manifest-persist.test.tsmobile/src/mobile-web-shell/mobile-web-shell-session-test-fixtures.tsmobile/src/mobile-web-shell/mobile-web-shell-session.test.tsmobile/src/mobile-web-shell/mobile-web-shell-session.tsmobile/src/mobile-web-shell/use-mobile-web-shell-session.test.tsmobile/src/mobile-web-shell/use-mobile-web-shell-session.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one durability claim to reconcile, plus a minor suggestion.
Reviewed changes
- Manifest write-through —
GenerationStore.persistActiveManifestrewrites onlymanifest.jsonbeside a host's active generation, refusing unless the build id and the asset list both match the stored generation (refuseManifestPersist, compared throughserializeMobileWebBundleAssets). Refusals are return values; the write goes to<host>/tmp/manifest-next.jsonand is moved over the live file. - Reducer —
onManifestReadnow emitspersist-manifeston every same-build read and carries the fresh routes ontosession.cached, whatever the route verdict (open-generation, native-route, wall). Different-build arms still neither persist nor open the cache. File.moveadapter — newmoveFileon the file-system port; deletes the destination first because expo-file-system 55'sFile.moverefuses an existing destination.- Module splits —
manifest-persist-refusal.tsandmobile-web-shell-reachability.tskeep the store and reducer under the line cap. - Tests — new store and session persist suites; fixtures refactored onto
MANIFEST_WIRE/manifestFacts, and the grants download-failure case moved to its own build id so it actually downloads.
The same-build gate and the asset-list refusal are the right checks for this feature, and the offline verdict now tracks a grant edit that moves no asset.
ℹ️ Nitpicks
persistManifestrewritesmanifest.jsonon every same-build mount even when the routes are unchanged, and each write is the delete-then-move below, so an unnecessary write still carries the crash window.readActivealready returns the parsed manifest, so comparingactive.manifest.routesto the fresh routes before writing could skip the no-op case — the PR note that this would need the stored text out ofreadActivemay not hold.
Technical details
# A failed `moveFile` can leave no manifest, not the old one
## Affected sites
- `mobile/src/mobile-web-shell/generation-store.ts:274` — comment promises the old manifest survives a write that "fails or tears"
- `mobile/src/mobile-web-shell/generation-store-file-system.ts:112` — the adapter deletes the destination, then renames
- `mobile/src/mobile-web-shell/generation-store.test.ts:746` — asserts the old manifest is still present, because the fake at `generation-store.test.ts:129` throws before deleting
## Required outcome
- The comment, the fake, and the assertion state the real contract: a failed move leaves the old manifest or none, and none reads back as "no activation" (a redownload). Alternatively the adapter keeps the old manifest on failure, which expo 55 does not support.
## Suggested approach (optional)
- Have the fake delete the destination before throwing, then change `expect(fs.text(MANIFEST_PATH)).toBe(stored)` to expect the absent/redownload outcome, matching the PR body's own note that a crash in the window "leaves no manifest, which reads back as 'no activation'".DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
`moveFile` deletes the destination before it moves, because expo offers no atomic replace, so a failure after that delete left a generation with no manifest at all — which reads back as "no activation" and drops the host's cache. A phone whose host is unreachable loses its whole workspace to one interrupted rename. The store's fake threw before that delete, so the suite never exercised the ordering the adapter really has. The write is now three steps inside the generation directory: the fresh manifest to `manifest-next.json`, the old one away, the fresh one over it. The old manifest is never deleted before the whole of the fresh one is on disk, and `readActive` settles every window it leaves — both files present finishes the swap, a pending manifest alone is adopted, and one that is torn or names another build is discarded with the old one kept. A pending file that cannot be settled deletes nothing, because it may be the only manifest left and the next read can still adopt it. The asset-path guard refuses the pending name too, or an asset could be read back as an activation. `joinUri` moves to a module that imports nothing: taking it from the file-system module pulled `expo-file-system` into everything that addresses the cache, which is the import the store's testability rests on not having. The refusal rule now names where the id-to-assets refine actually lives. It is on the host's strict schema, not on the loose reader the phone parses with, so the store's asset comparison is the phone's own check rather than a restatement of one already made. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Round 1 wrote every same-build manifest through, the walled ones included. That is the one read where the fresh manifest must not reach disk: an offline entry skips the compat check, so a stored manifest this shell has just declared it cannot read would have the next offline entry open a page under the grants of that bundle. What is on disk stays the last manifest this shell accepted, and the held generation keeps its routes with it, so the session's record still matches what was written. The native-route arm keeps the write: a route this build cannot serve is not a bundle it cannot read, and the fresh list still governs the other routes those same assets serve. Its round-1 test is now a control that pins the wall persisting nothing. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…sset digest (round 3) The id is a cache key and a claim about content at once, and only the host checked the two against each other. The phone read the same document loosely and never recomputed the digest, so a stale or forged id reached the shell — which treats an id it already holds as the same bytes and opens the generation on disk without paging one. The reader now carries the host's refine, so a manifest that reaches the reducer under the cached build id names the same serialized asset list by construction. The two checks in that reader are one `superRefine` with the cheapest first and the first issue returning: the digest is the only one that hashes, and a manifest already over the allocation ceiling must not be hashed to be refused. The store's comparison stays, as the second reading of one rule rather than a rule of its own: its argument is a plain object, and nothing in the type says which parse it came from. The fixtures that published a literal id now derive it from the assets they name, which is what the host does. The one test that needs a single id over two asset lists still names it, because that collision is what it is about. Every one of the 13 manifests in the golden corpus was already digest-correct; the replay suites pass unchanged. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
Rounds 2 and 3 pushed (4f797d1, f8b13ba, f6bf2b0): the manifest swap is crash-safe with the old manifest retained until the next one is fully written and readActive settling every window; a walled manifest is no longer persisted; and the phone's reader now refines buildId against the asset digest, so the reducer's same-build open names the same asset list by construction. Details and reds in the body. |

Phase D1: a same-build cache hit persists the fresh manifest
Why
A route-grant edit on the desktop is asset-invariant, so the bundle's
buildIddoes not change (that identity is pinned bymanifest-contract.test.tsand stays). Online was already right:onManifestReadderives routes and grants from the fresh manifest. But nothing rewrote the manifest stored beside the cached assets, so the offline branch ofonCacheRead, which readsgeneration.routes, kept the old routes and grants until the assets changed. Offline verdicts lagged behind a grant edit. Deferred from C1.8 (finding 7 on #21503, 2026-09-19) to this phase.What
GenerationStore.persistActiveManifest(hostKey, manifest)rewrites onlymanifest.jsonbeside a host's active generation. It refuses unless the build id matches and the asset list is identical, compared throughserializeMobileWebBundleAssets, the exact string the build id digests. Refusals are return values (persisted/refused-no-active-generation/refused-build-mismatch/refused-asset-mismatch), never throws. The write goes to<host>/tmp/manifest-next.jsonand is moved over the live file through a newmoveFileon the file-system port; a failed move leaves the old manifest readable.persist-manifeston every same-build manifest read, whatever the route verdict: besideopen-generation, on the native-route return, and on the wall return. The generation it holds carries the fresh routes from that point. Different-build arms are unchanged: no persist, and a wall still fetches nothing.manifest-readaswire, because a projection rebuilt from the facts would name other bytes.manifest-persist-refusal.tsandreadMobileWebShellReachabilitymoved tomobile-web-shell-reachability.ts, the module its test was already named for: both because the store and the reducer sit a few lines under the 300-line cap.Commits
661765ebd1persistActiveManifest,moveFileon the port, refusal rulestore.persistActiveManifest is not a function0e83fca1dfpersist-manifest, holds the fresh routes; runner calls the storeexpected [ { kind: 'open-generation', …(3) } ] to deeply equal [ …(2) ]; fresh routes:expected [ { pathname: '/h/[hostId]', …(1) } ] to deeply equal […]; offline opens the route only the fresh grants allow:expected [] to deeply equal [ { schemaVersion: 1, …(7) } ]68699565fdexpected [] to deeply equal [ { kind: 'persist-manifest', …(1) } ]on both arms; the two different-build controls pass both waysb484bf4be7origin/main(9243073b73), no overlap4f797d1a55manifest-next.jsoninside the generation directory, then the old one away, then the fresh one over it;readActivesettles every window (both present → finish; only next → adopt; torn or another build → discard, keep old); the fakemoveFilemirrors the adapter (destination deleted first) with failure injected after it; the asset-path guard refuses the pending namekeeps the host tree when the pending swap cannot be settled either: expected null not to be null(the cache loss),adopts the fresh manifest on the next read when the rename is interrupted: expected undefined to deeply equal [ { pathname: '/h/[hostId]', …(1) } ]f8b13ba189persists nothing of a manifest it walls: expected [ { kind: 'persist-manifest', …(1) } ] to deeply equal []f6bf2b0a57buildId === computeMobileWebBundleId(assets)in onesuperRefine, cheapest check first, so a manifest reaching the reducer under the cached build id names the same asset list by construction; the store's comparison stays as the second reading of one rule; fixtures derive their ids from their assetsrefuses a manifest whose build id is not the digest of the assets it names: expected true to be falseAlso fixed on the way:
mobile-web-shell-session-grants.test.tsread a "newer manifest" under the cached build id, so its download-failure case was driving a same-build hit where no download ever starts. It now uses a build of its own.Review rounds
CodeRabbit and pullfrog on
b484bf4be7: (1) the swap deleted the live manifest before the move, so a failure after that delete lost the cache — real, round 2; (2) a walled manifest made eligible for unchecked offline activation — real the other way, round 2 retains the previous manifest on a wall; (3) the reducer trusted a build id the phone never verified — real, round 3 adds the digest refine to the phone's reader (the host already had it). The digest costs 0.05–0.3 ms per manifest read at 8–256 assets, once per route entry. Goldens carry 13 manifests, all digest-correct; the replay passes untouched (23 suites, 1,752 passed).Not done here, on purpose
readActive.Verification
Lane on
b484bf4be7: closure census alone 5 passed (4,360 exactly; the two new modules are shell-side and not in the page bundle); full mobile suite 809 files, 9,010 passed; fullconfig/scriptssuite 251 files, 2,325 passed; mobile tsc, ratchet, oxlint (15 files, mobile and root), oxfmt, anti-slop, changed-code quality (0 new findings), React Doctor all 0. No/Users/ororca-lanes, nomax-linesdisable or bump.Lead gate on
b484bf4be7against9243073b73: tsc 0, ratchet 0, all lint gates 0 (15 changed files), changed-code quality passed, React Doctor 0;config/scripts251 files passed; mobile 809 files passed; no machine paths.Lead gate on
f6bf2b0a57against9243073b73: tsc 0, ratchet 0, all lint gates 0 (20 changed files), changed-code quality passed, React Doctor 0;config/scripts251 files passed; mobile 809 files passed; no machine paths.