Repository navigation
feat(knowledge-pgvector): a changed fingerprint builds a new generation and switches to it - #37492
Conversation
…e and switch to it (wip) Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…ases (wip) Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…rations Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 3 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 af9134ff4bf328fe0a78efaa050c76c2f6598123 && git checkout af9134ff4bf328fe0a78efaa050c76c2f6598123
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 54ea3c8c383c0fb83f8af7efb32a677c5bb46db0 06d53aa71c61fe68984936f028454bbbd0e66457 && git checkout -B drift-repro 54ea3c8c383c0fb83f8af7efb32a677c5bb46db0 && git merge --no-ff 06d53aa71c61fe68984936f028454bbbd0e66457
node scripts/docs-audit/affected-docs.mjs --json 54ea3c8c383c0fb83f8af7efb32a677c5bb46db0
|
…t hand-run clear SQL Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head dc620cd · 2026-11-26T09:45Z |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: PR #37492 (card #37101, epic #37000), declaration face. Read: card #37101 body and its five comments (triage 7143822425, claim 7186338598, report 7187647713, amend 7187694971, report 7188339132), card #37465, the PR body, the net diff against Check-runs on the head: 57 runs, 40 success, 17 skipped, 0 failed. The dev's 38/15 is the same set before the PR-body edit re-ran four workflows. ① Derived judgmentsCaller-visible changes the diff implies, each judged:
Correctness of the generation switch (read in
Findings: S1 (should-fix) — The idle release does not fire on a node that keeps receiving record events. S2 (should-fix) — The builder lock is a SESSION advisory lock, and the store's default URL is the platform's database URL. Behind a transaction-mode pooler (PgBouncer transaction pooling, and the pooled URLs several hosted PostgreSQL services hand out) a session lock is not owned by the client session: it stays on whichever server connection ran the statement, the unlock may reach another one, and S3 (should-fix) — N1 (nit) — A stale builder's N2 (nit) — When the fingerprint is put back to the active one while a N3 (nit) — A search that meets three switches throws a plain N4 (nit) — Two sweeps of one retired generation at once (a sweep that outlasts the idle time, then another process's N5 (nit) — Tests. The rewritten acceptance cases no longer assert anything about Tests, as asked:
Docs, as asked: README "Rebuilds" and protocol §4.1 "Rebuilds" describe the code at the head (one transaction, batches of 1,000, row last, ② Semver level
③ Boundary flags
S1, S2 and S3 are open should-fix items: the delta that closes them is read by this reviewer before landing. No must-fix. Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha:
|
…lock; warn on a release the session no longer held Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…tension Two sessions that run `CREATE EXTENSION IF NOT EXISTS vector` at the same moment on a fresh database: the loser fails on the catalogue's unique key although the extension now exists. ready() re-reads it after a failed create and refuses only when it is still missing. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ
…g code Giving it CONCURRENT_MODIFICATION pins a code the error-status baseline lists as unpinned, and check:error-status-conformance then asks for that baseline row to go, a file outside this change. The code is left for a change that owns the baseline. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: PR #37492 (card #37101, epic #37000), declaration face, delta round. This record is whole for this head: it stands on the full read of Check-runs on this head: 57 runs, 39 success, 17 skipped, 0 failed, 1 in progress. The one in progress is ① Derived judgmentsEverything judged right on the earlier head stands; the delta touches none of it: the switch in one transaction, the Caller-visible changes the delta adds, each judged:
Earlier findings, each with its state at this head: S1 (should-fix) — CLOSED. S2 (should-fix) — CLOSED. The requirement is in README (its own bullet, naming the S3 (should-fix) — CLOSED. The PR body and the changeset both read N1 (nit) — CARRIED to #37465 (scope note 7188703516): N2 (nit) — CARRIED to #37465 (scope note 7190583879): retire the leftover N3 (nit) — CARRIED to #37465 (scope note 7190583879), still open in the code: a search that meets three switches throws an N4 (nit) — CARRIED to #37465 (scope note 7190583879), marked optional there. Unchanged. N5 (nit) — CLOSED in its two test parts: the acceptance case pins that Extra fix, outside the REWORK, judged: New this round: N6 (nit) — The N7 (nit) — The idle timer now depends on the caller passing ② Semver level
③ Boundary flags
No must-fix and no should-fix is open on this head. What remains is nits: N1 to N4 carried to #37465, N6 and N7 new. Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha:
|
|
repo:objectstack#5 · os-bill · session_01Utp6Cb4BAjgQ43tqy1DvVJ Landing · 2026-11-26T11:24Z · zone ai-37000
State change: ready for review + auto-merge (merge queue; the live pgvector suite runs there). #37101 closes on merge; close-out follows. N6 (ready() re-read) is described in the PR body, not added to the changeset, to keep the accepted head. |
Requested by Bill · project thread
Fixes #37101
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
What changes
@objectstack/knowledge-pgvectorbuilds a new generation beside the active one when the index fingerprint changes, and switches to it (ADR-0161 K7, rules 1 to 4). Before,beginBuildunder a new fingerprint was refused and the reindex result carried hand-run SQL that cleared the source.activeand at most onebuildinggeneration per source (two unique partial indexes, createdIF NOT EXISTSon the next boot), plusretiredones being deleted. Passage tables are unchanged: they are per vector width and already keyed by generation.beginBuildtakes the builder lock, then: same fingerprint as the active one, rebuild in place; same as the one under construction, take it up (resumed with what it holds); otherwise retire any unfinished one and open a newbuildinggeneration numbered past every generation the source has. Orphan passages (generation row deleted by hand) are deleted before any generation opens, as the first generation already did.KNOWLEDGE_REBUILD_REQUIRED(409), message "is being rebuilt" (the same code and wording as knowledge-turso). The ranking statement holds only while its generation is active (anEXISTSon the generation row in the same statement), and a search that meets a switch runs again, at most three times; the third answers an error rather than an empty result.completeBuild(the service calls it after the walk and its single purge) retires the active generation and activates the new one in one transaction, then deletes the retired generation's passages in batches ofdeleteBatchSizerows (default 1000) and its row last. A deletion that stops is logged atwarnand finished by the next build; a retired generation is never read.beginBuildtocompleteBuildon a connection outside the pool (PgPoolLike.connectSession, provided bypoolFromPg). A second builder getsLOCK_CONFLICT(409, standard catalog), so its walk reads and embeds nothing. Freed on completion, on process or connection death (PostgreSQL), afterbuildLockIdleMs(15 minutes) without a call of the build itself (calls with reasonreindex; event-sync writes do not hold it), and on plugindestroy. It is a session lock, so the store needs a direct or session-mode PostgreSQL connection: a transaction-mode pooler breaks it. Whenpg_advisory_unlockanswers false (the session no longer held the lock), the release is logged atwarnand names that requirement. A crashed build is resumable: the next build under the same fingerprint keeps what was written and the walk skips it by document hash.CREATE EXTENSION IF NOT EXISTS vectorat the same moment: the loser failed on the catalogue's unique key, andready()refused although the extension existed. It now re-reads the extension after a failed create and refuses only when it is still missing (pre-existing, seen as a flaky first reindex on a fresh database while the live suite ran its files in parallel).buildLockIdleMs,deleteBatchSize,logger;PgPoolLike.connectSession;PgvectorKnowledgeAdapter.close(). The changeset stayspatchand carries the sameClause-②line.beginBuild,completeBuild,indexStatus.buildingandctx.indexare ADR-0161 K8 item 8, already on main. No error code is added.service-knowledgeneeds no change: its walk already callsbeginBuild, purges once and callscompleteBuild.content/docs/ai/knowledge-rag.mdx, and one bullet in its pgvector section. The "Rebuilds" section ofpackages/plugins/knowledge-pgvector/README.md(it ships in the npm tarball) and the "Rebuilds" bullet ofcontent/docs/protocol/knowledge.mdxsection 4.1 now describe generations; the hand-run clear-SQL instructions are gone (claim amend 7187694971). All three say the builder lock needs a direct or session-mode connection.Tests
generations.live-postgres.test.ts(live PostgreSQL + pgvector, the package's existing live pattern): same width with the model changed, throughKnowledgeService(generation 2 built beside generation 1; search during the build refused "being rebuilt"; an event-sync write during the build lands only in generation 2 and is present after the switch; purge 0; generation 1 deleted; readingcurrent). Also: two concurrent builds (one builds, the other getsLOCK_CONFLICTand embeds nothing); a build whose session is terminated is resumed by another adapter with its passage kept; the idle release while event-sync writes keep arriving (they do not extend the lock; released afterbuildLockIdleMs); batched deletion (5 rows at batch 2 = 3 statements) and abandoning a generation for a third fingerprint.builder-lock.test.ts(no database): a release whosepg_advisory_unlockanswers false logs one warning naming the direct or session-mode connection; one that answers true logs nothing.generations: truefor pgvector (it wasfalse, pending this card).acceptance.live-postgres.test.ts: two cases that pinned the retired behaviour (reindex refused with hand-run clear SQL;beginBuildunder another fingerprint refused) are rewritten to the new behaviour. The case that ran the printed clear SQL is removed, because that SQL is no longer printed. The rebuild-required remedy is pinned to say "complete reindex" and to carry noDELETE FROM,DROPorTRUNCATE.Acceptance notes
buildLockIdleMspasses; another process is refusedLOCK_CONFLICTmeanwhile, and that refusal's remedy says when it frees. Fencing a build that lost its lock mid-walk is service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465 (service lease), not this PR.buildinggeneration that stays after the fingerprint is reverted to the active one, is deleted at the next build under another fingerprint; until then it holds rows and is never read. N4, two sweeps of the same retired generation at once, can leave passage rows behind when one deletes the generation row first; the sweep no longer sees them (it walks generation rows); they are never read, and the orphan cleanup deletes them when the source next opens a generation. N3 (that third error carries no code): giving itCONCURRENT_MODIFICATION(409) pins a code thatscripts/error-status-unpinned-baseline.jsonlists as unpinned, andcheck:error-status-conformancethen requires that row to be removed. The file is outside the claim surface, so the code was taken back out; it needs a one-line claim amend. Protocol section 9's table row is outside the claim surface and left as is.Verification
Read first, by risk:
pgvector-adapter.tscompleteBuildandsweepRetired(the switch and the batched delete),searchAttempt(theEXISTSguard and the retry),takeBuilderLockandreleaseBuilderLock.Two-minute check: with
OS_TEST_POSTGRES_URLpointing at a PostgreSQL that has pgvector, runpnpm --filter @objectstack/knowledge-pgvector exec vitest run src/__tests__/generations.live-postgres.test.ts. You should see 5 passed, among them the idle release under event-sync writes and the "model changed" case that is refused "being rebuilt" mid-build.Local test runs (head 06d53aa; PostgreSQL 16.16 + pgvector 0.8.7, a local instance, fresh database)
vitest run --maxWorkers=2 --reporter=verboseunder the verify lock:Test Files 6 passed (6),Tests 75 passed (75), lock VERDICT command-exit 0. All 5 generation cases and both builder-lock cases passed. Run at tree 06d53aa (the same tree as d1c735dce, whose commits were reworded only), plusnot-ready.test.ts11/11 with the new race case.pnpm typecheckandpnpm buildof the package: exit 0, check-dts-emitted 2/2.Ablations (each restored, git diff empty afterwards)
reasoncheck removed). Red: 1 failed of 5, the idle release while event-sync writes arrive.not-ready.test.ts, the lost-race case.Derived gates (dispatch-gates, 102 families over the whole change)
--ranreconciliation at 06d53aa: 102 derived, 100 run, 2 NOT-MEASURED, 0 unrun. The two are PREREQUISITE NOT MET (exit 3) on this checkout:check-plugin-teardown-shape --self-test(shallow clone) andspec check:skill-examples(client-react not built). This round ran 98 families for the round-3 paths, then 61 again for the adapter and changeset after the last code change, and 6 more fornot-ready.test.ts. One went red in between:check:error-status-conformance, which N3'sCONCURRENT_MODIFICATIONtripped (see Acceptance notes). It is green after that code was taken out.overlap-check: clean against origin/main 54ea3c8, #37477 and #37442. PR check-runs at 06d53aa: 53 completed, 38 success, 15 skipped, 0 failure. The CI check-runs are the authority. The live pgvector job (Temporal Conformance) runs in the merge queue, not on the PR.Generated by Claude Code