Skip to content

refactor(rcache): make the index-file wire format public as IndexFile - #689

Merged
bryan-minimal merged 1 commit into
mainfrom
rcache/public-index-file-format
Jul 9, 2026
Merged

refactor(rcache): make the index-file wire format public as IndexFile#689
bryan-minimal merged 1 commit into
mainfrom
rcache/public-index-file-format

Conversation

@bryan-minimal

@bryan-minimal bryan-minimal commented Jul 9, 2026

Copy link
Copy Markdown
Member

Requested by @twitchyliquid64 on build-servers#153: build-bot now writes per-commit index.shisha snapshots and had to restate the 68-byte record layout by hand, because remote_index is a private module. That duplication is a silent-drift hazard — if this format ever changes, an out-of-tree writer keeps emitting the old bytes.

Export it, and name it for what it is (per Tom's steer: "probably with a better name, like wire or index file"). RemoteIndex named the in-memory map; what consumers need is the file.

  • remote_indexindex_file; RemoteIndexIndexFile
  • IndexEntrypub(crate): it appears in no public signature, so making the module public shouldn't leak it
  • module doc states the format as a contract — headerless array of 68-byte records (32-byte blake3 key, 4 zero flag bytes, 32-byte sha256), ascending spec_hash

The ordering guarantee is called out deliberately: because record order is a pure function of the keys, the same entry set always serializes to identical bytes. Callers that sign an index file (build-servers#86) depend on that, and it's the kind of property that's easy to break by accident once it isn't written down.

Consumers then get IndexFile::default() + Extend<(SpecHash, [u8; 32])> + write_to(), which is byte-identical to the hand-rolled writer it replaces.

No behaviour change — rename plus visibility only. Verified in-sandbox: cargo check -p rcache, cargo fmt --check -p rcache, cargo test -p rcache (11 passed).

I went with index_file/IndexFile over wire since the thing has one canonical on-disk home; happy to switch to wire if you prefer.

Summary by CodeRabbit

  • New Features

    • Added a clearer public index type for remote cache data, with updated API exposure and serialization support.
    • Improved documentation for the index format and forward-compatibility fields.
  • Bug Fixes

    • Updated remote cache read/write paths to use the new index type consistently, including empty-index handling and fetched index parsing.
    • Adjusted tests and fixtures to match the updated index behavior.

`index.shisha`'s wire format is a contract between everything that reads or
writes the remote cache index, but it lived in a private `remote_index`
module, so out-of-tree writers (build-bot, building per-commit index
snapshots) had to restate the record layout by hand.

Export it, and name it for what it is. `RemoteIndex` named the in-memory
map; the thing consumers actually need is the file:

- `remote_index` -> `index_file`, `RemoteIndex` -> `IndexFile`
- `IndexEntry` becomes `pub(crate)` — it appears in no public signature,
  so making the module public shouldn't leak it
- module doc states the format as a contract: a headerless array of
  68-byte records (32-byte blake3 key, 4 zero flag bytes, 32-byte sha256),
  ordered by ascending spec_hash

The ordering guarantee is load-bearing: it makes serialization a pure
function of the entry set, which callers that sign or digest an index file
depend on.

No behaviour change — rename plus visibility only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 83563452-05aa-416a-8123-6c23a562acda

📥 Commits

Reviewing files that changed from the base of the PR and between aee16ac and de841db.

📒 Files selected for processing (4)
  • crates/rcache/src/index_file.rs
  • crates/rcache/src/lib.rs
  • crates/rcache/src/remote.rs
  • crates/rcache/src/remote_writer.rs

📝 Walkthrough

Walkthrough

The rcache crate's RemoteIndex type is renamed to IndexFile, its module remote_index becomes index_file and is made public, IndexFile is publicly re-exported, IndexEntry visibility is narrowed to crate-private, and all usages in remote.rs and remote_writer.rs (including tests) are updated accordingly.

Changes

IndexFile Rename

Layer / File(s) Summary
IndexFile type definition and docs
crates/rcache/src/index_file.rs
Adds wire-format module docs, narrows IndexEntry to pub(crate), renames RemoteIndex struct to public IndexFile, updates the Extend impl target, and updates the from_reader test.
Module export wiring
crates/rcache/src/lib.rs
Changes mod remote_index to pub mod index_file and adds pub use index_file::IndexFile;.
RemoteCache index usage update
crates/rcache/src/remote.rs
Updates import, RemoteCache.index field type, local-index reuse path, 404/fetch parsing paths, and test fixtures to use IndexFile.
RemoteCacheWriter index usage update
crates/rcache/src/remote_writer.rs
Updates imports, fetched_index field, from_parts/merge_for_commit/fetch_gcs_index signatures, NOT_FOUND handling, deserialization, and all test fixtures to use IndexFile.

Estimated code review effort: 2 (Simple) | ~12 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RemoteCache
  participant GCS
  participant IndexFile

  RemoteCache->>GCS: fetch index object
  GCS-->>RemoteCache: 404 or bytes
  alt 404 Not Found
    RemoteCache->>IndexFile: IndexFile::default()
  else bytes returned
    RemoteCache->>IndexFile: IndexFile::from_reader(bytes)
  end
  IndexFile-->>RemoteCache: parsed index
Loading

Possibly related PRs

  • gominimal/minimal#643: Both PRs touch crates/rcache/src/remote.rs's remote-cache fetch/read path for retrieving and parsing the index bytes.

Suggested reviewers: twitchyliquid64

Poem

A hop, a skip, a renamed friend,
RemoteIndex's journey now must end!
IndexFile blooms in public light,
Docs and tests all set just right. 🐰
Through writer, reader, crate we bound —
One tidy name, new home found!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: exposing the rcache index wire format publicly as IndexFile.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@bryan-minimal
bryan-minimal enabled auto-merge (squash) July 9, 2026 19:59
@bryan-minimal
bryan-minimal merged commit 71b364b into main Jul 9, 2026
9 checks passed
@bryan-minimal
bryan-minimal deleted the rcache/public-index-file-format branch July 9, 2026 20:01
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