Skip to content

fix(mobile): count opening a cached page generation as use; cache six hosts - #23780

Merged
Jinwoo-H merged 6 commits into
mainfrom
mobile-web-shell-cache-recency
Sep 29, 2026
Merged

Jinwoo-H merged 6 commits into
mainfrom
mobile-web-shell-cache-recency

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​115 $\color{#cf222e}{\Huge{\mathbf{−}}}$​62 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​52 $\color{#cf222e}{\Huge{\mathbf{−}}}$​46 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6

What

The phone caches one OTA page-bundle generation per paired desktop and evicts the least recently used host past a ceiling. Recency was written only when a download committed, never when a cached bundle was opened. So a user with more desktops than the ceiling would see their daily host evicted first, because it was downloaded longest ago, and every return to it cost a fresh ~4 MB download that evicted another.

  • Opening a cached generation counts as use. readActiveGeneration moves the host to the end of the recency order inside the store's serialised queue, only when a generation is found and only when the host is not already last (the single-host case never writes), with no eviction pass because the host count did not change. The same-build recommit shares that one touchHost.
  • The index stores order, not time. hosts.json is now a list of host cache keys, least recently used first. Eviction needs nothing more, so there is no clock, no timestamp arithmetic, and a clock set back cannot demote the host in use. A host missing from the list sorts first; the host just activated is last, so it is never evicted. The timestamp record earlier builds wrote fails the parse and reads as empty once, which costs eviction order only, as the index already documents: recency, not truth.
  • Ceiling four hosts → six. Each host is about 8 MB on disk.
  • Update-failure log ceiling keeps its five-per-host ratio: 20 → 30.

persistActiveManifest still does not touch recency; its contract is "rewrites the manifest, and nothing else", and it always follows an open that already did.

Tests

  • New: a host opened after the others were activated is not the eviction victim when the ceiling is crossed (red before the change: expected undefined to be '75cb0005…'); opening the host already last writes nothing; an index write that fails during an open still returns the generation; a host missing from the order is evicted first; the old timestamp-shaped file reads as empty.
  • Eviction tests derive their host counts from MAX_CACHED_HOSTS instead of a hardcoded four. The failure-log test pins the ratio to the host ceiling (a derived constant would import-cycle).

… hosts

Eviction order was written only when a download committed, so a host opened
daily but downloaded long ago was evicted first and each revisit cost a full
redownload. An open now refreshes that host's recency inside the store queue.
The ceiling rises to six hosts and the update-failure cap to six hosts' worth.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…n open

An open stamped wall time, so a backward clock jump made the host in use the
oldest entry and the next download evicted it. Recency now stamps past the
newest entry. An unreadable or torn index read as empty, so every open rewrote
it with one host and demoted the rest; opens now leave it for a commit.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Changes host caching strategy and eviction logic.

The PR appears safe to merge, though a previously reported cache-order issue remains unresolved.

Findings

  1. P2 Failed read erases cache order ▶

Summary

The PR makes opening a cached mobile web generation refresh its host’s eviction order, changes the recency index from timestamps to an ordered list, and raises the cache ceiling from four hosts to six. The update-failure log ceiling rises proportionally.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Open cached generation] --> B{Generation found?}
  B -->|Yes| C[Move host to newest position]
  B -->|No| D[Leave order unchanged]
  C --> E[Return generation]
  F[Commit new generation] --> G[Move host to newest position]
  G --> H[Evict oldest host if over six]
Loading

Reviews (4) · Last reviewed commit: "Merge origin/main into mobile-web-shell-..."

@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 new issues found.

Reviewed changes

  • Recency on open — readActiveGeneration now routes through openActive, which stamps the host's recency in the store's serialised queue after a generation is found, with no eviction pass. It skips the write when no generation is found and when the index is unreadable/torn.
  • Order-based recency — new stampRecency sets the host to max(now(), ...values + 1), so a backward clock jump cannot mark the just-used host oldest; applied to both commit paths as well.
  • Ceilings — MAX_CACHED_HOSTS 4 → 6 and MAX_UPDATE_FAILURES 20 → 30, preserving the 5-per-host ratio (guarded by a test rather than an import that would cycle).
  • Index read contract — readHostIndex now returns null for unreadable/torn (was an empty Map); commit still rewrites it whole (?? new Map()) while openActive leaves it alone, and deleteHost tolerates null.
  • Tests — new cases for open-counts-as-use, null reads writing nothing, an unwritable index still returning the generation, backward-clock ordering, and a torn index left untouched; eviction tests derive host counts from MAX_CACHED_HOSTS; the offline-staleness assertion permits the one new hosts.json touch.

