Skip to content

feat(knowledge-pgvector): a changed fingerprint builds a new generation and switches to it - #37492

Merged
objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/issue-37101-pgvector-generations
Nov 26, 2026
Merged

objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/issue-37101-pgvector-generations

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Bill · project thread

Fixes #37101

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用 PostgreSQL 存知识库的部署,换了嵌入模型或切分设置后,重建会在旧索引旁边建一套新索引,建好才切过去,旧的分批删掉;以前这种情况会拒绝重建、要运维手工清表。
  • 属于「知识库平台」大项的第二阶段,替自建 PostgreSQL 的部署解决换模型后必须手工清索引的问题。
  • 出错时最坏是重建期间该知识源检索一直返回「重建中」或旧索引未删干净占空间,不会返回新旧模型混排的错结果;这个包的改动可以直接撤回。
  • 无。

What changes

@objectstack/knowledge-pgvector builds a new generation beside the active one when the index fingerprint changes, and switches to it (ADR-0161 K7, rules 1 to 4). Before, beginBuild under a new fingerprint was refused and the reindex result carried hand-run SQL that cleared the source.

  • Generations. The generation table holds one active and at most one building generation per source (two unique partial indexes, created IF NOT EXISTS on the next boot), plus retired ones being deleted. Passage tables are unchanged: they are per vector width and already keyed by generation.
  • beginBuild takes 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 new building generation 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.
  • Writes go to the generation of the fingerprint they carry: during a build, the walk and event-sync writes carry the new one and land in the new generation only. Each write share-locks its generation row inside its transaction, so a switch or a retirement waits for it, and a write that finds its generation retired is planned again.
  • Search under the new fingerprint while its generation is building answers 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 (an EXISTS on 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 of deleteBatchSize rows (default 1000) and its row last. A deletion that stops is logged at warn and finished by the next build; a retired generation is never read.
  • One builder per source: a PostgreSQL session advisory lock (key: 64 bits of a hash of schema and source id) held from beginBuild to completeBuild on a connection outside the pool (PgPoolLike.connectSession, provided by poolFromPg). A second builder gets LOCK_CONFLICT (409, standard catalog), so its walk reads and embeds nothing. Freed on completion, on process or connection death (PostgreSQL), after buildLockIdleMs (15 minutes) without a call of the build itself (calls with reason reindex; event-sync writes do not hold it), and on plugin destroy. It is a session lock, so the store needs a direct or session-mode PostgreSQL connection: a transaction-mode pooler breaks it. When pg_advisory_unlock answers false (the session no longer held the lock), the release is logged at warn and 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.
  • Fresh database. Two sessions that ran CREATE EXTENSION IF NOT EXISTS vector at the same moment: the loser failed on the catalogue's unique key, and ready() 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).
  • New exports, all optional (widening): adapter options buildLockIdleMs, deleteBatchSize, logger; PgPoolLike.connectSession; PgvectorKnowledgeAdapter.close(). The changeset stays patch and carries the same Clause-② line.
  • No contract member is added: beginBuild, completeBuild, indexStatus.building and ctx.index are ADR-0161 K8 item 8, already on main. No error code is added. service-knowledge needs no change: its walk already calls beginBuild, purges once and calls completeBuild.
  • Docs: a "Generations" subsection in content/docs/ai/knowledge-rag.mdx, and one bullet in its pgvector section. The "Rebuilds" section of packages/plugins/knowledge-pgvector/README.md (it ships in the npm tarball) and the "Rebuilds" bullet of content/docs/protocol/knowledge.mdx section 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

  • New file generations.live-postgres.test.ts (live PostgreSQL + pgvector, the package's existing live pattern): same width with the model changed, through KnowledgeService (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; reading current). Also: two concurrent builds (one builds, the other gets LOCK_CONFLICT and 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 after buildLockIdleMs); batched deletion (5 rows at batch 2 = 3 statements) and abandoning a generation for a third fingerprint.
  • New file builder-lock.test.ts (no database): a release whose pg_advisory_unlock answers false logs one warning naming the direct or session-mode connection; one that answers true logs nothing.
  • Contract suite: generations: true for pgvector (it was false, pending this card).
  • acceptance.live-postgres.test.ts: two cases that pinned the retired behaviour (reindex refused with hand-run clear SQL; beginBuild under 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 no DELETE FROM, DROP or TRUNCATE.

Acceptance notes

  • Fixed in this PR (dc620cd): the README "Rebuilds" section and the protocol section 4.1 "Rebuilds" bullet said the store does not yet build a second generation and printed clear SQL. Both now describe the generations behaviour, after the claim amend added the two files to the surface. Left as is, being generic and still true: protocol section 3.6's sentence about an adapter that does not keep generations.
  • The builder lock is held on a dedicated session for the whole build. A walk that fails on a process that keeps running keeps it until buildLockIdleMs passes; another process is refused LOCK_CONFLICT meanwhile, 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.
  • Carried, not fixed here (seat note 7188645663): N1 (fencing a builder that lost its lock) goes to service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465. N2, a building generation 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 it CONCURRENT_MODIFICATION (409) pins a code that scripts/error-status-unpinned-baseline.json lists as unpinned, and check:error-status-conformance then 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.
  • A second builder that took over after an idle release writes the same documents under the same fingerprint into the same generation, so the index stays correct; only embedding spend is doubled.

Verification

Read first, by risk: pgvector-adapter.ts completeBuild and sweepRetired (the switch and the batched delete), searchAttempt (the EXISTS guard and the retry), takeBuilderLock and releaseBuilderLock.

Two-minute check: with OS_TEST_POSTGRES_URL pointing at a PostgreSQL that has pgvector, run pnpm --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)
  • Package suite with the live files on, vitest run --maxWorkers=2 --reporter=verbose under 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), plus not-ready.test.ts 11/11 with the new race case.
  • pnpm typecheck and pnpm build of the package: exit 0, check-dts-emitted 2/2.
  • Correction: the runs reported at bc0cab4 and dc620cd as "pgvector 0.8" were on pgvector 0.6.0. Every run since fb4146c is on 0.8.7, the version the CI live job uses.
Ablations (each restored, git diff empty afterwards)
  • A: writes no longer go to the generation under construction. Red: 3 failed of 5 (model changed; session died and resumed; batches and third fingerprint).
  • B: the advisory lock answer is ignored. Red: 2 failed of 5 (two concurrent builds; idle release).
  • C: one delete batch only. Red: 1 failed of 5 (batched deletion).
  • D (round 3): event-sync calls touch the lock again (reason check removed). Red: 1 failed of 5, the idle release while event-sync writes arrive.
  • E (round 3): no re-read after a failed CREATE EXTENSION. Red: 1 failed of 11 in not-ready.test.ts, the lost-race case.
Derived gates (dispatch-gates, 102 families over the whole change)

--ran reconciliation 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) and spec 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 for not-ready.test.ts. One went red in between: check:error-status-conformance, which N3's CONCURRENT_MODIFICATION tripped (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

