Skip to content

fix(web): retry a composite read on a stale contract, and refetch only the contracts that moved - #394

Merged
PastaPastaPasta merged 4 commits into
masterfrom
fix/stale-contract-browser
Oct 5, 2026
Merged

PastaPastaPasta merged 4 commits into
masterfrom
fix/stale-contract-browser

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

#367 added a refetch-and-retry for reads that fail because the web app holds a contract older than the network's. In a real browser it still failed after UPDATE-1 (#390) took the sakura contracts to version 2. With the version-1 snapshot seeded, a fresh load of a repo page that shows a version-2 document said "That read did not land … trailing bytes … refetch the contract". "Try again" worked a few seconds later; a reload failed again.

Root cause

  • The composite read had no retry. The failing read was the repo-header read in lib/repo/chrome.ts. It goes through queryComposite (lib/sdk/composite.ts), which runs sub-queries across forge-core, forge-collab, forge-community and DPNS. That path never called retryOnStaleContract, so it rejected with the stale-contract error while revalidateSeeded refetched the contracts in the background. Those were the three getDataContract calls in the network log, and the reason "Try again" later worked.
  • A race in the seeded-version check. revalidateSeeded took a contract out of seeded before refetching it. A read failing in that window on a type an update added gave up. One failing on a newer document fetched the contract a second time.

Fix

  • retryOnStaleContract takes several contract ids, because the error doesn't name the stale contract. It refreshes each one and retries once if any was refreshed. The composite read uses it, and so do count, grouped count, sum and ranked reads.

  • revalidateSeeded refreshes through refreshStale, so a read failing in that window joins the refetch already in flight.

  • No refetch storm. The stale handler receives every contract the failed read used.

    • A one-contract read keeps the old path, with no extra request.
    • A multi-contract read makes one shared getDataContractsLatestVersions lookup. It refetches only contracts whose network version is past what this tab holds (the seeded version, or one a recent refresh fetched), and for a newer document, only those at or above the document's version.
    • A refresh already recorded in the window is joined, not repeated.

    An independent review showed the earlier per-contract logic refetching an unchanged contract on every failure (10 failures, 10 fetches). Tests now pin that down.

Evidence

  • Unit tests: new vitest cases in query.test.ts, service-stale.test.ts and a new composite.test.ts. They cover the composite retry, the race, the storm cases (seeded and unseeded, 10 failures, the moved contract refetched once), a composite with an unknown type, and "one contract costs no version lookup". The fix cases fail on master, and the storm cases fail with the per-contract logic.
  • Browser: a local sakura build seeded with the version-1 snapshot, driven by Playwright in fresh contexts.
Page Before After
rc1u-muutofz9/releases error renders (3 of 3 loads)
rc1u-muutofz9/issues/1 error renders (3 of 3)
rc1u-muutofz9/pulls/2 error renders (3 of 3)
v1 forge-v2-demo renders renders (3 of 3)

After the fix, each of the three rc1u pages makes three getDataContract requests (the three changed contracts) and two getDataContractsLatestVersions per load. Full vitest passes 5953 tests; tsc, lint and copy lint pass.

  • forge-core: no change needed. Its composite path already refreshes every contract it reads and retries, and its refresh never empties the cache.

#390 already ships the version-2 snapshot, so this matters for tabs left open across an update and for the next in-place update.

🤖 Generated with Claude Code

PastaPastaPasta and others added 4 commits October 5, 2026 02:29
…de stale

The repo chrome reads through documents.composite (a forge-core repo page with sub-queries over forge-collab, forge-community and DPNS), which had no stale-contract retry. With a v1 seed, a v2 issue or patch in a sub-query failed the whole read with 'trailing bytes ... refetch the contract' (a wasm-bindgen object in the browser), so the releases, issue and PR pages of an updated repo showed the error on every fresh load; the background seeded-version check refetched the contracts only after the page had given up, which is why Try again worked.

retryOnStaleContract now takes every contract a read touches (the error does not name the stale one), refreshes each and retries once when any was. The composite read and the count, sum and ranked aggregates go through it too.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…its refetch

revalidateSeeded took a contract out of seeded before refetching it, so a read failing meanwhile on a type an update added found it neither seeded nor refreshable and gave up, and one failing on a newer document fetched it a second time. The check now refreshes through refreshStale, which registers the refetch for those reads to join. A seeded contract already at the failed document's version is left alone, so a composite does not refetch its current contracts.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…etwork moved past

A composite's stale-contract error names a document version, but not which contract it belongs to, and versions of different contracts do not compare. Comparing it with each contract's own version refetched current contracts, and kept refetching them: a refreshed contract below the document's version stayed 'outran' for the whole window (10 failing reads, 10 getDataContract for forge-core), and with no snapshot every fetched contract was refetched on the first failure.

The stale handler now receives every contract a read used. One contract keeps the cheap path. Several are placed with one getDataContractsLatestVersions request (shared by reads failing together): a contract is refreshed only when the network's version is past the one held (seeded, or fetched by a recent refresh) and, for a newer document, at least that document's version; one held at no known version only for a newer document. A contract refreshed within the window is joined, so a read that failed while the seeded-version check refetched it still retries. A 'document type not found' composite now refreshes only the seeded contracts that moved.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0c65af25-ac3b-46a2-aa42-bb52c8092c7d
📥 Commits

Reviewing files that changed from the base of the PR and between 7177d17 and 9dbaf2f.

📒 Files selected for processing (7)
  • forge-web/lib/sdk/composite.test.ts
  • forge-web/lib/sdk/composite.ts
  • forge-web/lib/sdk/query.test.ts
  • forge-web/lib/sdk/query.ts
  • forge-web/lib/sdk/service-stale.test.ts
  • forge-web/lib/sdk/service.ts
  • forge-web/lib/sdk/write-engine.test.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@PastaPastaPasta
PastaPastaPasta merged commit 83af543 into master Oct 5, 2026
13 checks passed
@PastaPastaPasta
PastaPastaPasta deleted the fix/stale-contract-browser branch October 5, 2026 09:30
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