Repository navigation
fix(knowledge-turso): a build that continues after dropSource cannot bring the dropped source back - #38051
fix(knowledge-turso): a build that continues after dropSource cannot bring the dropped source back#38051objectstack-fleet[bot] wants to merge 2 commits into
Conversation
…y to the generation it began A build that continued after dropSource found no generation and opened a fresh active one, bringing the dropped source back. The adapter now keeps the generation each build began (its number, the time its row was made and its fingerprint) and refuses the build's later calls LOCK_CONFLICT once that generation is gone. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
📓 Docs Drift CheckThis PR changes 1 package(s): 9 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 2 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 5a219104bda2ab6615f8cb966c0b03d9aa303954 && git checkout 5a219104bda2ab6615f8cb966c0b03d9aa303954
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin b4c99b8dd17b4038b9b5891c87c998ad6e022bb5 82ee427df96222cd2e28a162b9f2cdb4a6b37f0e && git checkout -B drift-repro b4c99b8dd17b4038b9b5891c87c998ad6e022bb5 && git merge --no-ff 82ee427df96222cd2e28a162b9f2cdb4a6b37f0e
node scripts/docs-audit/affected-docs.mjs --json b4c99b8dd17b4038b9b5891c87c998ad6e022bb5
|
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP
Fixes #37953
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
IKnowledgeAdapter.dropSource(packages/spec/src/contracts/knowledge-adapter.ts) removes "every generation, the one under construction included", and afterwards "a source registered again under the same key is built from nothing". On the turso store a build that was under way when its source was dropped broke that: its next page reachedwriteTarget, which found no generation and opened a new active one (the rule that a source holding nothing takes the first fingerprint it is handed), and the rest of the walk landed there. The contract sentence is right and is unchanged. The adapter is fixed, mirroring the pgvector fix that landed for the same defect class.beginBuildnow records, per source, the generation the build writes into: the one it opened, the one under construction it joined, or the active one it rebuilds inside. The record is the generation's number, the time its row was made (created_at, already a column ofknowledge_generation, millisecond grain) and its fingerprint. The number alone is not enough on turso: the next generation is the source's highest plus one, so after a drop, or after one build replaces another, a new generation takes the same number again (pinned: a replacing build's generation is2again). Nothing new is stored; the table's shape is unchanged.ctx.reason === 'reindex'from a build this adapter began goes to its generation and to no other (writeTarget). When that generation is no longer active or under construction (the source was dropped in this process or another, or another build under another fingerprint replaced it), the build ends and the call is refusedLOCK_CONFLICT(409), the code and status pgvector answers.completeBuildmakes the same check first. Before, a completion with no write since the drop threw a plainErrorwith no code.writePassagesalready re-reads the planned generation inside its write transaction; that check now also comparescreated_at, so a later generation under the same number is never taken for the planned one. The batch is planned again, and the build's retry is refused by (2).turso has no builder lock and its drop is one SQLite-serialized transaction, so pgvector's first case (a drop missing a generation that a concurrent transaction opened) has no turso counterpart, as the card says.
Serial with F6. The approximate-index card (F6) edits the same file's search path and
completeBuild's start and has no PR yet. This PR stays out of the search code. A probegit merge-treeof this branch with that branch's head (84f82932d4) merges cleanly. Whichever lands second mergesmain.Tests
New top-level
describeinsrc/__tests__/acceptance.test.ts(the package's existing harness file), on:memory:and on afile:URL. Two adapters stand for two processes: each keeps its own builds, and on a file each has its own connection to the same database.LOCK_CONFLICT409; the store holds no generation row and no passage table for the source;indexStatusanswers{}; a build that begins afterwards builds the source from nothing and is searched.KnowledgeService: a walk whose source the other process drops after its first page stops (ok: false,indexed: 100, one page written), leaves nothing, and the next walk builds the source from nothing (ok: true,indexed: 250).Local readings at open time: NOT MEASURED (the shared verify lock)
NOT MEASURED: the package's tests, typecheck, the two ablations and the derived gate list. Reason: the container's shared verify lock never reached this branch in five queued attempts (about 53 minutes, each
VERDICT queue-timeout (exit 99) · never acquired, the place kept as a slot); the holder throughout was one full dogfood run (pid 7724, held 2653 s at the last reading), with three callers ahead of this one. The run that waits for the lock is queued as: the package'svitest run, then the ablations below, then the dependency-closure build,typecheck, and every commanddispatch-gates --commandsderives for this diff. Its readings go to the report comment on the card. CI'sTest Coreruns this package's test files,acceptance.test.tsincluded (it has no live dependency), andTypeScript Type Checkits typecheck.Ablations queued (each mutates the committed adapter, runs the new
describe, then restores and checksgit diff HEADis empty; the tests importsrc, so no dist is involved):writeTargetpath (thebuildbranch disabled): the write, listing, same-process, embedding, replaced and reused cells are expected red, the completion cells green;completeBuild's first check deleted: the completion cells are expected red.Overlap
node scripts/pm/overlap-check.mjsat 82ee427:VERDICT clean exit 0(origin/main 8d34c44 merges cleanly; 0 open PR heads share a file). F6 has no PR, so the probe above (git merge-tree --write-treeagainst its branch head 84f8293, empty attribute source) is the reading for it: exit 0.Acceptance notes
reasonother thanreindex, event sync) are not fenced. One that arrives after a drop opens a fresh active generation, as for any source that holds nothing; the service stops sending them once the source is unregistered in that process. Same boundary as pgvector.delete, the walk's purge) are not fenced: they remove from every generation of the source, and after a drop there is none, so nothing comes back.completeBuild, and turso has no builder lock whose idle time would end it, so its record stays until the source's nextbeginBuildin that process replaces it. A capped walk (limit, nobeginBuild) of that source in that process goes to the same generation it would have gone to anyway; after a drop it is refused once and the record is gone.buildEndedtext: one sentence, no SQL; operator text inremedy. No consumer parses it.Verification
Read first:
turso-adapter.ts, thebuildbranch at the top ofwriteTarget: every call of a walk goes through it, and a wrong match would refuse a healthy build.completeBuild: the check that comes first in its transaction.beginBuild: which generation is recorded (the one under construction taken up first, then the active one, else the one opened).Two-minute check:
pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2 src/__tests__/acceptance.test.ts -t "dropped while it runs". Expected: 30 passed (15 cells on each of the two store kinds).Generated by Claude Code