The behavior is coherent with the module's "recency, not truth" contract. I ran the full mobile-web-shell suite (91 files / 1343 tests) and tsc --noEmit against mobile — both green.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d17f26e4-5702-45c1-9e1d-88c3b1ec8ab4

📥 Commits

Reviewing files that changed from the base of the PR and between 2368d3a and 9f4f8e3.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 29f8e0d0-4265-4f1f-84aa-d77465a784e2

📥 Commits

Reviewing files that changed from the base of the PR and between 4b786e7 and 2368d3a.

📒 Files selected for processing (4)
  • mobile/src/mobile-web-shell/generation-store-host-removal-race.test.ts
  • mobile/src/mobile-web-shell/generation-store.test.ts
  • mobile/src/mobile-web-shell/generation-store.ts
  • mobile/src/mobile-web-shell/mobile-web-shell-update-failure-log.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/src/mobile-web-shell/mobile-web-shell-update-failure-log.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The generation store now supports six cached hosts and stores host recency as an ordered list in hosts.json. It updates recency when a generation is committed or successfully opened. Missing or invalid index data is treated as an empty order, and index writes remain best-effort. The global update-failure log limit increases to 30 entries, while the per-host limit remains five.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 2368d

The cache and failure-log capacity changes have no identified issue requiring resolution before merge.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 2368d

The cache can retain six hosts instead of four, and opening a cached page now updates its eviction order. The review found no demonstrated new security access path, but the format change and incomplete security coverage warrant a cautious assessment.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The device cache may retain two more host generations, and the global update-failure log may retain ten more entries; the inspected change does not establish broader service or tenant exposure.

Trust Boundaries and Controls

  • observed — The changed test helper adds no production entrypoint. The inspected production path obtains a host ID through the existing mobile session and passes its derived cache key to the store; caller authorization beyond that path was not established.

Resilience and Maintainability Implications

  • inferred — The production process-wide store contains the inspected read, commit, and removal paths within one queue. Separate instances sharing the same files would not receive that coordination; the reviewed evidence does not establish such instances in production.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives a detailed explanation of the behavior change and lists test coverage, but it omits most required template sections, including ELI5, Linked Issue, Visual Proof or an explicit N/A… Complete the required template sections. Add a plain-language ELI5 summary, a separate Why section, the linked issue under Linked Issue, Visual Proof or an explicit N/A with a reason, testing steps and platform coverage, AI Disclosure when …
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary changes: cached generation openings count as use, and the mobile cache limit increases to six hosts.
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.
Full details: Description check

Explanation

The description gives a detailed explanation of the behavior change and lists test coverage, but it omits most required template sections, including ELI5, Linked Issue, Visual Proof or an explicit N/A, Testing checkboxes and platform details, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Complete the required template sections. Add a plain-language ELI5 summary, a separate Why section, the linked issue under Linked Issue, Visual Proof or an explicit N/A with a reason, testing steps and platform coverage, AI Disclosure when applicable, Review, the Agent skill upstream boundary checkbox, Notes, and the Checklist. Mark completed checklist items accurately.

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • 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.

… write

Every open rewrote hosts.json even when the host was already the newest, so a
single-host user paid a native write per open. Opens now write only when the
order changes. The index is written to a sibling and renamed over the old one,
so an interrupted write leaves the previous index or none, never a torn file.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: cb8ea292-ca3c-485e-bb34-ceeee1396dc5

📥 Commits

Reviewing files that changed from the base of the PR and between 53f08c8 and 4b786e7.

📒 Files selected for processing (2)
  • mobile/src/mobile-web-shell/generation-store.test.ts
  • mobile/src/mobile-web-shell/generation-store.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 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 new issues found.

Reviewed changes

