Repository navigation
The recovery worker republishes counts and coverage when it drains a namespace - #1563
KaloyanNaumov wants to merge 7 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
zlareb1
left a comment
There was a problem hiding this comment.
P2 — A failed final coverage write can leave the saved coverage stale indefinitely. The pass publishes complete table_counts first, then refresh_coverage can swallow a failed write. The next idle pass sees complete counts and skips the coverage refresh. Retry until both rows reflect the completed embeddings, and test a failed coverage write followed by an idle pass. Existing coverage retry thread
With nothing pending, the embed phase declared its org and republished whenever a `table_counts` row existed. Readers write that row: `loom code stats` with a mistyped --org leaves a row of zeros, so the same typo on `--phase embed` declared the org, and every idle embed run on an indexed namespace paid the org gate, the count scans and the coverage aggregates. It now declares only when rows are pending or the published chunk counts differ from the chunk table. That comparison is a store read, `CodeRepo.published_chunks_behind`, over the shared counts and the chunk aggregate. The index phase writes `git_head` and the backfill stamps first, then `_close_index` compacts, records the pass and republishes last on every exit (a full run, a run resumed at the end of its cursor, a hold, a repair, a twin label), so the `republish` flag is gone. The cursor is cleared after the republish, so a run interrupted while it publishes resumes at the end and publishes then. The republish writes the coverage row first and the counts row only once the coverage has landed. An embed phase stopped between the two, by Ctrl-C or a failed coverage refresh, otherwise left the counts current and the coverage at the pre-embed vectors with a matching fingerprint, and the rerun found nothing behind. It also reads with sequential consistency: the fingerprint it stamps carries the `git_head` the run has just written, which the replica serving the read may not have yet. The tests drive `_backfill` and `_backfill_embed` against the real `CodeRepo` over a replica that lags the run's writes, and read the rows back. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
ed05a89 to
feb7a8d
Compare
|
Rebuilt rather than patched: the head is now one commit in |
zlareb1
left a comment
There was a problem hiding this comment.
P2 — A restart or worker handoff after embedding the last stub loses the pending counts and coverage refresh. I verified the current pass only republishes entries in its process-local set, and the replacement worker finds no live stub to put the namespace back in that set. Persist the refresh obligation or derive it from shared state. Cover a restart between the final vector write and the refresh. Existing restart finding
zlareb1
left a comment
There was a problem hiding this comment.
The restart regression passes when both saved rows are old. A mixed-version handoff can still leave coverage stale when the saved counts are current.
|
Thanks for the review. Converting to draft while I address it; a new head and the replies will follow, so no need to look at this head again. |
The CLI writes the counts row only once the coverage row has landed, but `refresh_coverage` swallowed its own write failure, so the counts landed anyway and the next embed phase found nothing behind. The CLI now passes `must_land=True`, which makes the coverage write raise. `published_chunks_behind` also reads the coverage row's embedded figure, so current counts over a coverage row that trails the chunks still count as behind. That state comes from vectors landing between the two writes, or from an earlier build that published counts after a failed coverage write. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
349b762 to
50e4d4f
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
Reviewed by Cursor Bugbot for commit 50e4d4f. Configure here.
zlareb1
left a comment
There was a problem hiding this comment.
The full scan now records lag before an idle pass, and the comparison covers stale coverage beside current counts. It still needs to check coverage when a counts row is missing.
zlareb1
left a comment
There was a problem hiding this comment.
The earlier SCIM integration run failed while flushing TraceLogElement. The same test failed on main with ClickHouse error 159. The repair flushes query_log directly and preserves the query-work assertions. Earlier job · Main job · Repair #1495
|
Thanks, I've seen the new comments. Back to draft while I address them; a new head and the replies will follow. |
When the index phase published coverage and its first counts write failed, an embed phase that landed its last vectors and stopped before publishing left an idle rerun reading a missing counts row as nothing to republish. published_chunks_behind now compares the coverage row on its own. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…namespace `code_embed_recovery` stores vectors without moving a watermark, and only an ingest pass that indexed a commit republishes the shared `table_counts` and `coverage` rows. A namespace whose stubs recovery filled kept its pre-embed figures, read `searchable: false`, and was searched lexical-only until a commit landed. The worker now notes each namespace it wrote chunk vectors to, and its first idle pass, the scan finding nothing left, republishes both rows for each of them with `refresh_coverage` and `refresh_table_counts`. A failed republish keeps the namespace noted, so the next idle pass retries it: the two refreshes take `must_land`, which raises a failed state write instead of dropping it. A namespace the pass did not scan, removed or switched off, waits, so a removed one is never written after its purge. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The namespaces whose chunks code_embed_recovery embedded are noted in process memory, so a restart between the last vectors and the next idle pass lost the note, and the namespace kept its pre-embed counts and coverage rows until a commit landed. A full-scan idle pass (the first after boot, then every code_embed_recovery_full_scan_seconds) now compares each configured namespace's published embedded chunk count with one aggregate of its live chunks, and notes the namespace when they differ. The in-memory note stays the fast path; the check is what guarantees the republish, at one point read and one aggregate per namespace per full-scan period. No state row is added: the published table_counts row already carries the figure, and nothing cheaper records that vectors landed (the counts fingerprint covers watermarks only). `shared_counts`, the read of that row, becomes public for the worker. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The full-scan check compared only the published counts with the chunks, so a coverage row that trailed under current counts was never noted. That is the state a handoff leaves when the previous build's vectors land between its coverage write and its counts write. The check now calls `published_chunks_behind`, which reads both rows, and `shared_counts` goes back to private. It also ran only on an idle pass. The first full scan after a restart reads superseded stub versions from zero and is rarely idle, and the idle passes after it are not full scans, so the check never ran. It now runs on every full-scan pass, and the next idle pass republishes what it noted. The read is guarded per namespace like the republish: a failed read is a pass error, and the next full scan reads that namespace again. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…uential consistency A lagging replica could make a current counts or coverage row read as behind, and let the republish overwrite it with older figures; the CLI's republish already reads sequentially. The worker's comparison and its republish now do too. A namespace with only a coverage row published, its counts write having failed, is compared and republished after a restart. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
50e4d4f to
154f7f7
Compare
zlareb1
left a comment
There was a problem hiding this comment.
The restart and missing-counts regressions pass. A drained namespace can still stay unsearchable while another namespace has recovery work.
| result.summaries_embedded += embedded | ||
| if result.full_scan: | ||
| await _note_behind(repo, set(repos) - _unpublished, result) | ||
| if result.idle: |
There was a problem hiding this comment.
P2 — A namespace whose chunks have all been embedded still waits for the entire worker to be idle. In a focused test, three vectors landed for one namespace, then three passes found only summary work for a second namespace. The first namespace still published zero embedded chunks and zero coverage. Publish drained namespaces independently of other namespaces' backlog, and test that case.

Closes: #1556
Related: #1538, #1550
TL;DR: A namespace whose stubs
code_embed_recoveryembedded kept reporting its pre-embed coverage andsearchable: falseuntil a commit landed, so search skipped its vectors. The worker now republishes the counts and coverage rows of every namespace it wrote vectors to on its first pass that finds nothing left to embed, retries on the next idle pass if a republish fails, and on each full-scan pass, idle or not, notes any namespace whose published counts or coverage trail its chunks for the next idle pass, so a restart before the drain loses nothing. With #1550, merged, which does the same forloom code backfill, both writers #1556 names publish what they write.Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
A namespace embedded by
code_embed_recoveryreports its embedding coverage, and is searched with vectors, once recovery has no chunks left to embed, even when its branch has no new commit.Why
ingest_pass._post_stepsrepublishes the sharedtable_countsandcoveragerows only insideif plan.commits:. Two writers store vectors outside that path: the CLI embed phase andcode_embed_recovery. Neither moves a watermark, and a reader serves the shared row whatever its fingerprint. A namespace whose branch head did not move therefore kept its pre-embedchunks_embeddedandembedding_coverage, readsearchable: false, andcode.searchskipped its vector leg. On our deployment a fork of vllm-xpu-kernels with 6,868 of 6,868 chunks embedded reported 0 after a clean pass that indexed no commit.PR #1550, now on
main, makes each CLI backfill phase republish at its end. This PR does the same for the recovery worker:_embed_rowsnotes each (org, namespace) whose chunk vectors it inserted._republishcallsrefresh_coverageand thenrefresh_table_countsfor each noted namespace that the pass scanned, the same two refreshes the ingest pass runs after a commit.must_land=True, so a failed state write raises instead of being dropped. A namespace whose republish raised stays noted, and the next idle pass retries both rows. The failure is a warning line and an entry in the pass's errors; the pass does not fail.code.repo.remove, or its org switched off) waits. A removed one is never written after its purge, and a switched-off one is republished once its org is back on.code_embed_recovery_full_scan_seconds), idle or not, callspublished_chunks_behindfrom The CLI embed phase republishes only when behind, once, with coverage first #1581 for each configured namespace and notes it when either published row trails the chunks. That read compares the counts row and the coverage row's embedded figure with one chunk aggregate, so current counts over a stale coverage row (the previous build's vectors landing between its two writes) are caught too. It runs on non-idle full scans because the first one after a restart reads superseded stub versions from zero and is seldom idle. The set is the fast path; this check is what guarantees "retry until both rows reflect the completed embeddings" across a restart. It needs no new state row: the published rows already carry the figures, and nothing cheaper records that vectors landed (the counts fingerprint covers watermarks only). The comparison and the republish read undersequential_reads(), as the CLI's republish does, so a lagging replica neither makes a current row read as behind nor lets the worker overwrite a current row with older figures. A namespace with only a coverage row published (its counts write failed) is compared and republished too. A failed read is a warning and a pass error, like a failed republish, and the next full scan reads that namespace again."Drained" is recovery's own predicate, so poisoned rows, rows under another model label and reference fixtures never hold it open.
Changed from the earlier approach
The earlier head of this PR had every ingest pass with no commit check the chunk figures itself: a
chunk_countsstate row laid overtable_counts, a fingerprint gate, a short-circuit once the published pending count reached 0, and a fourth copy of the pending-stub predicate. Review showed two problems with one root. A published pending count of 0 is only a snapshot, but the short-circuit treated it as permanent, so stubs added later at the same fingerprint were never recounted and the bootstrap ready check could flip on stale figures. A same-fingerprint republish from #1550 landing inside a pass also broke "converges next pass". The bug is two writers that do not publish what they write, so this head makes the remaining writer publish, in about 30 lines of the worker, with no new state row and nothing added to the ingest pass.Dependency
Depends on #1581 and is stacked on it: it uses
must_landonrefresh_coverageandpublished_chunks_behindfrom there. Review this PR's own two commits on top; it merges after #1581.Scope and risk
server/code/workers/embed_recovery.py(_republishand the noted set),server/code/store/index/status.py(must_landonrefresh_table_counts, default off, so every existing caller is unchanged),docs/features/code-index/freshness.md. The CLI embed phase reuses_embed_rows, so it notes namespaces in its own process too; it never runs an idle pass, and it republishes at its end itself.Cost: one full republish (the coverage aggregates and the seven count scans) per namespace per drain, nothing on a pass that embeds and nothing on an idle pass with no namespace noted, plus two point reads and one chunk aggregate per configured namespace per
LOOM_CODE_EMBED_RECOVERY_FULL_SCAN_SECONDS(30 min by default). A coverage computation that keeps failing is retried once per idle pass (code_embed_recovery_idle_interval_seconds, 120 s) with an error line, until it succeeds or a commit pass republishes.Not covered:
embeddingstage of a self-service entry still reads live coverage on every pass.code_embed_recovery_enableddefaults to false, so a deployment that leaves recovery off relies on CLI backfill phases republish the namespace's counts and coverage #1550 and on commit passes.Compatibility, rollout and rollback
How this was found
Found and reproduced on our deployment with AI assistance. Fixed on a fork, PR submitted.
Tests
tests/unit/test_code_embed_recovery_republishes.py(new, 9 tests, 11 cases). The fake holds the state rows by key and the chunk table as rows; the realrefresh_coverageandrefresh_table_countsrun against it, the worker'srun_passembeds through it, and each test reads the rows back:test_a_drained_namespace_publishes_the_counts_and_coverage_of_its_table: 2 of 5 chunks embedded and published. After one pass that embeds 3 and one idle pass,table_countsreads 5 of 5 and the coverage row 5 embedded, as the table does. A further idle pass writes nothing.test_a_failed_republish_is_retried_on_the_next_idle_pass, parametrised over a failed coverage write, a failed counts write and a failed counts aggregate: the idle pass records one error line and the counts stay at 0; the next idle pass republishes both rows at 3 of 3.test_a_namespace_removed_before_the_drain_is_not_republished.test_a_restart_before_the_drain_still_republishes_on_the_full_scan_pass: the last vectors land, the noted set, watermark and full-scan clock are dropped as a restart drops them, and the next pass (the boot's full scan, idle) republishes both rows at 3 of 3; a further full-scan pass over matching rows writes nothing. Without the full-scan check it fails (0 == 3).test_current_counts_over_a_coverage_row_behind_are_republished_after_a_restart: coverage published, the previous build's vectors land, counts published; after a restart the idle full scan republishes the coverage at 3. Without reading the coverage row it fails (3 == 0).test_a_coverage_row_alone_behind_the_chunks_is_republished_after_a_restart: only the coverage row is published (counts removed), the last vectors land, and after a restart the full scan republishes both rows at 3. It fails without the coverage comparison on a missing counts row (KeyErrorreading the counts row back).test_the_comparison_and_the_republish_read_with_sequential_consistency: spies onpublished_chunks_behind,refresh_coverageandrefresh_table_countsduring a restart pass and asserts each runs undersequential_reads(). It fails without the wrapper.test_a_full_scan_that_meets_unmerged_stub_versions_still_notes_the_namespace: after a restart the full scan meets one superseded stub version and is not idle; the next pass, idle and not a full scan, republishes both rows. With the check gated on idle it fails (0 == 3).test_a_failed_comparison_does_not_fail_the_pass: the chunk aggregate fails during the full-scan check; the pass records one error and the next full scan republishes. Without the guard the pass raisesTimeoutError.main, the first test fails (2 == 5) and the three retry cases fail (no error line, nothing republished); the removed-namespace test passes there, as nothing republishes. On this head all 6 pass.tests/unit/test_workers_poll_the_work.py: the recovery fake answers the two refreshes andpublished_chunks_behind, the fixture resets the noted set, and the idle-pass test checks that a full-scan pass checks each namespace once and writes nothing when the rows match.tests/unit/test_model_calls_switch_workers.py: the full scan's check reads only the namespace of the org left on.test_cli_backfill_publishes_counts.pyandtest_cli_embed_phase_live_stubs.py(the CLI embed phase shares_embed_rows), plustest_exception_text_ratchet.py,test_public_copy.pyandtest_tunable_constants.py, and every unit test that names the recovery worker or the counts rows: 378 passed on the previous head; on this head the recovery, poll, model-call switch and CLI counts files: 97 passed.ruff check,ruff format --checkandmypyon the changed server modules and the new test pass;scripts/gates/function_length_gate.pyholds its baseline. CI runs the full unit suite.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code wrote the diff and the tests. Checked: I reviewed the whole diff and its tests; the gate runs listed under Tests are the agent's, against this head.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.Note
Medium Risk
Changes shared index status publishing and embed-recovery idle/full-scan behavior; mistakes could leave stale embedding coverage or overwrite fresher cache rows, though sequential reads and must_land mitigate replica races.
Overview
Fixes namespaces that stayed at pre-embed
chunks_embedded/searchable: falsewhen vectors were written only bycode_embed_recoveryorloom code backfill --phase embed, because ingest republishestable_countsandcoverageonly after indexing a commit.code_embed_recoverytracks namespaces it embedded, republishes both rows on the first idle pass after draining stubs (with retry on failure), and on periodic full scans uses newpublished_chunks_behindto queue namespaces whose published figures trail the chunk table—covering restarts and split coverage/counts writes.CLI backfill always republishes at phase end (coverage first with
must_land, then counts) undersequential_reads; full index runs advancegit_headbefore publish and keep the cursor until counts land. The embed phase declares the org when there is pending work or published counts are behind.StatusMixinaddspublished_chunks_behind,must_landon refresh helpers, and docs/tests for interruption, replica lag, and repair/twin runs that leave watermarks unchanged.Reviewed by Cursor Bugbot for commit 154f7f7. Bugbot is set up for automated code reviews on this repo. Configure here.