Skip to content

Skip a SCIP document that fails to decode or convert; its file keeps its rows, marked stale - #1704

Open
KaloyanNaumov wants to merge 44 commits into
ClickHouse:mainfrom
KaloyanNaumov:pr/scip-skip-bad-document
Open

KaloyanNaumov wants to merge 44 commits into
ClickHouse:mainfrom
KaloyanNaumov:pr/scip-skip-bad-document

Conversation

@KaloyanNaumov

@KaloyanNaumov KaloyanNaumov commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #1701

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

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 compiler-tier pass no longer fails on one SCIP document that cannot be decoded or converted, such as one with a string that is not UTF-8: the document is skipped and logged, the rest of the index is applied, and the file keeps its compiler rows, marked stale. LOOM_CODE_SCIP_STOP_ON_FAILED_DOCUMENT=true fails the pass on such a document instead.

Why

_stream_documents parses each document with ParseFromString, and nothing caught a failure, so one bad document ended the run. The tier wrote no delta and kept its watermark, and the next pass indexed the same tree and hit the same document. scip-typescript can write a string field that is not UTF-8, which python-protobuf refuses (DecodeError: String field had bad UTF-8). One file that cannot be processed should not fail the whole repository's pass.

Every tier converts through convert_delta in lib.sh and runs its harness through compiler_tier.run_harness, so each change below covers C++ and its full run, Python, TypeScript and Go alike.

  1. The converter skips a document whose parse or conversion raises, whatever the exception. All its passes over the index read through _stream_documents; _ctor_overloads now does too, instead of parsing records itself. The skipped documents are kept per run (_Skips, created by each DeltaStream), not in module state.
  2. Each skipped document is named once on stderr. The delta counts them in stats.skipped_failed and the summary line, and lists in skipped_files those among the files it converts (the window's, or every file in a full run). A failing document outside the window is warned about and counted, but not listed, so no later delta marks it again. A document whose path cannot be read (a path that is not UTF-8 among them) is counted by its place in the index, so two of them are two. In a run over every document (the TypeScript and Python full runs, which name no files), such a document fails the run before anything is applied: the worker retires the live files a full delta does not name, and this one's file would be among them.
  3. The server never treats a skipped document as gone. gone_documents leaves the skipped paths out, so a full TypeScript or Python run keeps their rows, as a window does.
  4. The file is marked stale. Each worker passes its tier to apply_delta (an upload's is the tier whose watermark its producer moves). The apply writes one code_index_state row per skipped file, scip_stale:<tier>:<path> holding the delta's commit, and empties the row of each file of that tier this delta applied or deleted. All of these go in one insert per apply. The mark is filed under the applying tier, so a path no tier's suffixes name (a .cu file in a C++ index) is marked under the tier that skipped it. A tier reads and writes only its own marks, so two tiers applying side by side keep both. A file both converted and skipped (two documents of one path, one of them failing) is not applied: its rows stay as they are, marked stale, since the converted document alone would drop what the failed one defined. A path in deleted_files that is also skipped is not deleted either, as in the full run. A skipped path the entry's scope or path denylist refuses is never marked, since no delta would clear it. scip_stale_paths, which already decides scip_stale_files for code.callers and code.callees, reads the marks of the asked paths by key (each path under each tier) and treats a marked file as stale. Before, a moved watermark made those rows read as current. The whole-namespace state reads (all_state, all_state_many, behind the as-of block, code.index_status and code.repos) leave these rows out. A mark counts on every read while it is set (_marks_in_force, which scip_stale_paths and scip_stale_marks share). This build empties it when it applies the file, after every round of that apply has landed, or, for an entry whose tier this build's worker runs, when a pass of that worker finds a later apply of the file published (retire_published_marks): the tier's watermark holds another blob of the file than the mark's commit in the entry's mirror. A Python, TypeScript or C++ worker moves its watermark only after a whole apply of the window, and the previous build fails a run on a document it cannot read, so that watermark is a completed apply whichever build wrote it, whether or not the apply rewrote a row of the file (a change to a function body alone rewrites none). An upload batch whose apply fails leaves the watermark to a later batch that does not apply its files, so the pass keeps every mark older than the namespace's newest failed code_scip_apply batch (scip_marks_retirable); batch records expire after 30 days. The Go worker passes a module it could not fetch without a retry, so a Go mark also needs a compiler-tier row of the file written after it. A namespace fed by uploads alone, applied by code_scip_apply, has no mirror to check and keeps the mark until this build applies the file.
  5. run_harness logs the first five warning lines and the count. Before, only the exit code was read on success, so no tier logged them.
  6. One switch: code_scip_stop_on_failed_document (default false). run_harness passes it to the harness as SCIP_STOP_ON_FAILED_DOCUMENT, and convert_delta adds --stop-on-failed-document, which re-raises the first failure, as main does.
  7. The boundary: _top_level_records raises when a record's length runs past the end of the data. Before, the slice came back short and the parse of that last document failed, so a truncated index failed by accident; with per-document skipping it would have converted. _document_path returns "" for a payload it cannot read, and for a path that is not UTF-8, which it no longer decodes with replacement characters into a name no file has.
  8. The Go harness converts each module in an xargs job, whose convert_delta … | tail -1 took tail's status, so a failed conversion dropped the module and the watermark moved. run_module sets pipefail and returns 1 on a failed conversion. With the switch on, the Go run now fails like the others. With it off, a conversion that fails as a whole (a truncated index, a crash outside the per-document skip, a killed converter) now fails the Go pass and keeps the watermark, where before it dropped the module.
  9. A delta that lists a skipped file is delta_version 2; one that lists none stays 1. The converter writes the version last, since a document that fails to convert is known only once the files are written. code_scip_apply applies both. A build without this change applies version 1 only and ignores skipped_files, so it refuses such an upload instead of applying it without the marks.
  10. A full C++ conversion that skipped a document, in the window or anywhere in the constructor scan, makes no ctor_calls claim (DeltaStream.tail needs _Run.ctors_complete as well as an empty skipped_files, which holds the window's files only; the harness's --full run always passes a window): the skipped file may hold the only factory call, and with the claim set and no edge for it, code.callers would read the empty answer as exact. A claim an earlier clean full run already made is withdrawn on read: while any compiler-tier file is marked stale, _ctor_edge_coverage counts the compiler tier as not carrying constructor calls, so an empty constructor answer from code.callers, code.callees or code.verify stays a lower_bound with ctor_edges_absent. That lifts once this build converts the file; the claim itself comes back with the next full run that skips none. The probe caches the scip_ctor_calls bit an hour per namespace, but reads the marks on every call while the bit is set, so a new mark or its retirement shows on the next answer. That read is one query per empty constructor answer, over the tier's scip_stale: keys in code_index_state only.
  11. The constructor scan (_ctor_overloads) reads every document, the window's and the rest. When it skips one, that document may declare a type's only constructor, or one more overload of a type the scan found, so a factory call converted without it would lose its edge and the apply would retire the edge the file had. A document with a factory call is then skipped as well (_OverloadsIncomplete): it is listed in skipped_files when the delta converts it, so it keeps its rows and is marked stale. Documents without a factory call convert as before.
  12. code.callers and code.callees read staleness for the paths of the edges they return and for the seed's own path when the compiler tier covers it. A seed in a skipped file with no edge, such as a function whose first call, or its first caller in the same file, came in the skipped revision, is a lower_bound with scip_stale_files, not exact. An incoming answer also reads the namespace's marks once per query (_marked_stale): a marked file may hold the seed's first caller although it is neither a seed path nor the path of a returned edge. The read is bounded, since a full pass can mark a whole source tree: scip_stale_sample stops at a LIMIT of three paths, enough to say that a mark exists and to name files in the note, and the PR pack's line and the constructor probe, which need only a boolean, ask for one. A cleared mark, an empty row, is not in the sample either. While any mark is set, code.callers, code.impact, the grep neighbours' callers, the PR pack's callers line and the code.symbol uses block are a lower_bound with scip_stale_files, and code.test_gate lists the cause beside its other graph causes. The callers note names up to three marked files. A failed read of the marks counts as a mark.
  13. A delta file kept for scip-full --apply-delta is read by open_delta, which now refuses a delta_version the build does not apply (DELTA_VERSIONS, in scip_delta.py, which code_scip_apply reads too), as the worker does for an upload. The previous build's CLI applies a retained version-2 file as version 1: a skipped file's partial entry replaces its rows and no stale mark is written. Rule 70 says to apply a kept file with the CLI of the build that wrote it during a rollout or a rollback.

Scope and risk

The converter, lib.sh, the Go harness, compiler_tier.py (_attempt), delta_file.py, scip_delta.py (retire_published_marks), gitrepo.py (a strict read of blob_paths_at, and blob_ids), the code_scip_apply version check, scip_stale_paths, scip_stale_marks, scip_stale_sample and scip_marks_retirable in the store, the constructor-coverage probe and the stale read of the seed paths in coverage.py and graph.py, the namespace's marks read by every incoming answer (impact.py, gate.py, neighbours.py, packs.py, symbol_uses.py), one setting, docs and tests. A run without --changed-files (a TypeScript or Python full run, Go --full, a direct upload) fails, and keeps its watermark, on a failed document whose path cannot be read, until the indexer writes a readable one; a window does not. A skipped document is never repaired: its parser-tier rows are unaffected, its compiler rows stay as the last successful conversion left them and read as stale until a delta converts the file again. The stale marks are code_index_state rows, one per skipped file, so no migration is needed. A cleared mark stays as an empty row, which no read returns. A refresh that fails between its symbol and edge inserts leaves the mark counting until an apply of the file by this build completes; no watermark write retires it, whether from a completed apply that does not name the file, a window with nothing to apply, or the delta after a failed weekly C++ full run. The previous build never empties a mark, so a file it refreshes, during a rollout or after a rollback, stays stale and keeps constructor answers a lower_bound until, for an entry this build's tier worker runs, its next pass finds the refresh published, or until it applies the file itself. A failed upload batch newer than a mark keeps it until this build applies the file, and a Go refresh that rewrites no row of the file keeps it too. A namespace fed by uploads alone keeps the mark until this build applies the file. A Go tier keeps its marks while it owes a module retry, a mirror that lacks the watermark's commit or cannot answer keeps them all, and one that lacks a mark's commit keeps that mark. A marked file that the previous build deletes is never applied by this build again, so each apply of the tier also empties the marks of paths that have no blob at the delta's commit in the entry's mirror (_gone_at, one git cat-file --batch-check when marks are set); a mirror that cannot be read, or lacks the commit, keeps the mark. Namespace removal and the purge drop them with the namespace's other state. An index that cannot be read to its end now fails the Go tier too. An index that cannot be read to its end still fails the run, with or without the switch. A converter bug that broke most documents would skip them all and mark them stale rather than fail; an operator who wants such a run to fail sets the switch. While one document of a C++ index fails to decode, every changed file with a factory call is skipped and marked stale too, until the indexer writes that document again. A seed in a file the fast tier rewrote after the compiler tier's last run now reads stale in both directions, as its edges already did. While one file of a namespace stays marked, no incoming answer in that namespace is exact: the price of not knowing which seed the skipped document calls. code.impact and code.test_gate read the marks only: as on main, neither compares its seed paths with the fast tier's rows.

Compatibility, rollout and rollback

  • Wire: the delta gains skipped_files and stats.skipped_failed, and one that lists a skipped file is delta_version 2. An older server ignores the two fields and refuses version 2.
  • Rollout: the build before this one applies version 1 only. While it runs the workers, and after a rollback, it fails a version-2 upload (unsupported delta_version 2) and leaves the tier's watermark, so no old rows read as current; loom code scip-retry <batch_id> applies it once this build runs them. A delta with no skipped file stays version 1, which both apply. When the previous build applies one that converts a file this build marked, it leaves the mark and moves the watermark past the refresh; its rows cannot show that both inserts landed, so this build reads the file stale until, for an entry this build's tier worker runs, its next pass finds the refresh published (the watermark holds another blob of the file than the mark's commit, and no upload batch of the namespace has failed since the mark), or until it applies the file itself. A namespace fed by uploads alone keeps the mark until this build applies the file. The in-server tiers apply the deltas their own build's harness writes. A kept delta file read by the previous build's scip-full --apply-delta is applied without its skipped files, so it is applied with the CLI of the build that wrote it. The rolling-upgrade rules gain this as rule 70.
  • Operator steps: none. LOOM_CODE_SCIP_STOP_ON_FAILED_DOCUMENT=true restores the old failure.
  • Rollback: reverting restores the old failure. The older version has no prefix filter, so every scip_stale: row, emptied ones included, comes back in its whole-namespace state reads: the as-of block, coverage, code.repos, the tier-health sweep and code.index_status. Before or after the revert, remove them with a lightweight delete; no request waits on it: DELETE FROM loom.code_index_state WHERE startsWith(state_key, 'scip_stale:').

Tests

  • tests/unit/test_scip_to_delta_skip.py:
    • test_a_document_with_a_string_that_is_not_utf8_is_skipped_and_listed runs the command line on a two-document index whose second document carries invalid UTF-8: exit 0, only the good document in files, skipped_files == ["src/bad.cpp"], the count in the stats and the summary line, one warning, delta_version 2. On main it exits 1 on the DecodeError.
    • test_the_switch_stops_the_run_on_a_failed_document: with --stop-on-failed-document the run exits non-zero on the DecodeError and writes no delta.
    • test_the_harness_passes_the_switch_to_the_converter runs convert_delta from lib.sh with SCIP_STOP_ON_FAILED_DOCUMENT at 1 and 0: it fails and writes nothing, or succeeds and writes the delta. The 0 case fails on main.
    • test_a_document_that_fails_to_convert_is_skipped_and_listed makes _convert_document raise for one document: the other converts and the warning names the path and the error; a module prefix applies to skipped_files; a second DeltaStream leaves the first one's record as it was. On main the KeyError escapes.
    • test_a_window_lists_only_its_own_failed_documents: a window that does not hold the bad document counts it but lists nothing, and its delta is version 1.
    • test_a_run_over_every_document_fails_on_one_whose_path_cannot_be_read: the bad document's path is not UTF-8. A full run exits non-zero, names the document and writes no delta; a window counts it and converts. Before, the run exited 0 and listed the path with a replacement character.
    • test_the_server_logs_the_converters_warning_line pins the server's prefix to the converter's.
    • test_a_factory_caller_keeps_its_rows_when_the_overload_scan_misses_a_document: Foo's only constructor is declared in src/foo.h, which fails to decode, outside a window of the factory caller src/a.cpp and src/ok.cpp. The caller is listed in skipped_files and only src/ok.cpp converts; a full run lists both failed files. With a readable header the caller has its DB::Foo::Foo edge. On the head before it, the caller converted without the edge and nothing was listed.
  • tests/unit/test_scip_harness_windows.py::test_with_the_stop_switch_a_failed_document_fails_the_run, for the Python, TypeScript and Go harnesses over a real git window: with the switch on, a document that does not parse fails the run and writes no delta. Without pipefail in run_module the Go case exits 0 with no delta.
  • tests/unit/test_code_scip_ts_delta_worker.py::test_a_full_run_keeps_a_skipped_documents_rows_and_marks_the_file_stale: a full run whose delta skipped web/bad.ts retires only web/gone.ts and writes scip_stale:typescript:web/bad.ts. On main it retires web/bad.ts too.
  • tests/unit/test_code_scip_skipped_documents.py:
    • run_harness logs the first five warning lines and the count (on main it logs none) and passes the switch.
    • One apply marks and clears its tier's files in one insert, under its tier for an unowned suffix too, and never marks an out-of-scope or refused path.
    • A C++ delta that deletes a .py file, applied beside a Python delta that skips another, leaves both Python marks; the store fake lets both reads land before either write.
    • An upload applies for the tier whose watermark its producer moves.
    • test_a_skipped_path_that_files_or_deleted_files_name_keeps_its_rows_and_is_marked: a delta whose files or deleted_files and skipped_files both name one path hands the writer only its other files, and marks the path and clears the mark of the applied ones. On the head before this test, the path went through the key diff or was deleted.
    • test_a_full_run_that_skipped_a_document_does_not_claim_constructor_calls (in tests/unit/test_scip_to_delta_skip.py): a full C++ conversion with source whose only factory caller fails to convert lists it in skipped_files, has no factory edge and carries no features. On the head before it, it carried ctor_calls.
    • test_a_full_run_whose_constructor_scan_skipped_a_document_outside_its_files_makes_no_claim (same file): a --full run with a window of src/ok.cpp while src/foo.h fails to decode lists nothing in skipped_files and carries no features; with a readable header it carries ctor_calls. On the head before it, it carried ctor_calls.
    • test_a_skipped_file_withdraws_the_claim_a_clean_full_run_made (in tests/unit/test_code_ctor_call_edges.py): with scip_ctor_calls set and one compiler-tier file marked stale, code.callers on a constructor with no edges is a lower_bound with ctor_edges_absent. Before, it was exact.
    • test_a_mark_written_after_the_probe_is_cached_withdraws_exact (same file): three code.callers calls on a constructor with no edges in one process, with no cache clear: exact after a clean full run, a lower_bound with ctor_edges_absent once a later delta marks a file stale, and exact again once the mark clears, all through one state read. On the head before it, the second call was exact.
    • test_a_delta_version_the_build_does_not_apply_is_refused (in tests/unit/test_code_delta_stream.py): open_delta reads versions 1 and 2 and refuses 0 and 3 with unsupported delta_version. Before, it read any.
    • test_an_upload_that_skipped_a_document_waits_for_a_worker_that_marks_it stages a converted delta that skipped a document as an upload. Under a worker that applies version 1 only, as the build before does, the batch fails with unsupported delta_version 2 and no mark or watermark is written; under this build's it applies, marks the file and moves the watermark.
  • tests/integration/test_code_scip_stale_mark.py, against ClickHouse: a file whose document a delta skipped reads stale in scip_stale_paths after the watermark moved, and fresh again once a delta applies it; all_state and all_state_many leave the marks out. On main it reads fresh.
    • test_a_refresh_by_the_previous_build_keeps_the_mark_until_this_build_applies_the_file (same file): this build applies a delta that skipped src/bad.cpp, then a clean delta for it goes through the apply without _mark_stale, which is what the previous build runs, and the watermark moves. The file still reads stale, scip_stale_marks names it and _ctor_edge_coverage claims no constructor calls. This build's apply of the file then retires the mark, and a mark written after that counts again.
    • test_a_pass_of_this_build_retires_a_mark_the_previous_build_published (same file): with a two-commit mirror, the previous build refreshes src/bad.py and moves scip_commit_py, and an apply whose edge insert fails writes src/other.py, which is unchanged. One pass of the Python worker with nothing to index empties the first mark and keeps the second. On the head before it both marks stayed.
    • test_a_pass_retires_a_mark_the_previous_build_published_without_rewriting_a_row (same file): the previous build applies a body-only change of src/bad.py, which rewrites no symbol or edge row, and moves scip_commit_py; one pass of the Python worker empties the mark. On the head before it the mark stayed.
    • test_a_failed_upload_keeps_the_mark_past_a_later_batch_that_moves_the_watermark (same file): through code_scip_apply, an upload marks src/bad.py, the next batch changes it and fails on its edge insert, and a later batch for src/other.py moves the watermark; the pass keeps the mark. On the head before it the mark was emptied.
    • test_a_watermark_write_by_the_previous_build_keeps_the_mark_over_a_failed_apply (same file): after a skip and a moved watermark, a retry for src/bad.cpp lands its symbol insert and fails its edge insert; then the previous build's step for a window with no C++ change, the watermark write alone. The file still reads stale with coverage incomplete, and this build's later apply of the file retires the mark. On the head before it, the reads after that watermark write were fresh and complete.
    • test_a_failed_apply_keeps_the_mark (same file): the same failed retry with the watermark unmoved keeps the file stale, and so does the previous build's retry that then lands both inserts and moves the watermark.
    • test_an_apply_of_another_file_keeps_the_mark_over_a_failed_apply: after the failed retry, a completed apply of src/a.cpp and a moved watermark; src/bad.cpp still reads stale, and a completed apply of the file retires it.
    • test_a_failed_full_run_then_a_delta_without_the_file_keeps_the_mark: full_index with the harness stubbed converts both files and fails the edge insert, so scip_full_at moves and the watermark stays; a delta that applies only src/a.cpp then moves the watermark, and src/bad.cpp still reads stale.
    • test_a_window_with_nothing_to_apply_keeps_the_mark: after the failed retry, the C++ delta worker's _run_repo meets a window whose harness writes no delta and moves the watermark; the file still reads stale.
    • test_a_mark_for_a_file_the_previous_build_deleted_is_emptied_by_the_next_apply: over a two-commit git mirror, this build marks src/bad.cpp, the previous build deletes it, and this build's apply of another file at a commit the mirror lacks, or at one that still holds the file, keeps the mark; its apply at the commit without the file empties it and constructor coverage is complete again. Before, the mark stayed and coverage stayed incomplete for the whole namespace.
    • test_a_seed_in_a_skipped_file_with_no_edges_is_not_exact: src/bad.cpp holds caller and callee with no edges, exact both ways; a delta skips the revision that adds caller's first call to callee. code.callees on caller and code.callers on callee are then a lower_bound with scip_stale_files naming the file. On the head before it, both stayed exact.
    • test_a_first_caller_in_another_skipped_file_is_not_exact: callee in src/a.cpp and caller in src/bad.cpp are covered and nothing calls callee; a delta skips src/bad.cpp for the revision that adds the call. src/a.cpp does not read stale and no edge comes back, yet code.callers and code.impact on callee are a lower_bound with scip_stale_files, and exact again once a delta applies src/bad.cpp. On the head before it, both stayed exact.
  • tests/unit/test_code_stale_marks_bounded.py: a store fake holds 5000 marks, as a full pass can leave. test_a_namespace_marked_whole_is_read_with_a_limit reads them through _marked_stale and expects every query to carry LIMIT {limit:UInt32} with a limit of at most four, and a sample of exactly four (the note names three); test_the_pack_line_stays_a_lower_bound_over_a_bounded_read expects the same bound and the line lower_bound (scip_stale_files); test_a_failed_read_still_counts_as_a_mark expects the unread placeholder; test_stale_note_marks_that_there_are_more_files_only_when_a_fourth_is_sampled expects no ellipsis for three files and one for four. The first two failed on the head before it (the query had no LIMIT). In tests/integration/test_code_scip_stale_mark.py, test_the_bounded_mark_read_stops_at_its_limit_and_skips_a_cleared_mark sets six marks and gets four from the sample and one when asked for one, then clears them one by one: the sample never returns a cleared mark and is empty after the last.
  • A file marked stale elsewhere in the namespace lowers the grep neighbours' callers (test_a_file_marked_stale_anywhere_makes_the_callers_a_lower_bound), the code.symbol uses block (test_exact_only_when_every_seed_file_is_compiler_indexed) and adds the cause to code.test_gate (test_a_cut_coverage_read_is_a_cause_and_a_test_only_change_has_none); each failed on the head before it. The two constructor tests above now also list scip_stale_files, and the store stand-ins of the incoming-answer test files take a scip_stale_sample, and the callers note no longer counts files, since a sample cannot. tests/unit/test_code_stale_marks_note.py drives the PR pack's callers line (exact with no mark, a lower bound with one, absent when the read fails) and the callers note when the marks cannot be read.
  • tier is a required keyword of apply_delta: every test call passes one, the apply_delta stand-ins of four worker test files and the tier-health test take it, the batched-state test expects the scip_stale: filter of all_state_many, the store stand-ins of four test files take scip_stale_sample, and the converter stubs of two test files follow its new signatures.
  • Run here on the branch merged with main at e89cc858f, every extra installed: the skipped-document, delta-stream, constructor-call, constructor-remainder, apply-round, entry-lock, the four compiler-tier worker, converter-skip, harness-window, callers-candidate, epistemic-envelope, structural-verdict, pre-merge-input, batched-state, tier-health, any-namespace and scope-enforcement tests, 502 passed and 1 skipped, and the tunable-constant, public-copy and doc-link tests, 292 passed, on the commit before the last; on the final head the touched unit files give 493 passed. On the final head (main at 67fdb366b merges without conflict and is not merged in), the nine stale-mark integration tests pass against ClickHouse 26.12, and the converter, constructor-call, envelope, delta-stream and Python and TypeScript converter unit files give 225 passed; a wider set of eighteen unit files gave 653 passed before the last converter edit, which limits the completeness count to the C++ constructor scan. ruff check, ruff format --check, the function-length gate, the mypy gate (no errors: main's Streamed SCIP headers use their model field annotations #1915 fixed the delta_file.py header adapter), the secrets check and the analyzer corpus (no change) pass; this round changes no setting, and the settings, docs-reference and reach-census generators' --check runs passed on the earlier head; the SDK generators were not run here (CI runs them), and the change touches no wire shape. On the head that merges main at 583acb7b7, the ten stale-mark integration tests pass against ClickHouse 26.12, the Go worker file gives 90 passed, and 168 unit files around the graph answers, the envelope, the converter, the stale marks, the delta workers and the rolling-upgrade tests give 3056 passed and 43 skipped. ruff check, ruff format --check, the function-length and mypy gates, the secrets check and the settings, docs-reference and reach-census --check runs pass. On 20ccead39, the two new tests and the eight converter, delta-stream, entry-lock and constructor-call unit files around them give 229 passed, the ten stale-mark integration tests pass again against ClickHouse 26.12, and the lint, format, function-length, mypy and secrets gates, the tunable-constant, public-copy and doc-link tests pass. On a0f86605e, the three bounded-read unit tests and the eleven stale-mark integration tests pass against ClickHouse 26.12, 379 tests across sixteen unit files around the graph answers, the stale marks, the delta workers and the constructor calls pass, and the lint, format, function-length, mypy and secrets gates pass. On 60417d589, the converter-skip, converter, constructor-call, constructor-header, constructor-remainder and tunable-constant unit files give 122 passed, and the lint, format, function-length and mypy gates pass. On c3ae72247, the twelve stale-mark integration tests pass against ClickHouse 26.12, eighteen unit files around the compiler-tier workers, tier health, skipped documents, the entry lock, apply rounds and the stale marks give 621 passed and 1 skipped, and the lint, format, function-length, mypy and secrets gates pass. On b792baa8b, which changes text only, the doc-link, docs-reference and skipped-document unit tests give 308 passed. The full unit suite was not run here; CI runs it.

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 runs listed under Tests are the agent's, the last on 3906e188f.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the new setting's reference, schema, example file and defaults snapshot.
  • A new migration is additive and numbered after the latest on main; no migration is added.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version: no plugin file changed.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed: it did not.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes: the failure model in docs/operations/code-index-operations.md and scripts/scip_harness/README.md, and rule 70 in docs/architecture/rolling-upgrades.md.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

Note

High Risk
Changes core compiler-tier apply, versioned delta wire format, and cross-build mark retirement that affect code intelligence accuracy during rollouts and rollbacks.

Overview
Compiler-tier indexing no longer fails an entire pass when one SCIP document cannot be parsed or converted: the harness converter skips it (optional LOOM_CODE_SCIP_STOP_ON_FAILED_DOCUMENT to fail fast), lists paths in skipped_files, bumps deltas to delta_version 2 when any file is skipped, and the server keeps existing compiler rows while writing scip_stale:<tier>:<path> marks. Apply logic gains scip_applied records, retire_published_marks on tier passes, and stricter handling so skipped paths are not tombstoned or partially overwritten.

Rolling upgrades document rule 71 (N vs N-1 on v2 deltas and mark retirement). Harness scripts switch git file lists to NUL-separated paths for odd pathnames; factory/constructor edges are withheld when the constructor scan skipped documents, and ctor_calls namespace claims drop while stale marks exist.

Read-side epistemic answers (code.callers, impact, test gate, symbol uses, packs) treat namespace stale marks as scip_stale_files / lower_bound, with bounded mark sampling and updated ops/docs/schema for the new setting.

Reviewed by Cursor Bugbot for commit aff3758. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 3, 2026 11:43am UTC
loom-telemetry Ready Ready Preview Dec 3, 2026 11:43am UTC

Request Review

@zlareb1 zlareb1 self-assigned this Nov 28, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread scripts/scip_harness/scip_to_delta.py Resolved
Comment thread server/code/app/index/scip_delta.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full-run cleanup needs to distinguish a missing file from a document whose path could not be recovered. Queued uploads also need a rollout path that preserves skipped-file state when an older worker is still serving.

Comment thread server/code/app/index/compiler_tier.py Resolved
Comment thread server/code/workers/scip_apply.py Resolved
@zlareb1

zlareb1 commented Nov 28, 2026

Copy link
Copy Markdown
Member

The format job fails on the adoption page with the same formatter output on clean main. The pinned formatter passes locally with the repair. PR job · Main job · Repair #1706

@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Both points are addressed:

  1. Full-run cleanup: 4c2b16c fails a full run before apply when a failed document's path cannot be read, a path that is not UTF-8 included.
  2. Queued uploads: 695be37 writes a delta that lists skipped files as delta_version 2, which an N-1 worker refuses and leaves for N; rule 67 in the rolling-upgrade doc.

376a163 fixes the three unit failures CI found (a test stand-in without the tier keyword, a test that did not expect the scip_stale: filter) and realigns the operations guide's failure table for Prettier. The format job's biome failure is docs/pages/adoption.astro from main, which this PR does not touch.

…its rows, marked stale

One document python-protobuf refuses (a string that is not UTF-8) or that
fails to convert no longer fails the compiler-tier pass. The converter
names it once on stderr, lists it in the delta's `skipped_files` and counts
it; `run_harness` logs the warning for every tier. A full run does not retire
a skipped file, and `apply_delta` marks it stale (`scip_stale:<path>` in
`code_index_state`) until a delta applies or deletes it, which
`scip_stale_paths` reads. `code_scip_stop_on_failed_document` fails the pass
on such a document instead. An index that cannot be read to its end still
fails.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…ith the stop switch

A tier's stale files are one `code_index_state` row, `scip_stale:<tier>`,
rewritten in one insert by an apply that changes it, and left out of the
whole-namespace state reads. A skipped path the entry's scope or denylist
refuses is not marked. `run_module` in the Go harness sets `pipefail` and
returns 1 on a failed conversion. `run_harness` logs the first five skipped
documents and the count. A conversion failure carries the document's place in
the index, and the server's warning prefix is pinned to the converter's.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…the delta

`apply_delta` takes the delta's tier from every caller (an upload's is the
tier whose watermark its producer moves) and writes `scip_stale:<tier>:<path>`
rows: each skipped file marked at the delta's commit, and each of that tier's
marked files the delta applied or deleted emptied, in one insert. A tier reads
and writes only its own marks, so tiers applying side by side keep each
other's. `scip_stale_paths` reads the marks by prefix; the whole-namespace
state reads leave them out.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…ped files it converts

`scip_stale_paths` looks up each asked path's mark under each tier instead of
scanning every mark of the namespace. `skipped_files` holds only the failing
documents among the files the delta converts, so a document outside a window
is counted but not marked again. `tier` is a required keyword of `apply_delta`.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
Split the harness README's spliced sentence about a skipped document in
two, and add the window rule to the failure-table row.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
A run over every document lists each skipped document's path in
`skipped_files`, and the TypeScript and Python workers retire the live
files such a delta does not name. A document whose path could not be read
was only counted, so its file landed in that deletion set. The converter
now fails such a run before anything is applied; a window, which names its
own files, still counts it and converts. A path that is not UTF-8 is one
that cannot be read: it is no longer decoded with replacement characters
into a name no file has.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
An upload is applied by whichever build leads the workers. Build N-1's
`code_scip_apply` ignores `skipped_files`, so it would apply such a delta,
move the watermark and write no stale mark, and N would then read the old
rows as current. The converter now writes `delta_version` 2 when the delta
lists a skipped file, and 1 otherwise; the version goes last, since a
document that fails to convert is known only once the files are written.
N's worker applies both versions. N-1's applies version 1 only, so it fails
such a batch and leaves the watermark. The rolling-upgrade rules gain the
entry.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The `apply_delta` stand-in of the tier-health test takes the `tier`
keyword, and the batched-state test expects the `scip_stale:` prefix
parameter that `all_state_many` binds to leave the marks out. Prettier
realigns the operations guide's failure table after its widened row.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov
KaloyanNaumov force-pushed the pr/scip-skip-bad-document branch from 376a163 to 8bc15ff Compare November 28, 2026 14:10
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Rebased onto main at 07df22c95, which had taken rolling-upgrade rule 67 in the meantime, so this PR's rule is now 68. The commits named in the replies above are now 2da9227 (a full run fails on a document whose path cannot be read), 3ac33f5 (delta_version 2) and 8bc15ff (the test stand-in and the failure table). Nothing else changed.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full conversion now stops on an unreadable path, and version 2 keeps an older worker from applying a batch without stale marks. Applying an incomplete file can still retire its existing compiler rows.

Comment thread server/code/app/index/scip_delta.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rename report integration test fails at the same assertion on this head and on clean main. The tagged fixture describes a naming claim, so the planner returns about_naming. The same test passes with the fixture repair. PR job · Main job · Repair #1719

Two documents can cover one path, one converting and one failing. The
delta then names the path in `files`, holding only the converted
document's symbols, and in `skipped_files`. The apply took it through
the key diff, which tombstoned each symbol only the failed document
defined, and then marked the file stale.

`apply_delta` now leaves such a path out of the files it applies, as it
does a path that only `skipped_files` names: its rows stay as they are
and the file is marked stale until a delta converts it whole.

Also fix a comment: `scip_stale_paths` reads the marks by key.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

The overlap case is fixed in 03041ef: a file that one document converted and another failed is no longer applied at all. Its rows stay as they are and the file is marked stale until a delta converts it whole. The integration failure in the rename report is the one you traced to main; nothing here touches it.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new guard keeps rows when a path appears in both files and skipped_files. An uploaded delta can still delete rows for a path it declares skipped.

Comment thread server/code/app/index/scip_delta.py Resolved
A path listed in both `deleted_files` and `skipped_files` went to the
writer as a deletion and was then marked stale. The apply now leaves a
deleted path that the delta also skips out of the files it applies, as the
full run's deletions already do, so its rows stay and the mark is written.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tunable-constant check reports the same duplicate coverage limit on this head and on clean main. The coverage repair moves the bound report to the store. The same check passes on main with both the coverage and docstring repairs applied. PR job · Main job · Coverage repair #1722 · Docstring repair #1706

@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

A path in both deleted_files and skipped_files is no longer deleted by the upload path: skipped wins, as in the full run, and the file is marked stale. The red jobs on this head also fail on main: unit part 4 is test_no_new_tunable_constant on main's DOCSTRING_MAX_LINES, and integration part 1 is the rename fixture you repaired in #1719.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overlap test confirms that neither files nor deleted_files can retire a skipped path. Two remaining gaps affect complete graph answers and replay during an upgrade.

Comment thread scripts/scip_harness/scip_to_delta.py Resolved
Comment thread docs/architecture/rolling-upgrades.md Resolved
A full C++ conversion that skipped a document still listed `ctor_calls`
in its features, so applying it set the namespace's coverage bit. If the
skipped file was the only factory caller and had no prior edge,
`code.callers` had no edge to check for staleness and read the empty
answer as exact. The claim is now withheld when the delta lists a skipped
file.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The streamed reader behind `scip-full --apply-delta` read a delta file
without checking its `delta_version`, so a version this build does not
apply was read as one it does. It now refuses it, as the worker does for
an upload, and the list of applied versions lives in one place. Rule 68
says a kept version-2 file is applied with the CLI of the build that wrote
it during a rollout or a rollback, since the previous build's CLI applies
it without its skipped files.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…s stale

Withholding `ctor_calls` from a delta that skipped a document does not
undo a claim an earlier clean full run already made: the coverage bit
stays set. A later run that skips a new file with no prior edge left
`code.callers` with an empty answer it still read as exact, since the
staleness read looks at served edges and this file has none. The coverage
probe now counts the compiler tier as not carrying constructor calls
while any file it holds is marked stale, so the answer is a lower bound
until a delta converts the file and clears its mark.

Rule 68 now says what the previous build's CLI does with a kept
version-2 file: a skipped file's partial entry replaces its rows and no
stale mark is written.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The note names three marked files and adds ", ..." when more than three
paths were collected, but the bounded read stopped at three, so a
namespace with more marks read the same as one with exactly three.

The read now returns up to four marks (STALE_SAMPLE, STALE_SHOWN + 1),
the note still names three, and the ellipsis shows only when a fourth was
read. The bounded-read tests assert the new cap and the note tests cover
three and four files.

Assisted-by: Claude Code:claude-sonnet-5-5
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
KaloyanNaumov added a commit to KaloyanNaumov/loom that referenced this pull request Dec 2, 2026
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

@zlareb1 every finding on this PR is answered at 82521da, including the bounded stale-mark read. Once CI is green on this head, could it go in? The two findings that came after the earlier round are tracked as follow-ups, so this PR does not need another round:

  1. A C++ full run claims ctor_calls although its constructor scan skipped a document #2001: a C++ full run claims ctor_calls although its constructor scan skipped a document outside the window (Cursor's finding above). We found no input where an answer comes out wrong, and the fix is ready as a follow-up PR once this one merges.
  2. code.impact and code.test_gate answer exact for a seed file the compiler tier has not seen since it changed #2000: code.impact and code.test_gate do not check whether a seed's own file changed since the compiler tier last ran, here or on main.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incoming graph reads now fetch a capped sample of stale marks. The constructor coverage finding still applies. The full-run feature needs to depend on the constructor scan completing, including skips outside the emitted path list.

…ument

A full C++ run claimed ctor_calls whenever none of its listed files was
skipped. The harness passes --changed-files with --full, so a document the
constructor scan could not read outside that list was never listed, and
the run still claimed every factory constructor call of the namespace.

tail now also requires the scan to have read every document of the index.

Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test covers a constructor scan that skips a document outside the full-run window. The rolling-upgrade finding still applies. An N-1 worker can successfully refresh a marked Go, Python or TypeScript file and advance its watermark. N can retain that stale mark indefinitely when the file never changes again. Add a recovery path that can verify the file’s publication and clear its mark.

KaloyanNaumov and others added 2 commits December 2, 2026 11:00
The previous build writes no marks, so its refresh of a marked file left
the mark counting until this build applied the file again. For Python,
TypeScript and Go that wait had no bound when the file never changed.

Every compiler-tier pass now runs retire_published_marks for each entry
before its own work. A mark is emptied when the file holds a compiler-tier
row written after the mark and the tier's watermark holds another blob of
the file than the mark's commit. A Go tier that owes a module retry, and a
mirror that cannot answer, keep their marks.

Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The pass that retires a published mark runs only for an entry whose tier
this build's worker owns and whose mirror holds the commits. A namespace
fed by uploads alone, applied by code_scip_apply, has no mirror to prove
the refresh with and keeps its mark until this build applies the file.
Rule 69 and the docstrings of the pass, the mark reads and the integration
test said otherwise.

Say so, and drop the claim that a file that never changes again reads
fresh in every namespace. Also name the two limits of the proof: a Go
module that could not be fetched is passed without a retry, and a mirror
that lacks one mark's commit keeps only that mark, while one that lacks
the watermark's commit keeps all. Text only.

Assisted-by: Claude Code:claude-sonnet-5-5
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/code/app/index/scip_delta.py Resolved
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

The human speaking here.

The last failure found by Bugbot is an edge case.

This item saw a lot of work, and even if there are some edge cases left, it's passing a highly extended set of checks already. I think it's ready to go at this state.

if the edge case failure can be reproduced by a test, it may get a dedicated issue ... or not ... it's a really edge case.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous rolling-upgrade finding remains open. A valid N−1 apply can advance its watermark without rewriting any symbol or edge when only a function body changes. That file remains stale because recovery requires a newer graph row. The recovery can also clear a mark after an incomplete publication.

Comment thread server/code/app/index/scip_delta.py Outdated
"""The marked paths `retire_published_marks` empties."""
written = await repo.scip_marks_rewritten(org, ns, tier)
target = str(await repo.get_state(org, ns, watermark) or "") if written else ""
if not target or await repo.get_state(org, ns, f"{watermark}_retry"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 — A Go apply can write symbols and fail before writing edges. If the next attempt skips that unavailable module, the tier can advance the watermark without placing the module in its retry state. Recovery then treats the partial symbol write and changed blob as a completed graph publication. Use positive evidence that the file was applied before clearing its mark.

Comment thread docs/architecture/rolling-upgrades.md Outdated
writes after the migration ran. `tests/unit/test_store_names_refused.py` checks N's
side, and the mixed-version gate does not check this rule.

69. **A SCIP delta that lists skipped files** (`skipped_files`, written by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 — The combined list repeats item 69 after the workspace crawl entry. Prettier 3.9.9 fails on the CI merge and passes on its first parent. Format the combined file. The same merge also needs docs_reference.py to refresh the false-default setting count in docs/reference/status.md. Format job · Generator job

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged current main into the branch as fbf3c75, which renumbers this rule to item 70 after main's workspace crawl entry at 69 and formats the combined docs/architecture/rolling-upgrades.md with prettier 3.9.9. docs_reference.py was run on the merged tree, which refreshes the false-default count in docs/reference/status.md from 55 to 56, and the settings reference, schema, example, docs reference and reach census --check runs are clean.

KaloyanNaumov and others added 3 commits December 2, 2026 13:02
Upstream's rolling-upgrade list now ends with item 69 (workspace crawl
sources), so this branch's rule for a SCIP delta that lists skipped files
takes the next number, 70, and the combined file is formatted with
prettier 3.9.9. docs_reference.py refreshes the false-default setting
count in docs/reference/status.md (55 to 56) for the merged settings
catalog. No other in-repo text names the rule by number.

Assisted-by: Claude Code:claude-sonnet-5-5
Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The recovery pass asked for a compiler-tier row of the marked file
written after the mark. An apply of the previous build that changes a
function body alone rewrites no row of the file, so its refresh kept
the mark although the watermark had moved past the change. The Python,
TypeScript and C++ workers move the watermark only after a whole apply
of the window, so a watermark that holds another blob of the file than
the mark's commit is enough on its own.

An upload batch whose apply fails is recorded failed and leaves the
watermark; a later batch moves it without applying the failed batch's
files. The pass now keeps every mark older than the namespace's newest
failed batch, so such a file stays stale until this build applies it.

The Go worker passes a module it could not fetch without a retry, so a
Go mark still needs a row of the file written after it.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Both points are fixed in b914189 (head 3906e18, which also merges current main).

  1. Body-only refresh by N-1: the recovery pass no longer asks for a compiler-tier row written after the mark. For the Python, TypeScript and C++ tiers a watermark that holds another blob of the file than the mark's commit is enough, because those workers move the watermark only after a whole apply of the window and N-1 fails a run on a document it cannot read. An N-1 apply that rewrites no row of the file is then enough to retire the mark. Go keeps the row check, since its worker passes a module it could not fetch without a retry.
  2. Clearing a mark after an incomplete publication: the pass now keeps every mark older than the namespace's newest failed code_scip_apply batch (scip_marks_retirable). A failed batch leaves the watermark to a later batch that does not apply its files, so the file stays stale until this build applies it. A batch retried and applied since no longer counts as failed. Batch rows expire after 30 days.

Tests, in tests/integration/test_code_scip_stale_mark.py:

  • test_a_pass_retires_a_mark_the_previous_build_published_without_rewriting_a_row: N-1 applies a body-only change, checked to rewrite no symbol or edge row, and moves the watermark. One pass of the Python worker empties the mark. On b792baa the mark stayed.
  • test_a_failed_upload_keeps_the_mark_past_a_later_batch_that_moves_the_watermark: an upload marks the file, the next batch changes it and fails on its edge insert, and a later batch for another file moves the watermark. The pass keeps the mark. On b792baa it was emptied.

Rule 70 in docs/architecture/rolling-upgrades.md and the retire_published_marks docstring describe the new checks. The other 12 tests in the file still pass.

@zlareb1, could you take another look?

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Go recovery still treats an incomplete apply as publication when a later pass skips the unavailable module. The new failed-batch check also loses its protection when that record expires. Go publication thread

Comment thread server/code/store/index/symbols.py Outdated
)
SELECT marks.path AS path, marks.mark_commit AS mark_commit
FROM marks LEFT JOIN written ON written.path = marks.path
WHERE marks.marked > (SELECT at FROM failed)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 — Failed SCIP batch records expire after 30 days. Stale marks have no TTL. In test_a_failed_upload_keeps_the_mark_past_a_later_batch_that_moves_the_watermark, let the failed second batch expire and run recovery again. The third commit still has a different blob and max(version) returns zero, so recovery clears the mark even though the failed edge insert never landed. Require durable evidence that the file's publication completed before clearing its mark.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub reports conflicts with main in the SCIP converter, compiler tier, index store and TypeScript worker test. Please reconcile those files so CI can test the combined tree.

Brings the branch up to main (24950d9) so CI can test the combined tree.
No behaviour change beyond the conflicts below; the Go-publication and TTL
findings are a separate decision and are not in this merge.

Resolutions, by the main commit that moved each file:

- scripts/scip_harness/scip_to_delta.py (57ca94f, the record reader):
  the length prefix is read with word32 and bounds-checked in span, so the
  branch's varint cut and its own overrun check are dropped; both raise
  ValueError for a record that runs past the end. _document_path keeps the
  branch's strict decode on main's last-value reader: a path that is not
  UTF-8 reads as "", which _Skips refuses in a run over every document.
  Main's "replace" decode would name a file the index does not hold.
- server/code/app/index/compiler_tier.py (2434443, 611ce2f): the
  branch's skipped-document logging runs on main's three-value return,
  which also carries the job's output as printed.
- server/code/app/index/gitrepo.py (24950d9): main's blob_ids_at and
  commit_ids land whole, and blob_paths_at delegates to blob_ids_at, which
  raises on a reply short of the request. The branch's strict flag chose
  between that and an empty set, so it has nothing left to choose: the
  parameter and its one argument are removed. The branch's blob_ids stays
  for the delta's own blob reads.
- server/code/app/symbol/gate.py (24950d9): both causes are kept, the
  stale mark and the cut at the commit.
- server/code/store/index/base.py (1b55e34, 7aeede8): set_states stays
  one insert for several keys and takes main's floor per key: next_version
  on ClickHouse's clock, asked for each key, instead of one version_now for
  the batch. set_state still delegates to it.
- tests/unit/test_code_scip_ts_delta_worker.py (2434443): both tests
  kept, the stale-mark run and the harness env passthrough.
- tests/unit/test_code_scip_skipped_documents.py: the harness test asserts
  the new three-value return.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Merged main, merge only. Six files, seven hunks: the SCIP converter takes main's word32/span bounds check over this branch's varint cut; the compiler tier keeps the skipped-document warnings on main's three-value return; gitrepo takes main's blob_ids_at and drops the strict flag that made redundant; gate keeps both stale causes; set_states keeps one insert with main's per-key version floor. 4163e79

One composition worth naming: for a non-UTF-8 document path the converter keeps this branch's skip ("") rather than main's replacement-character decode. A skipped document is what this PR is for, and a full pass refuses on it. Say if you want the other way.

939 passed across the SCIP, converter, tier and gate suites. The stale-mark integration tests skip here — they need a ClickHouse target.

…y path and a deletion retires its rows

`_document_path` decodes with `replace` again. Its only job is a key: ordering and
pairing documents (`_stream_documents`) and naming a skip. Returning "" for every
undecodable path collapsed a bad byte under `src/` and the same byte under `lib/` onto one key,
where U+FFFD keeps them distinct, and it is the one string the store keys a document by.

`git_paths` emits git's `-z` output, raw and NUL-separated, and no longer drops a path
git still C-quotes (a name holding a tab, newline, quote or backslash). The second list
is a `--diff-filter=D` list: a dropped path never reached `deleted.txt`, never became
`deleted_files`, and the server — which reads a file the delta does not name as gone —
never retired the rows of a file that vanished. `_path_list` (scip_to_delta) and
`_read_lines` (scip_ts_projects) split on NUL only, decode with `replace`, and strip
nothing, so a deletion names exactly the key the store holds. `scip_ts_projects` matches
its member directories through the same `_key`, and prints the argv path back unchanged.
The C++ and Go runners' shell consumers read the lists with `grep -z`, `sort -zu`,
`read -d ''` and `path_count`, so no list is converted to newlines.

Pinned by tests/unit/test_scip_path_encoding.py on a real git fixture: one file's path
bytes go from UTF-8 to invalid and back across two commits; the old path is the delta's
`deleted_files`, the new one is the `replace` key, and every path git reported is in a
list. A full run now names an undecodable path by its replace key instead of failing;
it still fails for a failed document with no path at all, which cannot be named.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The merge restores the combined tree. The Go publication finding and the failed-batch expiry finding still apply. Both cases can clear a stale mark without evidence that the file’s edges were published.

…watermark

`retire_published_marks` read two absences as proof. A mark was retirable when
no `code_scip_batches` row of the namespace was `failed` and newer than it, so a
partial apply that published a file's symbols and raised on its edge insert
still cleared the mark once a later batch moved the watermark past the file, and
`code_scip_batches` expires a record 30 days after it is created, after which
every mark in a namespace was retirable.

A mark now retires on positive evidence only: a compiler-tier symbol or edge row
of the file stamped (`indexed_commit`) with the tier's watermark commit, which is
an apply's own record that it wrote the file there, plus another blob of the file
than the mark's. Every apply stamps its rows that way — this build's and the
previous build's, an upload's and a worker's alike — and a partial apply cannot
produce the stamp at the commit the watermark moves to: it stamps the commit it
failed at, writes no watermark, and what follows leaves the file's rows there. A
skipped file, a Go module its worker could not fetch, and a file whose apply
rewrote no row carry no row at the watermark's commit, so their marks stay until
this build applies the file. The pass reads `code_scip_batches` for nothing.

The Go tier also retires no mark while `tier_health:go` notes a dependency this
host cannot fetch (state `unavailable`), the module its worker passes without a
retry.

Rule 70 of `docs/architecture/rolling-upgrades.md` states the evidence, that it
does not expire, and that a mark without it stays until the file is applied
again. The tests read the tables' own definitions through clickhouse-local: a
mark whose apply failed its edge insert, a mark whose namespace holds no batch
row, and a Go mark under an unfetchable-dependency note survive, and the same
file applied with its edges empties its mark.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…termark

`scip_marks_retirable` retired on a row of either table stamped with the
tier's watermark commit, so a symbol row alone satisfied it. An apply whose
edge insert raised leaves the file's symbols stamped at the commit it was
applying, and a same-commit part or retry — a second batch that moves the
watermark onto that commit — made that symbol row the watermark's, so the
mark went with nothing showing the file's edges were published.

The evidence is now both of an apply's inserts: a symbol row of the file
stamped with the watermark commit and, when the store holds any compiler-tier
edge row of the file, an edge row stamped with that same commit. Whether a
file has edges is read from the rows it holds, so a file the tier writes no
edge of still retires on its symbol row alone. The blob difference and the Go
`rewritten` gate stand.

Rule 70 said a partial apply cannot carry the evidence, which held for the
batch that failed and not for the commit it failed at once a later batch moved
the watermark there; it now states both inserts, that same-commit path, and
the Go freeze the note imposes — every Go mark of the entry, because the
record names no faithful set of modules to scope it by. The integration test
that gave the old reason for a state its sibling retires now states what
empties a mark. Two of that file's harness stubs still returned the
pre-masking two-tuple and failed at the parent commit; they return the
printed output too.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
…ules

The pass read a count of the file's rows: a symbol row stamped at the watermark's commit
and, where the store held any edge row of the file, an edge row stamped with it. An apply
that rewrites a symbol row and leaves the edge set unchanged writes no edge row at all,
so `held > 0, stamped = 0` — a finished apply — is the shape a failed edge insert leaves,
which is the one state the mark exists to catch; `held` was a count with no FINAL and no
tombstone filter, so a file whose edges were legitimately removed was held for good; and
neither aggregation took FINAL, so a superseded version could answer for the live one.

Now each round writes one state row per marked file it carried —
`scip_applied:<tier>:<path>` holding the commit — last of the round's writes, after its
symbol insert and its edge insert and in the same coroutine, so the row exists only for a
round that raised neither. It is written for a file the round rewrote no row of too, which
is what a function body alone does. `retire_published_marks` reads that row and nothing
else: FINAL, non-empty, the watermark's commit, and newer than the mark. A mark and the
record that answers it are written and emptied in one insert, so no retirement joins a
record to a mark it was not written for.

The Go worker writes the modules it could not fetch to `scip_unavailable:go` before it
moves the watermark, and the pass gates those modules' files and a retried module's own:
one unbuilt module no longer holds every Go mark of the entry, and the masked health note
is not read for it.

A build that writes no record — the previous release — no longer retires a mark: its
refresh of a marked file leaves the mark counting, and the mark ends when this build
applies the file.

tests/unit/test_code_scip_mark_retirement.py applies every case on clickhouse-local, and
tests/integration/test_code_scip_stale_mark.py against a server.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The construction was accepted; what guarded it was not. Four gaps, closed by tests that
fail when the thing they name is flipped, and one duplicate that let the record's paths be
chosen in two places.

The Go gate (`scip_unavailable:go`) had no test: nothing named the key, so the wrong dirs
or a fetched module keeping its gate would have passed. Three tests now drive real passes:
a pass over three modules with two unfetched writes both dirs and not the built one, and
the next pass, which attempts one of them, rebases the gate as `previous - attempted`; a
module fetched again leaves the gate empty; and the row the pass writes is read back by
`_unbuilt_modules`, so the unfetched module's files are held and a file outside every dir
the gate names is not. Mutating the gate to name `attempted` fails all three
(`assert ['lib', 'mod_a', 'mod_b'] == ['mod_a', 'mod_b']`).

`applied_at > marked` was asserted only with the record newer than the mark. The same two
rows with the versions swapped — a mark written after an apply of the same commit — are now
parametrized: the mark-newer case is kept, the record-newer case retires. Flipping `>` to
`<` fails both.

`_record_applied` chose nothing before: `_apply_round` filtered `paths` through `marked` and
`_apply_file`'s `sink is None` fallback wrote its own conditional. Both pass their paths and
the marked set to one helper, which picks the record's files; the fallback needs no
difference, so it has none.

The test that asserted `["code_symbols", "code_edges", "scip_applied"]` read a call order.
It now reads the row back: live under FINAL, holding the apply's commit, newer than the
mark, and the mark it retires on the next pass. The order stays pinned by the keep-guard,
which fails when the record is written before the inserts: the edge insert raises and a
record of a round that never landed is left (`assert 'dddd…' == ''`).

The operations table still promised that "the next delta that converts the file clears the
mark". An N-1 delta neither reads nor empties a mark, so it now says the delta that carries
the file without skipping it empties the mark and N-1 neither reads nor empties one
(rule 70).

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Both findings are closed, and the fix is not in the predicate — it is in the apply. b5ff7ba

What was wrong. Retirement inferred that a file had been published from rows the apply writes for other purposes, and no arrangement of those rows can answer it: a symbol row stamped at the watermark says the symbol insert returned, not the edge insert — and when the edge set is unchanged the apply writes no edge row at all (_diff_edges keeps its rows without restamping), so a finished apply and a raised edge insert are the same rows. My first two attempts on this PR tried to read the answer out of those rows; both were unsound, and this one removes the question.

What it does now. Each round ends by writing one state row per file it carried — scip_applied:<tier>:<path> = the commit — after both inserts, in the same coroutine, including for a file whose rows did not change. The row exists only if neither insert raised. retire_published_marks joins the mark to that one row and to nothing else: FINAL, non-empty, the tier's watermark commit, written after the mark. A file the previous build applied holds no such row — N-1 writes none — so its mark ends when N applies the file.

That last sentence is a narrowing of the promise rule 70 used to make, and it is deliberate: N-1's rows are exactly what cannot distinguish a finished apply from a failed insert, and a mark kept a pass too long reads stale, where a mark retired on a partial apply hides the failure the mark exists for. Rule 70 and the recovery column in the operations guide now say this.

On the expiry half. code_scip_batches is no longer read at all. The failed-batch predicate and its 30-day TTL were the whole of that finding; nothing now infers from a row's absence, so expiry erases nothing and there is nothing to expire.

And on the encoding column of this PR — correcting what I said earlier: the branch no longer overrides #1962's policy. _document_path decodes with replace, one policy for the harness, and git_paths no longer drops a path it cannot print, so a path whose bytes change between revisions still reaches deleted_files and its rows are retired.

The Go tier's gate is now per module (scip_unavailable:go, the unmasked unreachable dirs, rebased each pass as previous − attempted), so one unbuilt module no longer freezes an entry's every Go mark.

Tests, each shown to fail against what it guards and pass after: a doc-only apply retires, an unchanged edge set retires, tombstoned edges do not hold a mark, a superseded version answers nothing, a record older than the mark does not answer it, the Go gate writes the unfetched dirs and rebases, a fetched module loses its gate, and an edge insert that raised leaves no record. 117 passed across the retirement and Go-worker files, 121 and 158 in the neighbouring scip sets, 14 in test_code_scip_stale_mark.py against a ClickHouse I started for it.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit b5ff7ba. Configure here.

Comment thread server/code/app/index/scip_delta.py Resolved
Upstream now carries the TypeScript held-edge delta (ClickHouse#2003): a delta that
indexed one member lists a reference to a term the index holds no definition
of in the file's `held_edges`, and the apply moves one into `edges` when the
stored compiler-tier row of its target is a function.

Conflicts, both resolved by keeping upstream's rule and this branch's threading:

- docs/architecture/rolling-upgrades.md: rule 70 is upstream's held-edge rule,
  and the skipped-files rule moves to 71. The operations guide's recovery
  column that names the skipped-files rule now says 71.
- scripts/scip_harness/scip_to_delta.py: upstream's `_ts_definition_unseen`
  and `_held_edges` with this branch's `skips` threading, so `_ts_prepass`
  takes a `_Skips` and still reads every document of the index.

The merge left the converter reading only NUL-separated `--changed-files`
lists, so a newline list (what `git diff --name-only` without `-z` writes, and
what the held-edge tests write) was one name with a trailing newline: the
delta matched no document and carried neither `edges` nor `held_edges`. A
list that holds a NUL is still split on NUL only, so a name holding a newline
survives; a list with no NUL is split on its lines. The held-edge test now
passes this branch's required `tier` to `apply_delta`, and its store double
answers `scip_stale_marks`.

Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
@KaloyanNaumov

Copy link
Copy Markdown
Contributor Author

Merged upstream main (b97367188). aff3758

The merge collided with #2003, which landed upstream while this branch was open: both claimed rule 70 of rolling-upgrades.md, and both changed the SCIP converter. Resolution — upstream's held-edge rule stays 70, the skipped-file rule here becomes 71, and the converter keeps upstream's _ts_definition_unseen/_held_edges beside this branch's skips threading. The apply keeps _settle_held_edges; nothing from either side was dropped.

One compatibility fix the merge needed, and it is worth naming because it is a contract change on our side rather than a defect upstream: this branch's _path_list read the changed/deleted lists as NUL-separated only, while upstream's --changed-files fixture writes a newline list (git diff --name-only without -z). A newline list arrived as one name with a trailing newline and matched no document, so the fixture produced no files at all. _path_list now accepts both: a list holding a NUL is split on NUL only with nothing stripped — a name may contain a newline — and a list with no NUL is split on its lines, as upstream read it. Nothing in the harness writes the newline form; it is read for callers that do.

454 passed across the seven files this touches, with a ClickHouse on the path for the real-SQL ones; 293 in the kind-prepass and doc-link pair. ruff and prettier clean.

This branch has not been deployed

No deployments
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.

One SCIP document that cannot be read fails the whole compiler-tier pass

2 participants