@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/knowledge-pgvector, touching 36 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/plugins/knowledge-pgvector/README.md), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/ai/knowledge-rag.mdx (via LOCK_CONFLICT (symbol, a top-level const object), LOCK_CONFLICT (literal, a string literal in LOCK_CONFLICT))
  • content/docs/api/error-catalog.mdx (via LOCK_CONFLICT (symbol, a top-level const object), LOCK_CONFLICT (literal, a string literal in LOCK_CONFLICT))
  • content/docs/protocol/knowledge.mdx (via LOCK_CONFLICT (symbol, a top-level const object), beginBuild (symbol, a method of class PgvectorKnowledgeAdapter), buildLockIdleMs (symbol, a field of class PgvectorKnowledgeAdapter; a field of interface PgvectorKnowledgeAdapterOptions), completeBuild (symbol, a method of class PgvectorKnowledgeAdapter), deleteBatchSize (symbol, a field of class PgvectorKnowledgeAdapter; a field of interface PgvectorKnowledgeAdapterOptions), indexStatus (symbol, a method of class PgvectorKnowledgeAdapter), listDocuments (symbol, a method of class PgvectorKnowledgeAdapter), LOCK_CONFLICT (literal, a string literal in LOCK_CONFLICT))
What this run could not see
  • 1 changed file(s) yielded no anchor (packages/plugins/knowledge-pgvector/README.md) — pages documenting those are invisible to this run
  • 17 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 2 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 54ea3c8c383c0fb83f8af7efb32a677c5bb46db0 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from af9134ff4bf328fe0a78efaa050c76c2f6598123 — the merge of head 06d53aa71c61fe68984936f028454bbbd0e66457 into base 54ea3c8c383c0fb83f8af7efb32a677c5bb46db0, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# 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

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 54ea3c8c383c0fb83f8af7efb32a677c5bb46db0 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…t hand-run clear SQL

Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head dc620cd · 2026-11-26T09:45Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: TIER_DEFAULT
Head-sha: dc620cdb69845cd8b7cacea8a7a1fa5eaf0dfcf5
Local-runs: none
Security-touching: no

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 main (11 files, +876/−194), and the check-runs on the head. Code outside the diff (service-knowledge walk and purge, ci.yml) was read, not reviewed.

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. Temporal Conformance (live PG + MySQL) is among the skipped: every case that exercises this diff is a *.live-postgres.test.ts file, so no check-run on this head executed the new behaviour. See B1.