Since the prior pullfrog review (53f08c82f7), a single commit (4b786e7533) landed:

  • Skip no-op recency writes on open — openActive now writes the host index only when the host is absent from it or not already the newest entry, so the common single-host open does no native I/O. A new test pins that opening the newest host leaves the file bytes and write count unchanged while opening an older host writes.
  • Stage the index write — writeHostIndex writes hosts.json.tmp and renames it over hosts.json, so a kill mid-write leaves the previous index or none rather than a torn one. The write-failure tests now target the staging path and assert the previous index survives intact.
  • Reverted the offline-staleness relaxation — because the skip-write path means the single cached host is already newest, an open writes nothing, so mobile-web-shell-offline-grant-staleness.test.ts returns to its original "no writes" assertion and drops out of the diff.

I ran the full mobile-web-shell suite (91 files / 1344 tests) and tsc --noEmit against mobile — both green. The behavior remains coherent with the module's "recency, not truth" contract.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Eviction needs order only, so hosts.json is now the cache keys least recently
used first. That drops the clock, the monotonic stamp, the unreadable-versus-
absent split and the staged write: a torn or old-format file reads as empty,
the same state a missing one gives. Opens and same-build commits share one
touch that writes only when the host is not already last.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Comment on lines +107 to +109
const order = await readHostOrder()
if (order.at(-1) !== hostKey) {
await writeHostOrder(withHostLast(order, hostKey))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Failed read erases cache order If reading hosts.json fails while a cached generation is opened, readHostOrder returns an empty list. touchHost can then overwrite a valid list with only the opened host. When a later activation exceeds the six-host limit, the other hosts have no recorded order, so a recently used bundle may be evicted and downloaded again. Keep a failed read distinct from an empty index on this path.

Knowledge Base Used: Mobile web delivery

@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 new issues found.

Reviewed changes

Since the prior pullfrog review (4b786e7533), one commit landed (2368d3a7e6) — a refactor of the cache recency index:

  • Order, not time — hosts.json is now a string[] of host cache keys, least recently used first (HostOrderSchema = z.array(z.string())). This drops the now option, stampRecency/Math.max, and the unreadable-vs-absent null contract; readHostOrder returns [] for anything it cannot parse.
  • Staged write dropped — writeHostOrder writes hosts.json directly again. A torn or old-format file reads as an empty order, which is now the same state a missing one gives, so the staging added in the previous commit is no longer load-bearing.
  • Activated host stays protected — withHostLast is shared by touchHost and the commit path, so the just-activated/opened host is always last in the order; enforceHostLimit sorts activated hosts by order.indexOf (missing → -1, evicted first). I traced the ceiling-crossing and torn-index cases: the in-use host is never among the evicted and no generation is ever deleted from a lost order.
  • Tests — cases updated to the array shape; the clock-jump tests are gone and replaced with a legacy-timestamp-reads-as-empty case; the MAX_UPDATE_FAILURES ratio is pinned to MAX_UPDATE_FAILURES_PER_HOST * MAX_CACHED_HOSTS.

I ran the five changed-adjacent suites (72 tests) and tsc --noEmit -p mobile/tsconfig.json — all green, and oxfmt --check passes on the changed files.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit c634432 into main Sep 29, 2026
26 checks passed
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
…3789, #23812, #23852) into brennanb2025/codex-home-single-writer

#23744 moves every agent's folder pre-trust into the PTY spawn hook (and
the structured Codex chat create), removing Codex's launch-prep and
resume-prep trust writes. markCodexProjectTrusted now takes the config
files to write.

Conflicts:
- agent-trust-presets.ts: #23744's configFiles signature and nested lane
  acquisition, with this branch's lane rationale (hook installs read and
  rewrite across awaits); main's "capture->restore window" wording
  described the grant snapshot this branch removed.
- agent-trust-write-deadline.ts: the Codex writer waits only on
  managed-home installs' inline grant; the real-home background approval
  holds no lane. #23744's SSH/SFTP writer is gone, so it is no longer
  named; its 1.5 s short deadline is kept.
- codex-trust-config-concurrent-launch.test.ts: this branch's tests
  (a launch's write lands while a grant session runs; the renamed
  sibling-failure case) with #23744's new call signature.

Outside the conflicts: codex-launch-during-real-home-grant.test.ts passed
launchAgent/workspacePath into launch prep, which #23744 removed; its
launch helper now runs launch prep and then applyAgentWorkspaceTrust, as
the spawn builder does, so it still proves a launch and its project trust
land while the real-home approval hangs.
@Jinwoo-H
Jinwoo-H deleted the mobile-web-shell-cache-recency branch October 1, 2026 05:19
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