Skip to content

fix: page every read that feeds a deterministic fold - #2

Merged
PastaPastaPasta merged 4 commits into
masterfrom
claude/affectionate-rubin-qrbh2s
Sep 21, 2026
Merged

PastaPastaPasta merged 4 commits into
masterfrom
claude/affectionate-rubin-qrbh2s

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Sep 11, 2026 •

Copy link
Copy Markdown
Owner

The bug

Platform serves at most 100 documents per query, and Drive fills an absent limit from DriveConfig::default_query_limit — which is also 100. So forge-core's pervasive limit = 0 argument, written throughout to mean "no limit", was in fact a silent 100-row truncation with no short-page signal; forge-web's explicit limit: 100 was the same thing.

That does not make a fold stale. It makes it confidently wrong. Reproduced against the real application readers with a mock SDK that enforces the actual page cap:

readRefUpdates  on a ref with 101 updates  -> 100
readEvents      on a target with 101 events -> 100

What each one costs

Read Severity Consequence
readEvents (web) blocker an issue reads open after it was closed; a merged PR reads unmerged
ref history (both) blocker branch pinned at push #100; stale ls-remote, stale clones, false non-fast-forward
pack manifests (both) blocker packRef indices shift → objects read from the wrong pack; clones miss the base pack
config timeline (both) high protected-branch enforcement silently switches off
comments, releases, labels, mirrors medium rows vanish rather than going stale (newest-wins folds)

Three of these deserve spelling out:

Events are un-gated. event carries no tokenCost in repo-v1.json, so anyone with a Platform balance may append. Pad a fresh issue or PR with 100 inert events and every later close, reopen, label, assign or merge lands past row 101 and is invisible to forge-web forever. forge-core already defended against exactly this — fetch_events uses query_all_documents and its comment says why — the TypeScript port did not.

Pack manifests are positional. A locator addresses pack bytes by packRef = the pack's index in oldest-first order. Drop the oldest manifests and every index shifts: lookups then read a valid offset in the wrong pack and return corrupt objects, with nothing in the reader able to detect the misalignment. On the transport side the initial import pack — holding the root objects every incremental pack deltas against — falls out of the set, so fetch downloads packs it cannot index. repack reads the same list and would consolidate over an incomplete input, then delete the chunks it superseded.

Config truncation disables a security rule. config_as_of treats "no config in force" as unprotected, so dropping early history silently re-admits plain refUpdates on protected refs that the rules layer had correctly rendered inert. The two clients also read this timeline in opposite directions — Rust ascending, forge-web descending — so past 100 revisions they held disjoint windows of the same append-only history and could resolve the same ref differently. That is precisely the failure FORGE_RULES_V1 exists to prevent.

Beyond the call sites

  • queryAllDocuments now throws IncompleteReadError when it cannot prove it reached the end — a full page it cannot advance past, or the page-count safety cap — instead of returning what it has. A caller folding a partial history cannot tell "no more events" from "I stopped early".
  • PlatformClient::query_documents rejects limit = 0 outright, naming query_all_documents as the way to ask for everything. This is the footgun that produced the whole class of bug. Caller-supplied page sizes are clamped to ≥ 1 at the service boundary, so a --limit 0 from the CLI is still a page.
  • loadArtifactBytes asked for a whole artifact in one range, which fetchPlatformRange capped at 100 chunk documents — a hard ceiling of ~1.47 MB, so a locator for a repo past roughly 40k objects could never load at all. Oversized requests now split across parallel queries.

Ref naming was also divergent

refNameHash is the indexed key but refName is caller-supplied content, so a token holder can file an update under main's hash carrying any legal name. resolve_ref correctly ignores such an update — but forge-core named the ref from the newest update unconditionally, and forge-web from the last element of a plain-then-protected concatenation. Either could show a branch under a name the other does not, and in ls-remote that also breaks the HEAD symref. Extracted as a shared display_ref_name / displayRefName rule with four new conformance vectors, so it is pinned rather than duplicated.

Why the conformance suite did not catch any of this

Every vector hands the pure functions a ready-made input array. The suite proves the two ports fold identically given identical input; it says nothing about whether each client fetches identical input. Every bug above is invisible to a green conformance run — which is how they survived. Both harness headers now say so.

That class is covered instead by forge-web/lib/repo/pagination.test.ts, which drives the application readers across a page boundary. I confirmed it bites: stashing the source fixes and re-running, all 9 tests fail with exactly the truncation signatures, including c-0100 first in the config case — proving the descending window had dropped the oldest config.

Verification

Check Result
cargo test --locked --workspace 188 passed
cargo clippy --locked --workspace --all-targets -- -D warnings clean
cargo fmt --all -- --check clean
pnpm test 172 passed (159 baseline + 9 pagination + 4 conformance)
pnpm typecheck / pnpm lint clean

Rust conformance runs the same 70 vector files; I verified the new case is actually executed by breaking a vector and watching it fail.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dh6fiRJTR2vXa6LBUXKdeB


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Repository, issue, pull request, comment, reference, configuration, pack, and registry views now retrieve complete histories beyond the previous 100-item limit.
    • Prevented incomplete reads from silently appearing as complete data.
    • Ref names are shown only when safely verified against their corresponding identifiers.
    • Browse-source loading now supports larger artifacts and repositories.
  • User Interface

    • Issues and pull requests display an “Unverified” status when their event history cannot be fully read.
  • Documentation

    • Updated testnet validation and parity status to reflect 70 passing conformance vectors.

Platform serves at most 100 documents per query. Drive fills an absent limit from
`DriveConfig::default_query_limit`, which is also 100 — so in forge-core a
`limit = 0` argument, written throughout to mean "no limit", was in fact a silent
100-row truncation with no short-page signal, and in forge-web an explicit
`limit: 100` was the same thing.

That does not degrade a fold. It makes it confidently wrong. Reproduced against
the application readers with a mock SDK that enforces the real page cap:

    readRefUpdates  on a ref with 101 updates -> 100
    readEvents      on a target with 101 events -> 100

Both readers feed `FORGE_RULES_V1` folds over a whole history, so what the caller
gets back is not a stale answer but a different one.

**Events (blocker, and a live attack).** `event` carries no `tokenCost` in
repo-v1.json — anyone with a Platform balance may append. Pad a fresh issue or PR
with 100 inert events and every later close, reopen, label, assign or merge lands
past row 101 and is invisible to forge-web forever: the issue reads open, the
merged PR reads unmerged. forge-core already defended against exactly this
(`fetch_events` uses `query_all_documents`, and says why); the TypeScript port did
not.

**Ref history (blocker, both clients).** A branch pushed more than 100 times
resolved to the tip of push #100 permanently. Downstream, `list` advertises the
stale oid, clones get a stale HEAD, and `plan_pushes` compares new pushes against
it and calls correct fast-forwards non-fast-forward. It also feeds the historical
-tips predicate, so a genuinely merged PR folds as open. forge-core was already
internally inconsistent here: `base_ref_tips` pages this same data, so one binary
could disagree with itself about a ref.

**Pack manifests (blocker, both clients).** `read_pack_manifests` took the newest
100. A locator addresses pack bytes by `packRef` = the pack's index in oldest-first
order, so dropping the oldest manifests shifts every index: lookups then read a
valid offset in the wrong pack and return corrupt objects, with nothing able to
detect the misalignment. On the transport side the initial import pack — holding
the root objects every incremental pack deltas against — falls out of the set, so
`fetch` downloads packs it cannot index. `repack` reads the same list and would
consolidate over an incomplete input, then delete the chunks it superseded.

**Config timeline (high, and a security regression).** `config_as_of` treats "no
config in force" as UNPROTECTED, so dropping early history silently re-admits
plain `refUpdate`s on protected refs that the rules layer had correctly rendered
inert. The two clients also read this timeline in opposite directions — Rust
ascending, forge-web descending — so past 100 revisions they held *disjoint
windows* of the same append-only history and could resolve the same ref
differently. That is the failure FORGE_RULES_V1 exists to prevent.

Also paged: comments, releases and labels (both newest-wins folds, where a capped
read drops rows entirely rather than showing them stale), and pack mirrors.

Three changes beyond the call sites:

* `queryAllDocuments` now THROWS `IncompleteReadError` when it cannot prove it
  reached the end — a full page it cannot advance past, or the page-count safety
  cap — instead of returning what it has. A caller folding a partial history
  cannot tell "no more events" from "I stopped early".