① Derived judgments

Caller-visible changes the diff implies, each judged:

  • beginBuild under a new fingerprint: main refused KNOWLEDGE_REBUILD_REQUIRED with clear SQL in remedy; the head opens a building generation and resolves. A refusal replaced by automatic work is a behavioural widening, and it is the declared contract (ADR-0161 K7 rule 3; protocol §3.6 "an adapter that keeps generations"), not a new one. Right.
  • reindexSource under a new fingerprint: ok: false with SQL becomes ok: true. Follows from the line above. Right. The cost is new and intended: the next boot now re-embeds the whole source by itself after a model change.
  • upsert carrying the fingerprint of the generation under construction: refused on main, accepted into that generation at the head. Right.
  • Search under the new fingerprint during a build: same code and status (KNOWLEDGE_REBUILD_REQUIRED, 409); the message changes from "needs a rebuild" to "is being rebuilt", the wording knowledge-turso uses. No code added. Right.
  • remedy of the refusal no longer carries SQL. Operator text only; the changeset says so. Right.
  • NEW refusal: beginBuild answers LOCK_CONFLICT (409) while another session holds the source's lock. This also covers the same-fingerprint rebuild and the first build, which main let two processes run at once. It is the card's item 3, a runtime behaviour, not a published accept set. The code is from the standard catalog (packages/spec/src/api/errors.zod.ts). Right, with S1 and S2 below on when it is answered wrongly.
  • indexStatus may answer building: true. Already a contract member. Right.
  • DDL at next boot: two unique partial indexes on knowledge_generation. Safe on data main wrote: main only ever inserted generation 1 per source, state active. Right.
  • Exported TypeScript surface of the package (reachable from src/index.ts): PgvectorKnowledgeAdapterOptions gains buildLockIdleMs, deleteBatchSize, logger; PgPoolLike gains optional connectSession; the adapter gains close(). All additive and optional. See S3.

Correctness of the generation switch (read in pgvector-adapter.ts at the head):

  • The switch is one transaction: every generation row of the source is locked FOR UPDATE, the active one is retired, the building one activated. Retire-then-activate keeps the one-active unique index satisfied inside the transaction. Atomic. Right.
  • The build itself is not one transaction and is not meant to be: each write batch is its own transaction, into a generation no search reads. Right.
  • A search cannot read a half-built generation after a fingerprint change: it ranks only the active row, the ranking statement carries an EXISTS … state = 'active' on the same snapshot, and an empty answer is re-checked and retried (3 attempts). A search whose statement started before the switch finishes on its MVCC snapshot. Right. Not changed by this PR: the FIRST build of a source opens its generation active, so it is searched while it fills.
  • Writes share-lock their generation row (FOR SHARE, matching number, fingerprint, width and state), so a switch or a retirement waits for them, and a write that finds its generation gone is planned again. This also guards a reused generation number. Right.
  • The old generation is not leaked: passages go in batches (deleteBatchSize), the row last; a stopped sweep is finished by the next beginBuild. No write can enter a retired generation. Right. N4 names one small leak.
  • Two replicas: pg_try_advisory_lock on a dedicated session, LOCK_CONFLICT before anything is read or embedded; the test asserts the second embedder saw zero calls. Under that lock, FOR UPDATE and the two unique indexes are a second line. Right, subject to S1, S2.
  • Crash mid-build: RESUMABLE, stated in code, docs and card report. The building generation is kept, the next beginBuild under the same fingerprint returns it, the walk skips by docHash, and the service purge confirms each candidate against its row before deleting. No per-generation tables exist: passage tables are per vector width (knowledge_vec_d plus an integer) and keyed by generation, so there are no orphan tables and naming is deterministic. Orphan passage ROWS (generation row deleted by hand) are deleted in the transaction that opens any generation. Right.
  • SQL: every value is a bind parameter, source ids and fingerprints included. The lock key is a sha256 of schema and source id, bound as a bigint. Inlined identifiers are the schema (held to SAFE_IDENTIFIER in the constructor), knowledge_vec_d plus a validated integer, and constants. The diff REMOVES the one place a source id was inlined as a SQL literal (clearSql). No injection path found.

Findings:

S1 (should-fix) — The idle release does not fire on a node that keeps receiving record events. touchBuilderLock runs on every upsert, delete and listDocuments for the source, whatever ctx.reason is, so event-sync writes restart the 15-minute timer. A walk that fails (the service then makes no completeBuild call) on a process that stays up leaves the lock held for as long as the source has a write at least every 15 minutes. Every other process is refused LOCK_CONFLICT for that whole time, with a remedy that says it frees "after 15 minute(s) without progress". README, protocol §4.1 and knowledge-rag.mdx item 5 say the same. No data is wrong; the same process can still rebuild (it reuses its lock), and a restart frees it. Fix: restart the timer only for calls of the build (ctx.reason === 'reindex'), or state the real condition in the three docs and the remedy. A test with an event-sync write inside the idle window would pin it.

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 pg_advisory_unlock's answer is not read. The result is either a LOCK_CONFLICT nobody holds until the pooler recycles that connection, or two builders. Read from the code, not run. Fix, text only at minimum: README (Rebuilds or the options table) states that the store's URL must be a direct or session-mode connection. Better: read the unlock answer and warn.

S3 (should-fix) — Clause-②: no. For the adapter contract it holds: no IKnowledgeAdapter member and no error code is added, and the behaviour is pulled to the declared contract. But the package's exported surface widens (three options, PgPoolLike.connectSession, close()), and by the letter of the L2 rule a widened public surface reachable through the exports map is a clause-② limb. The changeset names all of them in prose, so nothing is hidden. Either the lines read Clause-②: yes (widening) in the PR body and the changeset, or the seat records why adapter constructor options are not a published accept set. This record is the review that line would owe. Metadata-protocol: none is right: no key a metadata author writes changes.

N1 (nit) — A stale builder's completeBuild is not tied to the generation it opened: it switches whatever building row carries its fingerprint. With a lost lock plus two fingerprint flips inside one stalled build, it could activate another builder's half-filled generation. Belongs with #37465; see ③.

N2 (nit) — When the fingerprint is put back to the active one while a building generation exists, nothing retires that generation until the next complete build (beginBuild is the only place). indexStatus keeps answering building: true and its rows stay.

N3 (nit) — A search that meets three switches throws a plain Error with no code or status. The standard catalog glosses LOCK_CONFLICT as "Record is locked by another process"; the reuse is reasonable, the gloss is about records.

N4 (nit) — Two sweeps of one retired generation at once (a sweep that outlasts the idle time, then another process's beginBuild): one can read a short batch, stop, and delete the generation row while the other is still deleting passages. If that other one dies, the rows stay until the source's next generation opens. Never searched; space only.

N5 (nit) — Tests. The rewritten acceptance cases no longer assert anything about remedy, so nothing pins that it carries no SQL. The idle-release case sleeps 400 ms against a 150 ms timer on a live server. The table row for knowledge-pgvector in protocol §9 still says only "index fingerprint (§4.1)".

Tests, as asked:

  • The removed case ("the printed statements clear the source exactly") is removed rightly: clearSql is gone and nothing prints those statements. Its other half, "a first generation never adopts rows left behind", stays in the acceptance file untouched.
  • Rewritten case 1 still pins something real: a search under the new model is refused by code with no SQL in the message, then a complete reindex embeds once (indexed: 1, skipped: 0) and search answers. Rewritten case 2 pins that beginBuild under the active fingerprint opens nothing, that a search under another fingerprint is refused "needs a rebuild", and that completeBuild records the recipe hash.
  • Nothing that ran on main is newly skipped: the files keep describe.skipIf(!PG_URL) with requireLiveCell, and the contract suite turns generations from false to true, which adds a case. The CI step selects by the substring live-postgres, so the new file is picked up.

Docs, as asked: README "Rebuilds" and protocol §4.1 "Rebuilds" describe the code at the head (one transaction, batches of 1,000, row last, LOCK_CONFLICT, resume, orphan rows deleted before any generation opens). No "does not yet build a second generation" text is left in the package or content/docs. The one sentence that does not hold is the idle release (S1), in both files and in knowledge-rag.mdx.

② Semver level

.changeset/37101-pgvector-generations.md: @objectstack/knowledge-pgvector patch, with both declaration lines. Metadata-protocol: none takes patch (AGENTS.md Post-Task step 3: a non-protocol change, widening or breaking, ships patch). The level is right, and stays right if S3 flips the line to yes (widening). Nothing is removed from the exported surface, so no BREAKING banner and no ADR-0087 disposition is owed. The changeset body matches the diff. Check Changeset: success.

Clause-②: no — see S3.

③ Boundary flags

  • open_questions (report 7187647713): README and protocol §4.1 going false. Answered: amend 7187694971 took option A, and both are rewritten at this head. The latest report (7188339132) has none open.
  • Dev flag, carrier service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465: a build that lost its lock is not fenced mid-walk. ACCEPTABLE as a carried item; it does not block this PR. Concrete failure: (a) same fingerprint — a second builder resumes the same generation and both write the same ids and hashes into it; the first to finish switches; the index is correct and the embedding spend doubles. (b) another fingerprint — the later builder retires the earlier one's generation; the earlier one's writes are then refused KNOWLEDGE_REBUILD_REQUIRED (the fingerprint routing is itself a fence) and its completeBuild throws; spend is wasted, no row is wrong. Both are recovered by the next build. The one path to wrong data is N1, and it needs a lost lock and two fingerprint flips during one stalled build. Ask of the seat: service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465 speaks of the service lease only; add an adapter line to it — completeBuild switches only the generation this builder opened, and takeBuilderLock re-checks a kept session instead of trusting its map (a dropped session leaves the map entry in place).
  • Dev flag, no carrier: protocol §3.6 names only knowledge-memory as keeping generations. Generic and not false. Accepted.
  • B1, to the seat: the card's acceptance line "Container run … on CI PostgreSQL with pgvector" is NOT MEASURED on this head. Temporal Conformance never runs on pull_request; it runs on the merge-queue entry, and ci.yml says that queue run is outside the required set: a red does not eject the entry, it lands and shows on main. So the evidence for the switch, the lock and the batched delete at review time is the dev's local run (73/73 on PG16 + pgvector 0.8 at bc0cab45f; dc620cdb6 adds text only) and three ablations. Read that job's verdict on the queue entry or on main after landing; a red there is a main-red for this lane.
  • SQL push-down: no new id materialisation and no in-app join. The batched delete, the orphan-row delete, the active-generation guard and the generation number are all computed in SQL. One added read: an empty search answer re-reads the generation rows once.
  • Author: objectstack-fleet[bot]; no relay note owed.
  • Scratch: only files written this round under the PR's scratch dir were read.

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: claude/issue-37101-pgvector-generations
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: dc620cdb69845cd8b7cacea8a7a1fa5eaf0dfcf5
REWORK — L1, seat repo:objectstack#5. Contract record 7188620947 reads PASS, with no must-fix and three should-fix items open. The switch is one transaction, a search never reads a half-built generation, a crashed build resumes, and every value is bound. The lost-lock case wastes work but writes no wrong row (except N1, carried).

  1. Shape: open draft against main, 11 files (+876/−194), Fixes #37101, Clause-②: no, Metadata-protocol: none, knowledge-pgvector patch. Not governed. 0 failed.
  2. Premise: realises ADR-0161 K7. A fingerprint change rebuilds into a new generation and switches to it, where main refused with clear SQL. It reuses KNOWLEDGE_REBUILD_REQUIRED and LOCK_CONFLICT.
  3. Owed before ACCEPT:
  4. Accepted deviations (nits):
    • N2: a reverted fingerprint leaves a lingering building generation.
    • N3: three switches give a plain Error.
    • N4: concurrent sweeps can leave orphan passage rows until the next generation.
    • N5: a remedy no-SQL assert, the test timing margin, and the protocol §9 row.
    • Fix them if cheap, else carry them.
  5. Out of scope and where it went: N1 goes to service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465, together with the lost-lock fence. Add an adapter-side line there: completeBuild completes only the generation this builder opened, and re-checks a kept session.
  6. Landing terms: ungoverned, default tier. Owed: S1–S3 closed, the live count on the head, required contexts green, a same-head delta PASS and an ACCEPT. Then ai-37000 lands it with --land.

…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
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 06d53aa71c61fe68984936f028454bbbd0e66457
Local-runs: none
Security-touching: no

PR #37492 (card #37101, epic #37000), declaration face, delta round. This record is whole for this head: it stands on the full read of dc620cdb69845cd8b7cacea8a7a1fa5eaf0dfcf5 (record 7188620947) plus the delta dc620cdb6..06d53aa71 (9 files, +153/−26; the earlier head is an ancestor, no merge of main). Read this round: card #37101's new comments (claim amend 7188722795, report 7190533996), card #37465's four comments, the PR body as it now stands, the delta, and the check-runs on this head. Net diff against main: 13 files, +1001/−192.

Check-runs on this head: 57 runs, 39 success, 17 skipped, 0 failed, 1 in progress. The one in progress is Check Changeset, re-run by the PR-body edit at 11:19Z; its run on the push of this head is a success. Temporal Conformance (live PG + MySQL) is still skipped on pull_request (B1 below). The two new files without a database (builder-lock.test.ts, the new case in not-ready.test.ts) run in Test Core, which is green.

① Derived judgments

Everything judged right on the earlier head stands; the delta touches none of it: the switch in one transaction, the EXISTS guard and retry on search, the share-locked writes, the batched delete with the row last, resumable builds, bind parameters throughout. The delta adds no SQL identifier and no inlined value.

Caller-visible changes the delta adds, each judged:

  • The idle timer restarts only on a call whose ctx.reason is 'reindex', and when the lock is taken. The service's walk, its listing and its purge all carry that reason (read in service-knowledge, not reviewed), and event sync carries 'event-sync'. Right.
  • releaseBuilderLock reads pg_advisory_unlock's answer and logs one warn when it is not true. A session that is gone still takes the catch and logs nothing, which is right: PostgreSQL freed that lock. Right.
  • ready() re-reads the extension after a failed CREATE EXTENSION. See the judgment under "Extra fix". Right.
  • Texts: README, protocol §4.1, knowledge-rag.mdx items 4 and 5, the changeset, the option's JSDoc and the class JSDoc now state the real idle condition and the direct or session-mode connection requirement. They agree with the code at this head. Right.

Earlier findings, each with its state at this head:

S1 (should-fix) — CLOSED. touchBuilderLock(ctx) returns unless ctx.reason === 'reindex'; all three call sites pass ctx. The live case now sends event-sync upserts every 50 ms under a 300 ms idle time and requires the second adapter's beginBuild to get through, and not before 300 ms. With the check removed the timer would restart on each upsert and the case goes red, which is the dev's ablation D (1 of 5). All four texts are corrected.

S2 (should-fix) — CLOSED. The requirement is in README (its own bullet, naming the url option and OS_DATABASE_URL), knowledge-rag.mdx item 4 and protocol §4.1. The unlock answer is read and a false one is logged; builder-lock.test.ts pins both the warning and its absence, and runs in Test Core. The store still cannot DETECT a transaction-mode pooler before a build; the warning comes at release. That is accepted: the doc line is the control.

S3 (should-fix) — CLOSED. The PR body and the changeset both read Clause-②: yes (widening), claim amend 7188722795 says the same, and the changeset and PR body name the five new exports. This record is the review that line owes.

N1 (nit) — CARRIED to #37465 (scope note 7188703516): completeBuild completes only the generation this builder opened, with a coded refusal and a two-builder test. Unchanged in this diff.

N2 (nit) — CARRIED to #37465 (scope note 7190583879): retire the leftover building generation at beginBuild. Unchanged. One correction to the PR body's wording: the code already retires it at the next beginBuild under ANY fingerprint, the active one included, not only "under another fingerprint"; what is missing is that nothing starts such a build once the reading is current.

N3 (nit) — CARRIED to #37465 (scope note 7190583879), still open in the code: a search that meets three switches throws an Error with no code. The dev's reason for taking the fix back out holds: CONCURRENT_MODIFICATION needs its row removed from scripts/error-status-unpinned-baseline.json, which is outside the claim surface.

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 remedy says "complete reindex" and carries no DELETE FROM, DROP or TRUNCATE; the idle case no longer rests on one fixed sleep. Its third part, the protocol §9 table row, is left as is, outside the surface and not false. Accepted.

Extra fix, outside the REWORK, judged: ready() on a fresh database. Two sessions running CREATE EXTENSION IF NOT EXISTS vector at once make the loser fail on the catalogue's unique key although the extension now exists; ready() then answered not-ready. The fix is one line in the catch: read the extension again, and refuse only if it is still missing, with the first error kept for the refusal's text. It is inside the claimed surface (knowledge-pgvector/src), it cannot turn a missing extension into a ready store (readiness still requires the row in pg_extension), and a failed re-read falls back to the old refusal. The new unit case is deterministic and runs in Test Core; ablation E is the dev's. Right to fix here: this PR's own parallel live files are what expose it.

New this round:

N6 (nit) — The ready() fix ships in this package and is in the PR body, but the changeset body does not mention it. One line there would put it in the CHANGELOG.

N7 (nit) — The idle timer now depends on the caller passing reason: 'reindex'. reason is optional and open on the contract, so a caller that drives a build with another reason loses the lock after 15 minutes while it is still walking. The option's JSDoc says so; the knowledge service always passes it. No action owed here; it falls under #37465's fence.

② Semver level

.changeset/37101-pgvector-generations.md: @objectstack/knowledge-pgvector patch, Clause-②: yes (widening), Metadata-protocol: none. The kind none takes patch, and a non-protocol widening ships patch (AGENTS.md Post-Task step 3). Right. Nothing is removed from the exports, so no BREAKING banner and no ADR-0087 disposition is owed. A (widening) arm with kind none owes no Skills-docs: line and no full dogfood battery. The PR body and the changeset carry the same two lines.

③ Boundary flags

  • open_questions in report 7190533996: none.
  • Dev flags in that report: N3, N2, N4 and N1 each have a carrier comment on service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465 (7190583879, 7188703516), read this round. The §9 table row has no carrier and is accepted above.
  • Lost lock not fenced mid-walk: still acceptable as carried to service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465, on the reasoning of the earlier record. Same fingerprint: doubled embedding spend, correct index. Another fingerprint: the earlier builder's writes are refused and its completeBuild throws. The one path to wrong data is N1, now an acceptance line on service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465.
  • B1, to the seat, unchanged: the card's acceptance line "Container run … on CI PostgreSQL with pgvector" is NOT MEASURED on this head. Temporal Conformance never runs on pull_request, and its merge-queue run is outside the required set, so a red there does not eject the entry. The evidence at review time is the dev's local run, now 75/75 on PostgreSQL 16.16 with pgvector 0.8.7, the version the CI job pins, plus ablations A to E. The dev corrected the earlier reports: those runs were on pgvector 0.6.0. Read that job's verdict on the queue entry or on main after landing.
  • SQL push-down: the delta adds no query shape beyond aliasing the unlock answer and one re-read of pg_extension on a failed create. No id materialisation, no in-app join.
  • Author: objectstack-fleet[bot]; no relay note owed.
  • Scratch: only files written by this reviewer under the PR's scratch dir were read.

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: claude/issue-37101-pgvector-generations
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: 06d53aa71c61fe68984936f028454bbbd0e66457
ACCEPT — L1, seat repo:objectstack#5

  1. Shape:
    • Open draft against main, Fixes #37101.
    • Clause-②: yes (widening) (five new exports, per claim amend 7188722795), Metadata-protocol: none.
    • knowledge-pgvector patch.
    • Not governed.
  2. Premise:
    • A fingerprint change rebuilds into a new generation and switches to it in one transaction (ADR-0161 K7). A search never reads a half-built generation.
    • The idle release now restarts only on reindex.
    • The direct or session-mode connection requirement is documented, and a false unlock logs a warning.
    • The extra ready() re-read after a failed CREATE EXTENSION is one line, inside the surface, and pinned.
  3. Gates:
    • Delta record 7190640828 (same reviewer, verified on the transcript) reads PASS. S1 to S3 are closed.
    • Live pgvector acceptance is measured locally only: 75/75 on PG 16.16 with pgvector 0.8.7, plus ablations A to E. Temporal Conformance skips on PRs, and its queue run is outside the required set. The seat accepts the local measure, and the os-dev report carries it.
  4. Accepted deviations:
  5. Out of scope and where it went: service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465.
  6. Landing terms: ungoverned, default tier. A same-head delta PASS plus this ACCEPT. Area ai-37000 lands with --land once the in-progress Check Changeset re-run (from the 11:19Z body edit) is green.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6Cb4BAjgQ43tqy1DvVJ

Landing · 2026-11-26T11:24Z · zone ai-37000

Probe Reading
Head 06d53aa71c61fe68984936f028454bbbd0e66457 = ACCEPT 7190657403 head (delta contract record 7190640828 PASS)
Checks on head success=40 skipped=17, 0 failure; Check Changeset re-run after the body edit: success
Governed check-governed-merges.mjs --pr 37492: NOT governed, 1193 lines ≤ 3000

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.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 26, 2026 11:24
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit fc7bdeb Nov 26, 2026
58 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-37101-pgvector-generations branch November 26, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

knowledge-pgvector: a changed fingerprint builds a new generation and switches to it

2 participants