Repository navigation
fix(service-knowledge): a build that loses its lease stops at the next page, and a stalled build is cancelled - #37570
Conversation
…ease is lost, and is cancelled when it stalls Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…d completes nothing; an exhausted search is CONCURRENT_MODIFICATION Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…or fence; changeset Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…t the bound Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…bounds like a find Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 4 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 — 43 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 3197f5514a895c67201a4455e548fb3fd8453df3 && git checkout 3197f5514a895c67201a4455e548fb3fd8453df3
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin b1c41e55e23a604c9c59430f45d05b2b3ac86837 e5bac7e3ba7bd362eb932d7f5d8eef6a9678bf83 && git checkout -B drift-repro b1c41e55e23a604c9c59430f45d05b2b3ac86837 && git merge --no-ff e5bac7e3ba7bd362eb932d7f5d8eef6a9678bf83
node scripts/docs-audit/affected-docs.mjs --json b1c41e55e23a604c9c59430f45d05b2b3ac86837
|
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 50bac35 · 2026-11-26T14:29Z |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: Inputs: card #37465 (body, triage, three scope notes, claim and its amend, both os-dev-reports), PR #37570 (body, 9 files), the net diff against ① Derived judgmentsAccept-set and public-surface changes the diff implies:
Seat questions:
② Semver level
③ Boundary flags
Findings:
No must-fix: the card's acceptance holds. The per-page lease check has its lapsed-mid-walk test, the bound has its never-answering-embed test with the lease released and the next build Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha:
|
…ng, and a hung listing, purge or completion frees the source's walk Also: the pgvector lost-lock remedy names the transaction-mode pooler; the CLI's build view knows lease-lost and timed-out; the docs cross-reference the builder lock's idle time. Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: This is a delta review. The previous record was at Inputs:
Every required context is green: Lint & Repo Gates, TypeScript Type Check, Test Core, Build Core, Governed Surface Queue Guard, Test UI, Live E2E UI, Dogfood Regression Gate and Check Changeset. Temporal Conformance (live PG + MySQL) is still skipped on the PR, so the live pgvector cases have only the dev's local reading (83/83) until the queue runs. ① Derived judgmentsWhat the delta changes in the accept-set and the public surface:
Prior ids:
Judged as asked:
② Semver levelChangeset:
③ Boundary flags
Findings:
No must-fix: S1, S2 and S3 are closed as ordered, and the card's acceptance still holds. S4 to S6 are correctness defects in the stop and record semantics, not in the index's correctness, and none adds embedding spend beyond skipped-unchanged pages. Every check-run is green. Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对 (delta)Head-sha:
|
…k the bound The completion is no longer raced against the stall bound: the fence is disarmed once it begins (fence.completing()), and the source's walk chain stays held until it settles, so no rebuild on this node begins a build beside an old switch or sweep. Each purge deletion restarts the bound. The per-document limit of a hung purge removal is named as it is, and its test no longer hides the document from later builds. Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
…ncelled at the bound Pins rebuildSource's race of the whole walk, which the walk's own fenced calls do not cover: the wait in the source's queue behind a plain reindex. Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: Second delta review. The previous head was Sources read:
Temporal Conformance is still skipped on the PR, so the live pgvector cases rest on the dev's local reading until the queue runs them. ① Derived judgmentsWhat the delta changes in the accept-set and the public surface:
Prior findings:
Judged as asked:
② Semver levelThe changeset is unchanged in its frontmatter:
③ Boundary flags
New findings:
No must-fix:
Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对 (delta 2)Head-sha:
|
|
repo:objectstack#5 · os-bill · session_01Utp6Cb4BAjgQ43tqy1DvVJ Landing · 2026-11-26T16:59Z · zone ai-37000
State change: ready for review + auto-merge (merge queue; the live pgvector suite runs there). #37465 closes on merge; close-out follows. Accepted nits N6/N7 go to a p3 follow-up under #37465. |
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 45863935395 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 分类: 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 45864600663 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 分类: 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
Requested by Bill · project thread
Fixes #37465
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
What changes
Cluster lease fence (service-knowledge).
rebuildSourcenow runs its walk under a build fence (startBuildFence,knowledge-build.ts), andwalkObjectSourceasks the fence before each page:isHeld() === false, when a renewal failed and the handle no longer holds the lease, or when no renewal has succeeded withinBUILD_LEASE_MS. The last case covers a lock store that does not answer, or a renewal that hangs.lease-lostand the lease is released.completeBuild.Stall bound (service-knowledge).
BUILD_STALL_LIMIT_MSis a fixed 15-minute ceiling on the time between two pages or two purge deletions (and before the first page, and from the last page to the purge). It is not a settings key and not an option, so ADR-0049's key-with-reader rule has no key to apply to.timed-out, the lease is released, and nothing is purged or completed.beginBuild, the document listing, each page'sengine.find,adapter.upsertandadapter.delete, and the purge. Such a call that never answers no longer holds the source's walk chain, so the next rebuild runs at once (with the one exception named in Acceptance notes).serializehook inwalkObjectSourceticks the fence when each candidate settles), so a large, healthy purge is never cut short.rebuildSourcealso races the whole walk. That covers what the walk does not fence: the wait in the source's queue behind another walk, andplanIndex.completeBuildhelper checks the fence first, so a lease lost during the purge, or a purge that answers after the bound, completes nothing. Once it lets the completion begin, it callsfence.completing(), which disarms the bound for the rest of the build, and awaitsadapter.completeBuildwithout a race. A switch that began before the bound passed therefore still commits, and the record readsdoneorfailed, nevertimed-outover a switched index. pgvector's sweep of the replaced generation runs inside that call, so it is not cut short either.reindexTails) stays held until the completion settles. No rebuild on this node can begin a build, and so take pgvector's builder lock, beside an old switch or sweep. The old call'sfinally(which clears the adapter'sbuildsentry and releases its lock) can therefore no longer clear a newer build's entry or lock. The cost, named in the docs: a completion that never answers keeps the buildrunninguntil it answers or the process restarts.pgvector builder-lock fence.
ctx.reason === 'reindex', for a build this adapter began) first checks inpg_locks, on the lock's own session, that the source's advisory lock is still held. If it is not, the write is refused withLOCK_CONFLICT(409) before anything is embedded.completeBuildcompletes only the build this adapter began, and only the generation that build began. Otherwise it is refused withLOCK_CONFLICTand switches, records and deletes nothing.beginBuild, so a lock whose session ended is no longer kept.N3. A pgvector search that meets three generation switches is refused with
CONCURRENT_MODIFICATION(409). The rows forCONCURRENT_MODIFICATIONandLOCK_CONFLICTleavescripts/error-status-unpinned-baseline.json.check:error-status-conformancerequired theLOCK_CONFLICTremoval too, because the new pgvector refusals declare its status.N2. Measured live:
beginBuildunder the active fingerprint already retires a building generation of another fingerprint. This PR pins that with a live test and states it in the docs; no code change was needed. What remains is that no build is due after a revert (readIndexStatereadscurrent), so the stale generation stays until the next build of any kind. See Acceptance notes.N4 is not implemented. Two sweeps of one retired generation need two lock holders at once. The fence now refuses a lapsed builder's
completeBuild, andbeginBuildsweeps only under a freshly checked lock.knowledge-turso (measured, not changed). It has no builder lock:
beginBuildtakes up any generation under the same fingerprint, so there is no builder identity for an "own generation" check beyond the fingerprint, whichcompleteBuildalready requires. Its cluster-lease protection is the service-level fence in this PR.CLI. The CLI's
KnowledgeBuildView.statustype and therebuild.tscomments listlease-lostandtimed-out. No runtime change: a followed rebuild already exits 1 on any status other thandone.Docs.
content/docs/ai/knowledge-rag.mdxadds generation item 6 (the pgvector fence), extends item 5 (the reverted fingerprint) and adds a paragraph on the two stops in "The first build, and rebuilding a source". That paragraph'slease-lostsentence links back to item 5: on pgvector, the stopped build's builder lock stays with its node until the idle time passes. None of these sections is one that #37442 edits.Widening. The exported
KnowledgeBuildRecord.statusgainslease-lostandtimed-out. Nothing else becomes newly exported from the package entry.Files to read first (by risk)
packages/services/service-knowledge/src/knowledge-service.ts,rebuildSourceand the privatecompleteBuildhelper: the race onfence.cancelled, the status taken fromfence.stop()when the walk returnsok: false, andfence.completing()before the unracedadapter.completeBuild.packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts:holdsBuilderLock(thepg_lockskey split intoclassid/objid) and thecompleteBuildown-generation check.packages/services/service-knowledge/src/knowledge-build.ts,startBuildFence: the local lease expiry (heldUntil) for a renewal that never settles, andcompleting()(the bound disarmed for good).Two-minute verification
pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/knowledge-build-fence.test.tsshould report 14 passed. The first case shows 1 page embedded of 3 andlease-lost. The stall case showstimed-outat 15 minutes of fake time, then a next build that completes. The completion case shows a build stillrunningat 30 minutes, thendone, with the secondbeginBuildonly after it.Tests
Local readings
knowledge-build-fence.test.ts(new, 14 cases):findcalled once,completeBuild0,lease-lost, released once;lease-lost;lease-lost;timed-outat the bound, lease released, the next builddone;done;runningwith its lease kept; a rebuild asked meanwhile answers the same running record; a complete walk asked meanwhile does not callbeginBuilduntil the completion settles; thendone, the lease released once, and the queued walk'sbeginBuildruns second;done,purged: 3;timed-outwith no complete, then a second builddone;timed-out; the second build alsotimed-outat its purge, with no second removal call and no complete; once the hung removal answers, the document is gone and a third build isdone;timed-outat the bound, lease released, nobeginBuild;close()disarms the bound;completing(),cancellednever settles andprogressed()does not re-arm the bound.src/commands/knowledge/knowledge.test.ts7 passed.OS_EXPECT_LIVE_DIALECT_MATRIX=1): Test Files 8 passed, Tests 83 passed, against 76 before this PR. New:build-fence.live-postgres.test.ts(6 cases) andsearch-switches.test.ts(1). Typecheck exit 0.git restore:fenceBuilddisabled: 2 live cases red;completeBuildhelper disabled: the lease-lost-during-purge case red.fencedCallaround the purge or the listing removed, one at a time: the matching hung-call case red each time (the second build waits behind the chain).fence.completing()removed, and separately the old race aroundcompleteBuildrestored: the completion case red each time.unboundedguards in the fence removed: thecompleting()unit case red.rebuildSource's race of the whole walk replaced by a plain await: the queued-build case red. Before that case was added, this ablation stayed green: the walk's own fenced calls cover everything but the wait in the source's queue and the unfencedplanIndexand tenancy reads.Acceptance notes
buildLockIdleMs.running, its lease renewed and the source's walk chain held, until it answers or the process restarts. That is the price of never starting a build on this node beside an old switch or sweep. The docs name it.AdapterContexthas no abort signal, and adding one would be an ADR-0161 contract member, which this PR does not add. If such a call answers later, its page is written; for pgvector that write is still fenced by the builder lock.readIndexStatereadscurrent, so no build runs and the stale building generation stays until the next build. Retiring it without a build would needindexStatusor a read-time sweep. Not done here.SERVICE_UNAVAILABLE503 ("the store is not ready"), while pgvector now answersCONCURRENT_MODIFICATION409 for the same condition. Parity card knowledge-turso: search exhaustion after generation switches answers CONCURRENT_MODIFICATION 409, like pgvector #37597 (p3, sub of service-knowledge: a build that loses its lease stops at the next page, and a build has a time bound #37465) codes itCONCURRENT_MODIFICATION409; this PR leaves turso alone.timed-outin turn, completing nothing, until the removal answers or the process restarts. That document's event sync waits behind it too. Keeping the per-document chain is deliberate: freeing it would let a late delete race the event sync of that document. The hung-purge-removal test asserts exactly this, with a store that keeps listing the document.knowledge-service.tsedits stay insidewalkObjectSourceandrebuildSource, plus the import block, a one-parameter pass-through inreindexWiththat threads the fence, and the privatecompleteBuildhelper (its fence check andfence.completing()). None of these touches the regions feat(core): requires knowledge mounts the knowledge service and one vector store #37442 edits; overlap-check reports a clean merge.Verification
VERDICT clean exit 0against origin/main (54d6726), feat(core): requires knowledge mounts the knowledge service and one vector store #37442 and fix(cli): os knowledge rebuild and status give the right answer behind a load balancer #37578 (which sharesrebuild.ts). No merge of main was needed.--repo objectstack-ai/objectstack):--ranreconciliation reports 111 run and 1 NOT MEASURED,check-plugin-teardown-shape --self-test, a recorded exit 3 (PREREQUISITE NOT MET: shallow clone).Generated by Claude Code