* `PlatformClient::query_documents` rejects `limit = 0` outright, naming
  `query_all_documents` as the way to ask for everything. This is the footgun that
  produced the whole class of bug; caller-supplied page sizes are clamped to >= 1
  at the service boundary so a `--limit 0` from the CLI is still a page.

* `loadArtifactBytes` asked for a whole artifact in one range, which
  `fetchPlatformRange` capped at 100 chunk documents — a hard ceiling of ~1.47 MB,
  so a locator for a repo past roughly 40k objects could never load at all.
  Oversized requests now split across parallel queries.

While here, the two clients disagreed on how a ref is NAMED. `refNameHash` is the
indexed key but `refName` is caller-supplied content, so a token holder can file
an update under main's hash carrying any legal name; `resolve_ref` ignores such an
update, but forge-core named the ref from the newest update unconditionally and
forge-web from the last element of a plain-then-protected concatenation. Either
could show a branch under a name the other does not, and in `ls-remote` that also
breaks the HEAD symref. Extracted as a shared `display_ref_name` /
`displayRefName` rule with four new conformance vectors, so it is pinned rather
than duplicated.

The conformance harness headers now state their scope: the vectors prove the two
ports FOLD identically given identical input, and say nothing about whether each
client FETCHES identical input. Every bug above is invisible to a green
conformance run, which is how they survived. That class is covered by
`lib/repo/pagination.test.ts`, which drives the application readers — not the pure
functions — across a page boundary, and fails on every one of these defects when
run against the pre-fix code.

Verified: 188 Rust tests, 172 web tests, clippy `-D warnings` clean, fmt clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Dh6fiRJTR2vXa6LBUXKdeB
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 4f04c613-8a9c-43c8-a15d-41350c322e2f

📥 Commits

Reviewing files that changed from the base of the PR and between b50ecf7 and 6558a08.

📒 Files selected for processing (32)
  • EXECUTION.md
  • README.md
  • crates/dg/src/repo.rs
  • crates/forge-core/src/collab.rs
  • crates/forge-core/src/error.rs
  • crates/forge-core/src/platform.rs
  • crates/forge-core/src/repo.rs
  • crates/forge-core/src/rules.rs
  • crates/forge-core/tests/collab_tokens.rs
  • crates/forge-relay/src/ingest.rs
  • crates/git-remote-dash/src/admin.rs
  • docs/design-freeze-2.md
  • forge-contracts/vectors/display_ref_name__name_from_newest_matching_update.json
  • forge-contracts/vectors/display_ref_name__no_matching_name_is_none.json
  • forge-contracts/vectors/display_ref_name__other_key_updates_ignored.json
  • forge-contracts/vectors/display_ref_name__other_key_with_matching_name_ignored.json
  • forge-contracts/vectors/display_ref_name__tie_at_timestamp_id_tiebreak.json
  • forge-web/components/repo/issues-content.tsx
  • forge-web/components/repo/pulls-content.tsx
  • forge-web/lib/repo/config.ts
  • forge-web/lib/repo/issues.ts
  • forge-web/lib/repo/packs.ts
  • forge-web/lib/repo/pagination.test.ts
  • forge-web/lib/repo/refs.ts
  • forge-web/lib/repo/writes.ts
  • forge-web/lib/rules/conformance.test.ts
  • forge-web/lib/rules/index.ts
  • forge-web/lib/rules/resolveRef.ts
  • forge-web/lib/sdk/index.ts
  • forge-web/lib/sdk/query.ts
  • forge-web/lib/view/browse-source.ts
  • forge-web/lib/view/issues-view.ts
 ________________________________________________________________________________________________________________________________________
< Use assertions to prevent the impossible. Assertions validate your assumptions. Use them to protect your code from an uncertain world. >
 ----------------------------------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • 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.

Making `query_documents` reject `limit = 0` was right — it silently meant
"Drive's default 100" and produced the truncation this branch is about — but the
change stopped at forge-core's own module. Four call sites in other crates still
passed 0 and now hard-error at runtime, and none is covered by the test suite:

* **`forge-relay` could not start.** `preload_targets` (ingest.rs) reads every
  issue and patch to map an event's `targetId` back to its target; both calls
  passed 0, so `init_repo` failed for every configured repo and the daemon
  refused to come up. Now `query_all_documents` — that index has to be complete
  anyway, since a target missing from it is an event the relay cannot describe.
