Skip to content

feat: history index v2 — per-path version lists for Blame and History - #168

Merged
PastaPastaPasta merged 6 commits into
masterfrom
feat/history-index-v2-path-versions
Sep 29, 2026
Merged

PastaPastaPasta merged 6 commits into
masterfrom
feat/history-index-v2-path-versions

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

What

History index v2: the push-time history index (packManifest kind 3, #146) now also lists, for every path of the tip, its newest 256 first-parent versions. Each version has the commit (with author, time and subject) and a 6-byte blob oid prefix, and each list says whether it reaches the commit that added the path. Blame and a path's History read those lists through pathVersions instead of walking history in the browser. They fall back to the walk when the index is missing, behind, stale or fails to load.

Design: docs/design/history-index.md ("v2: per-path version lists"). The original proposal is docs/design/last-change-index-v2.md, now marked implemented, with where the build differs from it.

Numbers (offline, dashpay/dash develop @ 3ba0805c)

moutai moved to beta.7 and can no longer be read with the forge contracts, so the "after" measurement is an offline replay. forge-web/lib/view/history-replay.test.ts runs the real BrowseReader, blameFile and pathVersions over the pack a push of that tip builds, its locator and its v2 index (all exported by forge-core's export_a_replay_fixture). It reads chunk documents as the browser does: 14,700-byte chunks, 100 per query, a 32 MiB chunk cache, 280 ms per query. The answers with and without the index must be equal, and they are.

walk (today) v2 index
Blame src/clientversion.h (135 versions, 10 commits) 357 chunk queries, ~102 s 16 queries, ~3.9 s, identical hunks
History src/validation.cpp, first page (40) 22 queries, ~6.3 s (276 commits walked) 3 queries, ~0.9 s, identical commits

The live baseline on moutai was 121 s and 427 requests; the showcase mirror holds many packs, not one. Follow-up: measure live on bonsia once the dash mirror is re-imported, with dg repo reindex as its owner, then e2e/history-index.spec.ts hi-2 and hi-3.

Sizes and fees (dash, quoted upper bounds, docs/guides/costs.md)

size chunks Platform your own storage
full v2 752,738 B 52 ~0.284 DASH ~0.0016 DASH
delta, 1 / 10 / 50 / 200 commits 236 B / 1.9 KB / 12.3 KB / 47.7 KB 1 / 1 / 1 / 4 ~0.0026 / 0.0031 / 0.0060 / 0.020 DASH ~0.0016 DASH

Average per push on Platform: about 0.009 DASH, over a cycle of ~80 one-commit pushes per full index (see below).

Format and rules

  • Format. A new tagged section (tag 1) after v1's paths, and version = 2. v1 readers already skip unknown tags, so there is no flag day. The section has, per path row: (count << 1 | complete), then (commit, mode, oid prefix). It also holds an author table.
  • Why K = 256 and 6-byte prefixes. Measured on dash, K = 32 would still walk 1,947 commits for clientversion.h, which has 136 versions. Blame compares at most 201 versions. Whole oids would make the index 1.3 MB (91 chunks). The web resolves a prefix through the locator it already holds, uses it only when it names exactly one object, and hash-checks the object it then reads.
  • Delta merge rule. A delta's list comes first, then the base's list, deduplicated and cut to K. A complete delta list (the path was re-added) replaces the base's. A path the delta changed but has no list for (a v1 delta) is unknown. The same rule is implemented in forge-core (overlay_versions) and forge-web (overlayVersions). Both are tested on the same git-built fixtures (forge-contracts/fixtures/history-index-v2-{base,delta,tip}.hex), where base overlaid with delta equals the full index of the tip.
  • Format marker. A kind-3 manifest's offsetIndexParts (otherwise unused, since the artifact locates itself) records the format: 2 for v2, 0 from v1 writers. A v1 index neither covers a tip nor serves as a delta base, so the next push, or dg repo reindex, publishes a full v2 over it (the backfill). Reindex says "replaces the tip's v1 index". A delta also supersedes a v1 index of its own tip, and the web ranks a tip's indexes v2 first. This will be reworked at the wipe/beta7: the contract rework (R-09, pack_complete) makes packHash an identifier and drops offsetIndexParts and manifestPart. The marker is read in one place on each side (forge-core HistoryEntry::format, forge-web PackManifest.historyFormat), so it moves with whatever replaces the field.
  • Writer bounds. Both decoders refuse, whole, an index over 4M rows or 64 MiB inflated. That would lose the column and count too. So the writer halves the per-path limit until the index fits. It stays v2 and never falls back to v1.
  • A declined full index offers the delta. When a full index is due but the delta is still at most half the base, the helper's cost guard is asked again with the delta. Before, a declined full index refused a push that stored a pack, and left a pack-less push with no index.
  • Full republish is now rent-or-buy. Each delta is cumulative, so every push pays for all changes since the base again. The old rule (delta under half the base) would let one-commit pushes climb to ~0.14 DASH each at v2's size. Deltas now go on while the v2 deltas members already published over the base, plus this one, stay within the base's size. Only current members' manifests count, so a stranger cannot force full republishes.
  • Reader. A list is believed only where the path's entry at the page's start is what it claims. That is the blob prefix for a file, and only the mode for a directory or gitlink, since the index stores no oid for those. The check applies to pages resumed inside a served list too. A list naming a commit that cannot be read is dropped for the walk. A blob the index names that cannot be read as the file's text sends that version back to the trees. Past a cut list the walk goes on from the oldest listed commit's parent, and a walk stops at a commit an index covers (an index a few pushes behind). Blame takes the list whole, keeps only the texts it is about to compare (four read ahead, none once every line has its commit), and reads no commit or tree except the adding commit's rename check. The History page moves onto pathVersions and says "from the history index".

Tests

  • forge-core: lists equal a brute-force tree-by-tree walk and git log --first-parent -- <path> across merges, renames, deletes, delete and re-add, file to directory, mode changes and gitlinks. Also: the limit and complete; delta overlay equals a full index; mixed v1/v2; the v2 decoder fixture; hostile sections (limit, oidLen, author and commit indexes, an over-long list, trailing bytes, a duplicate section, row cap, inflate cap); the planner's v1 handling and the rent-or-buy rule. The v1 fixture is unchanged.
  • forge-web: the decoder (the v2 fixture, the overlay against forge-core's trio, mixed v1/v2, the same hostile sections); pathVersions (served with only the start commit and root tree read, paging and resume equal to the walk for files and directories, a cut list, stale, failing and v1 indexes, a behind index, the whole-repo log never asking); blame over the index equals the walk and reads no commit past the tip.
  • Offline replay on real dash data (above). The live Playwright hi-2 and hi-3 run on bonsia after the re-import. The live e2e job is expected red until the cut-over.

Found on the way

dash's v1 index counts (33,553 / 7,979) came from a shallow clone. The real counts are 34,001 / 8,363. The shallow check now refuses such a clone, and the next index published for the mirror corrects them.

Tradeoff to note

The home's commit column loads the same artifact, so a cold home of dash downloads ~750 KB instead of 67 KB. It is still one chunk query, and IndexedDB caches it. The web decodes the lists section only when Blame or History first reads it, so the column doesn't parse it. Splitting the lists into their own kind-4 artifact would avoid the download too, if that matters.

Review

code-review-validator: M1 (Blame memory), M2 (writer bounds, plus lazy decoding) and L1–L8 are all addressed in 1d05774. code-simplifier's edits are behaviour-neutral, and the fixtures are byte-identical.

🤖 Generated with Claude Code

PastaPastaPasta and others added 5 commits September 29, 2026 15:02
A new tagged section (tag 1) after v1's paths: per path, its newest 256 first-parent changes (commit, mode, 6-byte blob oid prefix) and whether the list reaches the commit that added it, plus the commits' author names. v1 readers skip it. The manifest's offsetIndexParts records the format (2), so a v1 index neither covers a tip nor serves as a delta base: the next push or dg repo reindex publishes a full v2 index over it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Each delta is cumulative, so every push pays for all changes since the full index again. The old rule (delta under half the base) was cheap at v1's 67 KB; at v2's 753 KB it let one-commit pushes climb to ~0.14 DASH each. Rent or buy: publish deltas while the v2 deltas members already published over the base plus this one stay within the base's size, then a full index. On dashpay/dash that is about every 80 one-commit pushes, ~0.009 DASH a push on average.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
pathVersions answers from the v2 index's list when one covers the start commit (checked against the path's entry there), resumes inside it page by page, walks on past a cut list, and stops a walk at an index a few pushes behind. Blob oid prefixes resolve through the locator, so Blame reads one blob per version, four ahead, and no commit or tree. The History page moves onto pathVersions and says when the index listed it. The decoder reads the versions section and overlays deltas by the shared merge rule.

Offline replay on dashpay/dash 3ba0805c: Blame of src/clientversion.h 357 chunk queries to 16, History of src/validation.cpp 22 to 3, same answers.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
M1: Blame drops each version's text once compared and reads nothing ahead once every line has its commit. M2: the writer holds an index to the readers' row and inflate bounds, halving the per-path limit until it fits (still v2); the web decodes the lists section lazily, so the column never parses it and a malformed section costs only the lists.

L1/L2: a list is believed only where the path's entry at the page's start matches it, resumed pages included; a list naming an unreadable commit is dropped for the walk; Blame re-reads a version from the trees when the index's blob is not the file's text. L3: a delta supersedes a v1 index of its tip and the web ranks v2 first. L4: saturating arithmetic on member sizes. L5: the Rust overlay takes the delta's limit. L6: TS decoder refuses what forge-core refuses. L7: offsetIndexParts docs. L8: a due full index carries the delta as a fallback the cost guard can take instead. Blame takes an index list whole (listLimit), keeping 16 queries on dash.

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

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 47 minutes.

Check out review usage here.

View limit details

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

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b8292a61-080f-4b69-98e1-16d4e7f2e3a2

📥 Commits

Reviewing files that changed from the base of the PR and between 8fa3fa6 and e0d1661.

📒 Files selected for processing (30)
  • crates/dg/src/maint.rs
  • crates/forge-core/src/pack/historyindex.rs
  • crates/forge-core/src/pack/historytests.rs
  • crates/forge-core/src/repo.rs
  • crates/git-remote-dash/src/helper.rs
  • docs/contracts/data-contracts.md
  • docs/design/history-index.md
  • docs/design/last-change-index-v2.md
  • docs/economics.md
  • docs/guides/costs.md
  • docs/security/private-repos.md
  • forge-contracts/fixtures/history-index-v2-base.hex
  • forge-contracts/fixtures/history-index-v2-delta.hex
  • forge-contracts/fixtures/history-index-v2-tip.hex
  • forge-contracts/fixtures/history-index-v2.hex
  • forge-web/components/repo/blame-content.test.tsx
  • forge-web/components/repo/blame-content.tsx
  • forge-web/components/repo/commits-content.test.ts
  • forge-web/components/repo/commits-content.tsx
  • forge-web/e2e/history-index.spec.ts
  • forge-web/lib/browse/history-index.test.ts
  • forge-web/lib/browse/history-index.ts
  • forge-web/lib/repo/packs.ts
  • forge-web/lib/view/blame.ts
  • forge-web/lib/view/commit-log.ts
  • forge-web/lib/view/history-replay.test.ts
  • forge-web/lib/view/history-source.test.ts
  • forge-web/lib/view/history-source.ts
  • forge-web/lib/view/path-history.ts
  • forge-web/lib/view/path-versions-index.test.ts

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.

commits-content: master's URL paging, author-date labels and footer count (L-27, L-31, L-35) kept, on pathVersions with entry.author and the history-index marker.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PastaPastaPasta
PastaPastaPasta merged commit 6460643 into master Sep 29, 2026
34 of 36 checks passed
PastaPastaPasta added a commit that referenced this pull request Sep 29, 2026
PastaPastaPasta added a commit that referenced this pull request Sep 29, 2026
…x format lives in its header

#168 recorded a kind-3 index's format in packManifest.offsetIndexParts, which RC1 removes, so its writers would be refused on bonsia. The format now lives only in the artifact header's version byte: nothing writes offsetIndexParts, HistoryEntry/Artifact lose their format field, the planner treats every kind-3 manifest as an index with version lists (every RC1 writer writes version 2; no v1 index can exist on a network that started empty) and dg repo reindex drops its v1-upgrade note. The decoder refuses a header version other than 1 or 2 with an update-the-client error. history-index.md says so. The offline round trip now publishes main's history index as a push does, validates its manifest against RC1 and reads it back.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PastaPastaPasta added a commit that referenced this pull request Sep 29, 2026
RC1 drops packManifest.offsetIndexParts, where #168 carried the kind-3 format: PackManifest.historyFormat is gone, and history-source ranks a full index over a delta with every index read as v2 until the format comes from the artifact header (PR-5a's history-index split rewrites that reader).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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