Skip to content

Index passes write onto the newest record and never drop each other's entries - #984

Merged
coderhelm[bot] merged 6 commits into
mainfrom
fix/contract-index-versioned-writes
Dec 5, 2026
Merged

coderhelm[bot] merged 6 commits into
mainfrom
fix/contract-index-versioned-writes

Conversation

@nambok

@nambok nambok commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two index passes on the same repository could overlap: each read the stored contract record, replaced its own files' entries, and wrote the whole record back unconditioned, so the later write silently dropped the earlier pass's entries. Every write of a repository's record is now conditioned on its version. A pass that loses the race reads the newer record, merges its own files onto it, and tries again, a bounded number of times, so neither pass's entries are lost. Follow-up to #979.

Changes

  • common::contracts:
    • Each repository's record carries a version v.
    • write_pass writes a Pass (the files it read, their fresh entries and, for a full pass, its tree) onto the newest stored record, conditioned on that version, over a RecordStore (DynamoRecords in production).
    • After WRITE_TRIES (5) lost races it returns Wrote::Conflict. Nothing is written in that case, and the other pass's record stays intact.
    • A full pass drops only the entries of files no longer in its tree.
    • The unconditioned save_record is gone.
  • common::app_map: the versioned-write loop the map's build status already used is now one shared, generic loop (write_versioned). The status update calls it and behaves as before.
  • worker::passes::code_graph:
    • refresh_contracts and the contracts-only pass write through write_pass.
    • A conflict that outlasts the retries logs a warning and leaves the stored record as it is.
  • Incident xt (case and page): source checks that every pass writes through the versioned path and warns on a conflict, and that no unconditioned write is left.

Verification

  • cargo fmt --all --check and rustfmt --check on the incidents: clean.
  • cargo clippy -p common -p worker -p gateway --all-targets -- -D warnings: clean.
  • Full cargo test -p common -p worker -p gateway: common 3,345 passed, gateway 1,363 passed, worker 2,967 passed, none failed.
  • New tests:
    • interleaved_passes_keep_both_passes_entries: another pass writes between this pass's read and its write. The write is retried, and the stored record holds the base entries and both passes' entries at the next version. A later full pass drops only the files missing from its tree.
    • a_conflict_past_the_tries_leaves_the_stored_record_intact: every write loses. The result is Conflict, and the stored record and its version are unchanged.
  • brand_spelling.py and domain_examples.py: clean.

… entries

Each repository's record carries a version, and every write is
conditioned on it. A pass that loses the race to another reads the newer
record, merges its own files onto it and tries again, at most a few
times (contracts::write_pass, over the versioned-write loop the app map's
status already uses, now shared). A pass that keeps losing writes
nothing, leaves the other pass's record intact and logs a warning.
@nambok nambok added the ch-review CoderHelm reviews this pull request label Dec 5, 2026
coderhelm[bot]

This comment was marked as outdated.

…rote

Each file's entries in a repository's record carry the time of the
commit they were read from, and so does a file a pass found gone. A pass
merges file by file in that order: it replaces or removes a file's
entries only when they came from a commit no newer than its own, and the
record's commit moves only forward. A full pass that read an older tree
and overlaps a push from a newer one keeps the push's new and rewritten
files.
coderhelm[bot]

This comment was marked as outdated.

@coderhelm
coderhelm Bot dismissed their stale review December 5, 2026 12:29

Superseded by CoderHelm's latest review

…commit times

A pass writes only at the branch's current head. Before each write it
reads the head again; a pass whose commit isn't it never writes its
view, but reads the files that changed between the two, either way, and
writes at the head, whether the branch moved forward or was reset back.
A comparison too large to tell queues a full read instead. The version
condition still guards writers at the same head. Each file's entries
record the head they were read at, and only files with entries are
kept, within the record's bound. Turning the graph off empties the
record with no commit, so the first read once it is on again writes
every file. Commit times are no longer used.
coderhelm[bot]

This comment was marked as outdated.

@coderhelm
coderhelm Bot dismissed their stale review December 5, 2026 13:06

Superseded by CoderHelm's latest review

What changed between a pass's commit and the head is read from GitHub's
comparison, both ways. A file renamed or copied names the path it came
from as well (previous_filename), so a rename is its old path removed
and its new one added, and no entries stay under the old path. A
comparison that may be cut still queues a full read.
coderhelm[bot]

This comment was marked as outdated.

@coderhelm
coderhelm Bot dismissed their stale review December 5, 2026 13:38

Superseded by CoderHelm's latest review

@coderhelm

coderhelm Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

💚 Post-merge health check passed: the deploy of 36e1ab9 completed and stayed green for the full 15-minute watch window (no new failures vs. the pre-merge baseline).
Auto-merge

  • ✅ CoderHelm approved
  • ✅ CI green
    The rest is in the pull request description.

@coderhelm coderhelm 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.

✅ Approved 828188c (merged)

@coderhelm
coderhelm Bot merged commit 36e1ab9 into main Dec 5, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ch-review CoderHelm reviews this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant