Repository navigation
fix(platform): end an indexing run whose document was released - #3439
Merged
Merged
Conversation
… module `assessRefLiveness` — the one definition of corpus-liveness and blob-liveness for a blob ref — moves from `domains/knowledge/release.ts` to `domains/knowledge/liveness.ts`, unchanged. The release seam imports the knowledge service for the scope reconcile, so the service could not import the predicate from it without a cycle; the indexer is about to ask the same question.
The corpus is keyed by blob ref, and a ref dies the moment its document is rewritten, replaced or deleted: the release seam deletes the corpus row, often seconds after the `rag.index_file` job for the same ref was queued. An agent that wrote `setup-state.json` and rewrote it two seconds later made the first job fail its chunk insert with 23503 `chunks_document_id_org_fkey` (the row had been released while the slice was embedding), burn a retry, and — wherever the old file row survived — a retry or a later slice re-indexed the dead ref until the daily reconcile. Three guards, one concept — a released document ends the run quietly: - `indexUploadedFile` asks the release seam's own corpus-liveness predicate (`isCorpusRefLive`) before it downloads anything, so a job that runs after the rotation indexes nothing, and hands the same question to the indexer as `stillWanted`. - `indexDocument` asks `stillWanted` AFTER claiming its corpus row, on every slice, and drops the claim on no. After the claim, never before: a release always follows the commit that killed the ref, so a release that ran before the claim is visible to a check made after it, and one that runs later finds the claimed row and takes it. - The write path holds the document row `FOR KEY SHARE` inside the write transaction and stops as `released` when it is gone (a concurrent release waits for the commit and cascades — never an FK violation); a continuation slice that no longer finds the row the first slice claimed stops instead of claiming a fresh one for the dead ref. `released` is a new `skipped` outcome: no `failed` status, no rethrow, no retry. Unit tests cover the write-time guard, the post-claim question and its ordering, the continuation guard, the clone path and the service handling; `checkIndexingReleaseRace` proves it on the real worker — the release landing during the embedding of a single-slice and of a later slice completes the job on its first attempt with no corpus row left for the old ref, and a job for an already-superseded ref indexes nothing.
The CLI workflow on main (run 35525098046, after #3438) failed its Windows build in config-source.test.ts: "a self-consistent changed archive still cannot claim the original Git pack tree" took 5.7 s and bun test's 5 s default killed it. The test builds the git release fixture; Windows runners stall on git for seconds at a time, and Linux and macOS finish the same test in well under a second. 1d1c532 raised the budget per file with `setDefaultTimeout(30_000)`, but twelve test files that build the same fixture never got it, and three of the four tests in this file carried a per-test 30 s while the fourth did not. One rule instead of a per-file convention: the package `test` script runs `bun test --timeout 30000`, and the workflow's unit and smoke steps go through the script, so no test file has to remember the budget and the local run matches CI. Linux, tools/cli: 1218 pass, 19 skip, 1 fail — provision.test.ts binding port 3005 against a running dev stack, the documented environmental red.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A document rewritten, replaced or deleted while its
rag.index_filejob is queued or running never comes back into the corpus, and the job ends quietly instead of failing.Why
Seen on the dev stack (09-20 17:07 UTC, org
test): an automation run wrotesetup-state.jsonand rewrote it two seconds later. The rewrite rotated the document's ref,releasePreviousBlobtrashed the old file row andknowledge.release_refsdeleted the old ref's corpus row — while the job indexing the old ref was still embedding. Its chunk insert failed withthe job burned a retry, and in the shapes where the old file row survives (a replacement keeps it bound, a late first attempt) the retry re-indexed the dead ref until the daily
knowledge.reconcile_corpussweep.indexDocumentclaimed its corpus row in one short transaction, embedded, then wrote chunks in another, with nothing in between checking the ref was still alive; a continuation slice whose row vanished re-claimed and re-embedded from chunk 0;indexUploadedFilenever asked whether anything still referenced the file.How
One concept, three guards — a released document ends the run as
released(a newskippedoutcome: nofailedstatus, no rethrow, no retry):indexUploadedFileasks the release seam's own corpus-liveness predicate (isCorpusRefLive, moved withassessRefLivenessintodomains/knowledge/liveness.tsso the service can import it without a cycle) before it downloads anything, and hands the same question to the indexer asstillWanted.indexDocumentasksstillWantedafter claiming the corpus row, on every slice, and drops the claim on no. After the claim, never before: a release always follows the commit that killed the ref, so a release that ran before the claim is visible to a check made after it, and one that runs later finds the claimed row and takes it.writeChunks/cloneChunkshold the document rowFOR KEY SHAREinside the write transaction and stop when it is gone (a concurrent release waits for the commit and cascades — never an FK violation); a continuation slice that no longer finds the row the first slice claimed (resumeDocumentId) stops instead of claiming a fresh one.Proof
core/knowledge/indexing.test.ts(write-time guard, post-claim question and its ordering, continuation guard, clone path, proceed-when-wanted),domains/knowledge/service.released.test.ts(early gate,releasedhandling, the wired question); the three sibling fakes answer the liveness query.backend:integration, new lanecheckIndexingReleaseRace— the fake embedding server performs the rotation and runs the release inline from inside the embedding request, on the real pg-boss worker:completed,retry_count 0, no corpus row for the old ref, old file row gone;tsc,oxlint --type-aware,oxfmt --check,lint:manual, knowledge vitest (149) all green. Fullbackend:integrationrun: 706/708 checks across 151 lanes; the two red lanes aretask-agent turn drive (reused host: exec→harvest→settle)(latest agent comment is the deliverables notice, not the report text) andsandbox teardown revokes the session gateway key(gateway admin answered 503 onexpiryHandBack) — both outside knowledge indexing, no[knowledge]line near either, not re-run onmain(the harness has no lane filter).Not in scope
The
[automations] trigger scan: N due schedule(s) have no deployed version to runlines from the same log are by design: provisioning binds every builtin pack's schedule enabled while the pack startsNot deployed, and the dev database has four organizations with nothing deployed.tests/manual/reference/automation.mdcarries the new row.Also here: the CLI workflow's Windows red on
mainThe last
mainrun of the CLI workflow (35525098046, after #3438) failed its Windows build inconfig-source.test.ts: a git-fixture test took 5.7 s andbun test's 5 s default killed it. 1d1c532 had raised the budget per file withsetDefaultTimeout(30_000), but twelve fixture-building files never got it.eb3b97769makes it one rule: the CLI package'stestscript runsbun test --timeout 30000and the workflow's unit and smoke steps go through the script. Touchingtools/cliand the workflow file makes the CLI workflow run on this PR, so the fix is proven here on all three platforms.