Skip to content

fix(mobile): a same-build cache hit persists the fresh manifest (OTA phase D1) - #22139

Merged
Jinwoo-H merged 7 commits into
mainfrom
ota-d1-manifest-persist
Sep 22, 2026
Merged

Jinwoo-H merged 7 commits into
mainfrom
ota-d1-manifest-persist

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​579 $\color{#cf222e}{\Huge{\mathbf{−}}}$​79 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​500
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​356 $\color{#cf222e}{\Huge{\mathbf{−}}}$​69 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​287

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 buildId does not change (that identity is pinned by manifest-contract.test.ts and stays). Online was already right: onManifestRead derives routes and grants from the fresh manifest. But nothing rewrote the manifest stored beside the cached assets, so the offline branch of onCacheRead, which reads generation.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 only manifest.json beside a host's active generation. It refuses unless the build id matches and the asset list is identical, compared through serializeMobileWebBundleAssets, 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.json and is moved over the live file through a new moveFile on the file-system port; a failed move leaves the old manifest readable.
  • The session reducer emits persist-manifest on every same-build manifest read, whatever the route verdict: beside open-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.
  • The manifest travels whole on manifest-read as wire, because a projection rebuilt from the facts would name other bytes.
  • The refusal rule lives in manifest-persist-refusal.ts and readMobileWebShellReachability moved to mobile-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

sha change red before
661765ebd1 store: persistActiveManifest, moveFile on the port, refusal rule five store tests: store.persistActiveManifest is not a function
0e83fca1df reducer: same-build hit emits persist-manifest, holds the fresh routes; runner calls the store expected [ { 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) } ]
68699565fd round 1: native-route and wall same-build reads persist too; reachability extracted expected [] to deeply equal [ { kind: 'persist-manifest', …(1) } ] on both arms; the two different-build controls pass both ways
b484bf4be7 merge of origin/main (9243073b73), no overlap
4f797d1a55 round 2: the manifest swap is crash-safe — fresh manifest to manifest-next.json inside the generation directory, then the old one away, then the fresh one over it; readActive settles every window (both present → finish; only next → adopt; torn or another build → discard, keep old); the fake moveFile mirrors the adapter (destination deleted first) with failure injected after it; the asset-path guard refuses the pending name nine reds, e.g. keeps 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) } ]
f8b13ba189 round 2: a walled same-build manifest is not persisted and the held routes are not refreshed — disk holds the last manifest this shell accepted, so offline reads the last grants it could use; the native-route arm keeps the write persists nothing of a manifest it walls: expected [ { kind: 'persist-manifest', …(1) } ] to deeply equal []
f6bf2b0a57 round 3: the phone's reader carries the host's refine buildId === computeMobileWebBundleId(assets) in one superRefine, 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 assets refuses a manifest whose build id is not the digest of the assets it names: expected true to be false

Also fixed on the way: mobile-web-shell-session-grants.test.ts read 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

  • The persist is unconditional on a same-build hit, so an unchanged manifest is rewritten once per mount, one small write. Skipping it would need the stored text out of 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; full config/scripts suite 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/ or orca-lanes, no max-lines disable or bump.

Lead gate on b484bf4be7 against 9243073b73: tsc 0, ratchet 0, all lint gates 0 (15 changed files), changed-code quality passed, React Doctor 0; config/scripts 251 files passed; mobile 809 files passed; no machine paths.

Lead gate on f6bf2b0a57 against 9243073b73: tsc 0, ratchet 0, all lint gates 0 (20 changed files), changed-code quality passed, React Doctor 0; config/scripts 251 files passed; mobile 809 files passed; no machine paths.

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
@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2c39d073-613d-4349-973e-7fb5802cdd73

📥 Commits

Reviewing files that changed from the base of the PR and between b484bf4 and f6bf2b0.

📒 Files selected for processing (10)
  • mobile/src/mobile-web-shell/generation-cache-uri.ts
  • mobile/src/mobile-web-shell/generation-manifest-swap.ts
  • mobile/src/mobile-web-shell/generation-store.test.ts
  • mobile/src/mobile-web-shell/generation-store.ts
  • mobile/src/mobile-web-shell/manifest-persist-refusal.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session-manifest-persist.test.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session.ts
  • mobile/src/transport/mobile-web-bundle-fetch.test.ts
  • mobile/src/transport/mobile-web-bundle-reply-schemas.test.ts
  • mobile/src/transport/mobile-web-bundle-reply-schemas.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • mobile/src/mobile-web-shell/manifest-persist-refusal.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session-manifest-persist.test.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The 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 f6bf2

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 37 functions across 20 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: persisting the fresh manifest on a same-build mobile cache hit.
Description check ✅ Passed The description is detailed and covers the purpose, implementation, edge cases, test coverage, and verification results. It does not use all template headings and omits the required Linked Issue forma…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3d17e074-f455-45c6-a9e5-80bcd31d4843

📥 Commits

Reviewing files that changed from the base of the PR and between 9243073 and b484bf4.

📒 Files selected for processing (15)
  • mobile/src/mobile-web-shell/generation-store-file-system.ts
  • mobile/src/mobile-web-shell/generation-store.test.ts
  • mobile/src/mobile-web-shell/generation-store.ts
  • mobile/src/mobile-web-shell/manifest-persist-refusal.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-reachability.test.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-reachability.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session-contract.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session-effects.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session-grants.test.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session-manifest-persist.test.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session-test-fixtures.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session.test.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-session.ts
  • mobile/src/mobile-web-shell/use-mobile-web-shell-session.test.ts
  • mobile/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one durability claim to reconcile, plus a minor suggestion.

Reviewed changes

  • Manifest write-through — GenerationStore.persistActiveManifest rewrites only manifest.json beside a host's active generation, refusing unless the build id and the asset list both match the stored generation (refuseManifestPersist, compared through serializeMobileWebBundleAssets). Refusals are return values; the write goes to <host>/tmp/manifest-next.json and is moved over the live file.
  • Reducer — onManifestRead now emits persist-manifest on every same-build read and carries the fresh routes onto session.cached, whatever the route verdict (open-generation, native-route, wall). Different-build arms still neither persist nor open the cache.
  • File.move adapter — new moveFile on the file-system port; deletes the destination first because expo-file-system 55's File.move refuses an existing destination.
  • Module splits — manifest-persist-refusal.ts and mobile-web-shell-reachability.ts keep 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

  • persistManifest rewrites manifest.json on 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. readActive already returns the parsed manifest, so comparing active.manifest.routes to the fresh routes before writing could skip the no-op case — the PR note that this would need the stored text out of readActive may 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'".

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

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.

@Jinwoo-H
Jinwoo-H merged commit 5064469 into main Sep 22, 2026
23 of 24 checks passed
@Jinwoo-H
Jinwoo-H deleted the ota-d1-manifest-persist branch September 22, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant