Skip to content

TR-1192: central lore adopts a repo a Job indexed, without indexing again - #6

Merged
ashish-bagri merged 3 commits into
mainfrom
factory/TR-1192
Nov 14, 2026
Merged

ashish-bagri merged 3 commits into
mainfrom
factory/TR-1192

Conversation

@adamglassflow

Copy link
Copy Markdown

Ticket: TR-1192 https://linear.app/glassflow/issue/TR-1192/lore-central-service-adopts-a-repo-a-job-indexed-without-indexing (depends on TR-1191, lore#5).

What changed

  • SyncReport gains adopted. A sync reports adopted: true when the source was already indexed (by lore index) but this process held no mirror or no checkout for it. It builds both and indexes nothing when the remote head is the indexed commit (up_to_date: true, files_indexed: 0, chunks and vectors untouched). When the remote is ahead it indexes only the changed files (full: false), builds the checkout and also reports adopted: true. A sync that ends as a full index is a reindex and reports adopted: false.
  • The up-to-date branch now rebuilds the checkout when the mirror OR the checkout was missing (before: only the checkout).
  • One info log per adoption (source id, commit, files indexed); no URL or token.
  • Deep answers need no change: grep / read_file already read <data_dir>/repos/<source id>/checkout, which adoption builds. A new test proves it.
  • Docs: docs/usage.md (response field, Job-then-central flow), docs/architecture.md.

Tests

  • cli_index::a_sync_adopts_what_a_job_indexed_and_indexes_nothing: Job indexes, central sync on an empty data dir: adopted, 0 files, mirror and checkout present, chunk rows and vectors identical, no new index_runs row; the second sync reports adopted: false.
  • cli_index::a_sync_of_a_remote_ahead_of_the_job_indexes_only_the_diff: modified, added and deleted file; only the diff is indexed, untouched rows unchanged.
  • adopt::a_deep_answer_reads_the_checkout_the_sync_adopted: scripted deep ask greps and reads the adopted checkout (a file added after the Job) and cites it.
  • sync tests: first sync and full reindex report adopted: false; lost data dir, lost checkout and lost mirror with a damaged checkout report adopted: true.
  • Run on 1e97d7c: cargo fmt --check clean; cargo clippy --all-targets -- -D warnings clean; cargo test --all-targets --no-fail-fast: 35 binaries, 694 passed, 0 failed, 4 ignored (fresh pgvector).
  • Mutations (each fails a test, then restored): adopted forced false; adopted ignoring full; up-to-date branch skipping the checkout rebuild; rebuild only when the checkout is missing; incremental path indexing the whole tree; index_commit skipping the checkout.

Notes

  • adopted also fires for a partial data-volume loss (only mirror or only checkout missing); the checkout is rebuilt either way.
  • The adoption path does not set the local lore-indexed ref; nothing reads it there.
  • Out of scope: decision documents (TR-1208). Follow-ups TR-1313 untouched.

@adamglassflow

Copy link
Copy Markdown
Author

factory/review: CHANGES, head 1e97d7c

The adoption itself is right. Deciding "held" before ensure_mirror creates anything is the right place for the check, and the remote-ahead path correctly reuses the incremental diff. One blocking gap remains: a Job that indexes a repo the server already holds leaves the server's checkout stale.

What I verified (in a worktree at 1e97d7c, local pgvector/pgvector:pg17)

  • cargo fmt --check: clean.
  • cargo clippy --all-targets -- -D warnings: no warnings.
  • cargo test --no-fail-fast: 36 binaries (doctests included), 694 passed, 0 failed, 4 ignored, exit 0.
  • I made 5 mutations on the adoption logic in sync.rs, and the tests caught all 5. For each one I broke the code, ran --test cli_index --test adopt --test sync, and restored the code.
    • With adopted forced false in the remote-ahead path, the adopt and remote-ahead tests fail.
    • With adopted = unheld (ignoring full), a_lost_mirror_and_rewritten_history_fall_back_to_a_full_index fails.
    • With unheld ignoring the mirror, sync_indexes_the_remote_then_only_what_changed fails.
    • With unheld ignoring the checkout, the same test fails.
    • With the refresh run only on a missing checkout, the same test fails.
  • The DoD test a_deep_answer_reads_the_checkout_the_sync_adopted runs grep and read_file on the adopted checkout.
  • Probes. I ran two of my own: a scratch test, deleted afterwards, and a git experiment. The results are under F1 and F2.

Findings

  • F1, P2, blocking (src/repo/sync.rs:508): the up-to-date branch rebuilds the checkout only when the mirror or the checkout is missing. It does not rebuild one that sits at an older commit.
    • Probe:
      1. A Job indexes A, and a server sync adopts it.
      2. The remote moves to B, and a Job indexes B.
      3. A server sync answers {up_to_date: true, adopted: false}, but checkout/README.md still has A's text.
    • The index is at B, but grep and read_file read A. They keep doing so until a server sync, not a Job, indexes a later commit.
    • When Jobs do the indexing and the server only syncs afterwards (the Job always gets to the new head first), this happens on every re-index. So "from then on grep and read_file in deep answers work on that repo" (usage.md) is not true after the first one.
    • Fix: record which commit the checkout is at, written only after refresh_checkout succeeds. For example, update-ref refs/lore/checkout <commit> in the mirror. In the up-to-date branch, refresh when that ref is missing or differs from head.
    • Don't compare with refs/heads/lore-indexed. index_commit sets it before refresh_checkout (src/repo/mod.rs:421), so a failed refresh would leave it at B while the checkout is at A.
    • Please add the probe as a test: the server holds A, a Job indexes B, then a sync.
  • F2, P3 (sync.rs:505-530): you flagged this one. An up-to-date adoption leaves the new mirror with no ref, because fetch_remote stores only FETCH_HEAD.
    • I checked with git: with no ref, the first fetch after the remote moves sends no haves and downloads the whole history again. The objects grew from 896K to 1728K on a copy of this repo; with the ref, they grew to 896K only.
    • It happens once per adopted repo, because index_commit then sets the ref. It doesn't lead to a full reindex, since that full fetch brings the old commit back for merge-base.
    • Fix: update-ref refs/heads/lore-indexed <head> in the up-to-date branch. It fits with the F1 fix.
  • F3, P3, pre-existing (src/repo/mod.rs:613): refresh_checkout creates the checkout dir before read-tree. A failed read-tree (a full disk, say) leaves a dir that the next sync counts as "held", so the checkout is never rebuilt while the remote stays put. The F1 marker fixes this too, because the ref is written only after success.
  • F4, P3, nit (docs/usage.md:170): adopted: true is reported only by the first attempt. If the remote-ahead index fails after refresh_checkout created the dirs, the retry reports adopted: false. Accept it or reword the doc; either is fine.
  • Accepted, not a finding: adopted is also true when only the mirror or only the checkout is lost. That matches the doc wording "no mirror or no checkout".

Not covered

  • Nothing ran against a real https remote or GitHub. I used file remotes only. The F2 probe used file://, which negotiates the same way.
  • I did not check lore index against a server on a shared volume. That is out of scope, as the docs say.
  • CI check is green on 1e97d7c (from the ticket). I did not rerun it.
  • Challenge: a Sonnet read of the diff and my draft. It agreed F1 is reachable and argued for P2 non-blocking. I keep it blocking because the Job-then-sync flow hits it on every re-index, and the docs promise working deep answers. It also:
    • showed that my first fix idea (lore-indexed) was wrong (now in F1);
    • raised F3 and F4;
    • confirmed F2.
      I rejected its claim that F2 can cause a full reindex after a gc: the no-haves fetch brings the history back.

…1192 review round 1)

A sync that finds the index already at the remote's head used to keep an existing
checkout as it was. After a Job indexed a newer commit, the checkout was stale.

- The mirror keeps `refs/lore/checkout` at the commit the checkout is at. It is
  dropped before a rebuild and written only after read-tree and clean succeed, so a
  missing or different ref means the checkout is rebuilt (F1, F3).
- The up-to-date branch also sets `refs/heads/lore-indexed` so the next fetch
  negotiates instead of downloading all history again (F2).
- docs: adoption wording covers the marker and the rebuild (F4).

Tests: a_sync_rebuilds_a_checkout_that_a_job_left_behind and
a_sync_rebuilds_a_checkout_whose_rebuild_never_finished.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ashish-bagri

Copy link
Copy Markdown
Member

factory/review: pass (round 2) at aa7841c

Reviewer: ashish-crew-reviewer

Round 1 findings

  • F1 (stale checkout after a Job re-indexes a held repo): fixed. refs/lore/checkout is written only after read-tree and clean succeed, and the up-to-date branch rebuilds when it differs from head.
  • F2 (no mirror ref after up-to-date adoption): fixed. The up-to-date branch now sets refs/heads/lore-indexed.
  • F3 (half-built checkout counted as held): fixed.
  • F4 (adopted on retry): fixed. The docs now say so.

Verified

Clean env through tares factory heavy: rust:1.95-trixie, my own pgvector/pg17 container and target volume.

  • cargo fmt --all -- --check: exit 0.
  • cargo clippy --all-targets -- -D warnings: clean.
  • cargo test --all-targets --no-fail-fast: 35 binaries, 694 passed, 2 failed, 4 ignored. The 2 failures are tests/cli_search.rs:83 and :209, which assert that stderr is empty, and onnxruntime prints a cpuid warning on arm64 Docker. That is environmental, and the file is untouched here.
  • The PR's CI on this head (x86) passed.

Mutations:

  • M1: drop the checkout_commit clause in the up-to-date branch. Both new tests fail.
  • M3: drop the lore-indexed update. a_sync_rebuilds_a_checkout_that_a_job_left_behind fails.
  • M2: refresh_checkout no longer deletes the ref first. It survives (see F6).

Probe: report["adopted"] in the left-behind test is false (see F5).

A second-model challenger (read-only) agreed F1-F3 are fixed and found no new defect in the delta.

Findings (none blocking)

  • F5 P3 docs/usage.md:170: the docs say a rebuild after a later Job reports adopted: true, but the code reports adopted: unheld (src/repo/sync.rs:540), which is false there. The probe confirms it. Fix the sentence, and assert adopted in the test. The rebuild also logs nothing, since the log line is gated on unheld.
  • F6 P3 src/repo/mod.rs:623: the "dropped before the work" half of the marker has no test, so mutation M2 passes every test. A test that makes read-tree fail after an earlier good checkout would cover it.

Not verified

  • The full suite on x86 myself (I relied on CI).
  • A real Kubernetes Job run.
  • A real interrupted read-tree.
  • Deep-answer reads during a rebuild (pre-existing).

@ashish-bagri
ashish-bagri merged commit a9fd41b into main Nov 14, 2026
2 checks passed
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