* **`dg repo list` was unconditionally broken.** The subcommand has no `--limit`
  flag, so it always passed 0. Now complete: it prints "the owner's repos", and a
  101st repo missing from that would be a wrong answer, not a short one.
* `git-remote-dash --dump-refs` — a diagnostic whose whole purpose is to dump the
  raw history; now dumps all of it.
* The `collab_tokens` live-testnet test helper, which would have panicked the
  moment the gated suite ran.

The `limit.max(1)` clamp was also wrong in a quieter way. `dg issue list` and
`dg pr list` declare `--limit` with `default_value_t = 0` and the help text
"0 = server default", so clamping 0 to 1 turned the default invocation into a
one-row listing. 0 now maps to a real page size.

Two more from the same review:

* `inBatchAllPerKey` / `inBatchNewestPerKey` were dead code — nothing imported
  them — and `inBatchAllPerKey`'s docstring advertised it as the completeness
  primitive for event folds while capping each key at 100 rows with no short-page
  check. A future "fix" that routed `readEvents` through it would have read as
  correct in review and changed nothing. Deleted rather than left as a trap.
* `skipScanDistinct` returned a silently short key list when it hit `maxKeys` or
  a non-string key. A truncated ref enumeration is the same class of
  confidently-wrong answer as a truncated history — the caller renders "these are
  the branches" from a partial set — so it now throws `IncompleteReadError` like
  the paging loop does.

And `findOwnRegistryDoc` in forge-web, whose docstring says it mirrors forge-core
`find_own`, read one page where `find_own` pages: a user past 100 stars could not
un-star an older repo, and the call reported success, because "not found" and
"not looked at" are indistinguishable at that call site.

Verified: 190 Rust tests, 172 web tests, clippy -D warnings clean, fmt clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Dh6fiRJTR2vXa6LBUXKdeB
Review of the previous two commits found that throwing on an unprovable read was
right for a detail view and wrong for a list, plus four smaller gaps.

**One buried target took down a whole page.** `issue`, `patch`, `comment`, `event`
and `review` carry no `tokenCost`, so anyone with credits may append without
limit. `listIssues` and `listPulls` fold every row inside a single `Promise.all`,
so after the previous commit a single target padded past the reader's page cap
failed the entire list — a worse outcome than the staleness being fixed, and
reachable by anyone willing to pay storage fees.

Detail reads still throw: there, a confidently wrong state is worse than an
error. List reads now catch per row and keep it, with `stateComplete: false`, and
both list UIs render that as "state unverified" rather than showing a fold over a
partial history as fact. Dropping the row instead would have been the same class
of bug as truncating it.

**The naming rule's two callers disagreed on the null case.** The rule itself
ports exactly, but forge-core's `read_refs` skips a ref with no displayable name
while forge-web rendered it with `refName: ''` — reopening the divergence the
shared rule was extracted to close, one level up. forge-web now drops it too.

**The new vectors did not pin what they claimed.** The reviewer ran two mutants of
the rule — one deleting the `refNameHash == key` guard, one deleting the preimage
check — and all four vectors passed against both. Added the one shape that only
the key guard rejects: an update whose own key is a different ref but whose
`refName` hashes to the key being queried. The "tie at timestamp" vector was
misnamed: which of two tied updates wins is not observable through this rule at
all (two distinct names cannot hash to one key), so it is re-described as what it
actually pins rather than left claiming a tiebreak it cannot see.

**Chunk fan-out was unbounded.** A 100 MB artifact spans ~7,100 chunk documents,
so splitting oversized requests meant ~72 simultaneous proof-verified queries with
all-or-nothing failure and no bound on peak memory. Now a small pool, and
`loadArtifactBytes` delegates to the windowed loader instead of requesting a whole
artifact as one range.

**The two pagers disagreed at their own boundary.** forge-web caps at 1000 pages
and throws; forge-core's loop had no cap and no error, so on a target with 100,001
events one client hard-errors while the other keeps paging — a cross-client
divergence introduced by the fix for cross-client divergence. forge-core now has
the same cap and an `Error::IncompleteRead` mirroring `IncompleteReadError`, and
also refuses the impossible "full page with no cursor document" rather than
treating it as the end.

Also: the vector count was left stale in a fourth place, in a sentence that also
still described the superseded sibling-checkout CI arrangement.

Verified: 188 Rust tests, 175 web tests, clippy -D warnings clean, fmt clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Dh6fiRJTR2vXa6LBUXKdeB
Review of the test suite found that the paging LOOP was genuinely pinned but the
query SHAPE it carries was not, and that the reviewer could write a wrong
implementation the suite accepts.

**The mock ignored `where` entirely**, and every fixture held rows for exactly one
ref/target/owner — so deleting `where: [['targetId','==',targetId]]` from
`readEvents` passed all nine tests while making every issue in a repo fold every
other issue's close events (`foldIssueState` never checks `targetId` itself). The
mock now applies `==`, `in` and `>` clauses, sorts by the NAMED orderBy field
rather than just its direction, and the ref and event fixtures seed decoy rows the
filter must exclude. Verified by mutation: dropping that filter now fails.

**The `seen` query recorder was dead code** — pushed to on every query, never
asserted. The ref-history test now pins the shape: the filter is carried on both
pages, page 1 has no cursor, and page 2 resumes from the last `$id` of page 1
rather than re-reading it.

**The packRef consequence was not gated at the composition point.** The manifest
test asserted a row count; the failure that matters is objects read from the wrong
pack. A new test composes a complete manifest read with `orderGitPacks` and
asserts packRef 0 is the OLDEST pack — which is exactly what a truncated read
shifts.

**Half the fixed readers had no test**: added `readComments` across a page
boundary (with a decoy on another target), and `skipScanDistinct`'s two new
throws. That second one surfaced a real off-by-one: the loop ran `maxKeys`
iterations, so a key space of exactly `maxKeys` — which IS complete — threw as
though it had overflowed. It now probes once more.

**The Rust paging loop had no seam.** It was a method on `PlatformClient`, which
owns a live `Sdk`, so the one piece of logic deciding whether a read is complete
was the one piece with no test. Extracted `page_to_exhaustion` over an injected
page fetcher; `query_all_documents` is now a closure over `query_documents`. Five
tests cover it, including the subtle case — an exactly-full last page is not
itself proof of the end and must provoke one more probe. Verified by mutation:
relaxing the short-page check to `<=` fails three of them.

**One vector was unfalsifiable.** `display_ref_name__tie_at_timestamp_id_tiebreak`
could not fail for a wrong tiebreak: two distinct names cannot hash to one key, so
which of two tied updates wins is unobservable through this rule. Removed rather
than left as apparent coverage, and the remaining vectors now say plainly that
they pin the preimage/key filter and not an ordering — so a future relaxation of
the filter cannot silently un-pin itself.

Verified: 193 Rust tests, 178 web tests, clippy -D warnings clean, fmt clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Dh6fiRJTR2vXa6LBUXKdeB
@PastaPastaPasta
PastaPastaPasta merged commit 2bad41b into master Sep 21, 2026
2 checks passed
PastaPastaPasta added a commit that referenced this pull request Sep 25, 2026
…mirror lies

Review #2/#4/#9: requests are limited to 4 per origin and a pack's URLs are raced 3 at a time; the 15 s deadline covers the response starting and then each gap between chunks, not the time spent queued; a URL that timed out gets one sequential retry before the pack is declared unavailable; URLs that failed outright are remembered for the session; range reads use the same list; a Platform pack failing cancels the external downloads; a partial clone is reused for 60 s, not the session, so a later view retries the mirrors. Review #8: a mirror serving bytes that fail the sha256 is shown as 'served bad data' and recorded separately in the ledger and trust detail. Review #5: a REF_DELTA whose base is in a skipped pack names that pack instead of failing with a bare indexer error.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PastaPastaPasta added a commit that referenced this pull request Sep 30, 2026
The live vitest tests read the fixture owners from the seed summary (v2.live, chrome.live were still on moutai's identity ids). A malformed seed summary no longer breaks every spec's import: seedRepo returns null and loadSeedPulls names the file. fg5-dash skips only when the dash mirror's name does not resolve, not on a transport failure. pulls-budget opens the merged PR by its dense number from the seed summary (#6, was #2). The docs say the hosted site and the nightly follow master's workflow files, so they move to bonsia at the cut-over.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Sep 30, 2026
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.

2 participants