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) |
…a type with its loader, its registry and two authoring guards (objectstack-ai#37676) <!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgHittdG1nUD4Ne4ozfqAXgk)_ Fixes objectstack-ai#37304 Clause-②: yes (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up objectstack-ai#37310 ## 维护者速读 - 用户能看到什么变化:知识源成为一种正式的应用配置,可以随应用一起发布,也可以在 Studio 里新建和修改;保存后平台自动建立、更新或清除对应的检索索引。旧写法升级时会被明确拒绝,迁移命令会列出每一处要改的地方。 - 为什么做:属于“知识检索平台化”专题,让应用写一份知识源配置就有可用的检索,并且谁能建知识源、能索引哪些数据都有人管。 - 出错会怎样:只影响用到知识检索的应用。旧配置没迁移时会报出要改的位置,不会悄悄丢数据或建错索引;新增的“管理知识源”权限默认只有平台管理员有;回退本改动即可恢复原状。 - 要你做什么:批准一次。这是一次不兼容的协议收紧,改了两份对外技能文件(各一两行),改动量也超过三千行,按规则要你批准后才能合并。 ## What changes **New metadata type: `knowledge_source`.** Registered in the metadata type registry with the one schema `KnowledgeSourceSchema`; a stack carries its sources in the new top-level collection `knowledgeSources` (`*.knowledge-source.ts` or `.yml`). An item can be created and changed at run time (Studio, MCP) and takes no environment overlay. Studio's menu lists the type under AI, and ADR-0084's type table carries its row. **New platform capability: `manage_knowledge_sources`.** Platform administrators hold it by default. Nothing else grants it. - **The schema is strict.** An undeclared key is refused. `id` becomes `name`, `source.contentFields` becomes `source.content`, a non-empty list of field names; `'*'` is refused with the instruction to list the fields, and an empty-string member is refused too (it names no field). `embedding`, `vectorStore`, `adapterConfig`, `refresh.cron` and the `file` / `http` source kinds are retired with their ADR-0087 entries (three conversions, six retired keys, six retired defs, four semantic entries on protocol 19). `os migrate meta --from 18` lists every edit and `--write` applies the ones it can prove. - **The loader** (`service-knowledge`, `knowledge-source-loader.ts`). `KnowledgeServicePlugin` reads the published items when it starts and follows the type while it runs: an added source is registered and built when a build is due; a changed one is registered again (a changed `where` or `metadataFields` rebuilds inside the generation, a changed `content` or `split` builds a new one); a removed one is unregistered and its index dropped. The reap guard's object set follows the sources. - **The registry** (`knowledge-source-registry.ts`), under the maintainer's rulings on this card (record 7192063608, forks 6 and 4d, both A). A source is held by `(package, name)`. A source registered in code belongs to no package; it shares one slot with an environment-authored item of the same name, and the second of the two to arrive is refused `409 RESOURCE_CONFLICT`, naming both doors. A package's source of the same name is a second source. Code names a source by its face: the bare name for the package-less one, `NAMESPACE-NAME` for a package's; a bare name several sources answer to is refused `409`, naming the candidates. `search` hits carry the face as `sourceId`. No `IKnowledgeService` signature changes for addressing. - **`IKnowledgeAdapter.dropSource?(ctx)`**, implemented by `knowledge-memory`, `knowledge-pgvector` and `knowledge-turso`; the contract suite (`@objectstack/service-knowledge/testing`) takes `implements.dropSource`. An adapter reads the source's index key from `ctx.source.name` (it was `ctx.source.id`): the bare name for a package-less source, so an existing index is found under the same key and nothing is rebuilt. - **Guard one: the capability.** A write of a `knowledge_source` through `/meta` (REST and the dispatcher: save, publish, rollback, delete) and through the MCP draft door needs `manage_knowledge_sources` beside `manage_metadata`: `403 PERMISSION_DENIED` naming the capability, `401` for an anonymous caller. It is one row in the existing per-type table `META_TYPE_WRITE_CAPABILITIES` (`packages/rest/src/meta-item-read-gate.ts`), so the three doors that already ask that table ask it for this type too. The package doors ask it as well (maintainer's ruling A, record 7207325373 on objectstack-ai#37304): each of the twelve doors that write an existing package (enable, disable, publish, publish-drafts, discard-drafts, the commit revert, rollback, revert, adopt-orphans, duplicate, the manifest update, delete) refuses a caller without the capability `403` when the package holds a knowledge source: an item, a pending draft, or, for the commit revert and the rollback, a commit that touched one. A package that holds none is written as before; a holding that cannot be read refuses `503`. Two doors are not asked, see Acceptance notes. - **Guard two: source admission at save.** The same doors save a source only when its author may themselves search what it would index: an object of a disabled package, an object the API does not serve for `search`, a system object without `enable.aiReadable`, or a field the author may not query refuses the save `403`, naming the object or the field; a verdict that cannot be reached refuses `503`. The fields a source's `where` reads are judged with the fields it serves, at save and at search. A knowledge service that is registered and cannot be resolved refuses the save `503` at every door (REST, the dispatcher, MCP). The duplicate door admits each knowledge source it would copy for the caller before anything is copied, and refuses the whole copy when one is refused. Over MCP the human is judged. - **The push door leaves.** `IKnowledgeService.indexDocument` and `deleteDocument` are removed with the `file` / `http` branches that served them. - **Removed exports**, twelve names from `@objectstack/spec/ai`. The `embedding` module: `EmbeddingModelSchema`, `VectorStoreSchema`, `VectorStoreProviderSchema` and the types `EmbeddingModel`, `VectorStore`, `VectorStoreProvider` (the knowledge source was their only composer). The retired source kinds: `FileKnowledgeSourceSchema`, `HttpKnowledgeSourceSchema`, `KnowledgeSourceKindSchema` and the types `FileKnowledgeSource`, `HttpKnowledgeSource`, `KnowledgeSourceKind`. The changeset lists the same twelve. - **Boot notice** (`packages/objectql`). A deployment that holds `knowledge_source` items and mounts no knowledge service says so once at boot, at warn, naming the items; it is not a boot refusal. - **CLI.** `os knowledge status` prints the package that holds a source and no longer a source kind. - **Showcase.** `examples/app-showcase` ships `showcase_task_notes` (object `showcase_task`, adapter `memory`) and mounts the knowledge service and the memory store. - **Docs.** `content/docs/protocol/knowledge.mdx` and `content/docs/ai/knowledge-rag.mdx` describe the type, the loader, who may author a source, and one name per source; the generated references follow. - **Skills (Tier H), enumeration row only**, under ruling A on objectstack-ai#32584: `knowledgeSources` joins the top-level key list in `skills/objectstack-platform/SKILL.md`. `skills/objectstack-ai/SKILL.md`'s compiled `supportKb` example changes two keys (`id` to `name`, `contentFields` to `content`) because the old spelling is now refused at parse. Teaching the type (prose, tables, evals) rides objectstack-ai#37310. - **One ceiling, raised by the row's measured delta and by no more** (`scripts/check-skills-token-ratchet.mjs`): `skills/objectstack-platform/SKILL.md` was at zero headroom (24603 priced bytes, 6151 tokens, after objectstack-ai#37442's row); the `knowledgeSources` row adds 20 bytes, so the priced text is 24623 bytes, 6156 tokens, and the ceiling moves 6151 to 6156, pinned at the measurement. Nothing else in the file is cut and nothing rides along. `skills/objectstack-ai/SKILL.md` stays at 6799 tokens under its ceiling of 6801. - **The two rulings the raise path names**, quoted: - Ruling A on objectstack-ai#32584 (record 6819475461): "a product PR that adds an authorable `defineStack()` top-level key, or a live member of a schema symbol bound to a registered exhaustive skills section, carries the matching skills enumeration row in the same PR. Only that row; prose, examples and evals still go to the skills sub-card." - objectstack-ai#32673 letter A (record 6840575378): "a PR that adds a metadata key and, under ruling A on objectstack-ai#32584, carries the matching enumeration row in a published skill may raise that skill file's token cap by the row's measured delta, and by no more. The PR body cites ruling A and this ruling. Nothing else in the file is cut to make room, and no wider raise rides along." ## Tests - `packages/spec/src/ai/knowledge-source.test.ts`: the strict schema, `'*'` refused, an empty-string member refused (and `minLength: 1` in the JSON Schema), every retired key answered with its prescription. - `packages/services/service-knowledge/src/__tests__/knowledge-source-registry.test.ts` (new): the slot rules above, both orders of arrival at each door, face resolution and the `409` with its candidates. - `.../knowledge-source-loader.test.ts` (new): boot read, add, change (each of the two rebuild arms), remove with `dropSource`, an adapter without `dropSource`, the reap guard following the sources. - `.../knowledge-source-admission.test.ts`: each refusal of guard two and its fail-closed `503`; the fields `where` reads (keys, `$and` / `$or` / `$not`, `{ $field }` comparands) judged at save and at search. - The adapter contract suite with `dropSource: true` in `knowledge-memory` and `knowledge-turso`; `knowledge-pgvector` declares it in `contract.live-postgres.test.ts` (see Remaining). - `packages/rest/src/meta-type-write-capability.test.ts`: every write shape of a `knowledge_source` for a caller with `manage_metadata` alone, with `manage_platform_settings`, and with a record grant: `403 PERMISSION_DENIED`, store unchanged, no protocol call; a holder of both saves, publishes, rolls back and resets; the capability without `manage_metadata` is refused by the door's own admission. - `packages/rest/src/meta-write-door-capability-enumeration.test.ts`, `packages/runtime/src/domains/meta-save-capability-gate.test.ts`, `packages/runtime/src/domains/mcp-authoring.test.ts`: guard two at REST, the dispatcher and the MCP save door (the human is judged); on a real kernel, a knowledge service whose factory throws answers `503` at the dispatcher and at MCP, and one never registered is not asked. - `packages/runtime/src/domains/meta-type-write-capability-parity.test.ts`: REST and the dispatcher answer the same for the new row. - `packages/runtime/src/domains/packages-knowledge-source-gate.test.ts` (new): each of the twelve package doors refuses a `manage_metadata`-only caller when the package holds a source (item or draft) and the writer never runs; a holder goes on with no listing read; a package with none answers as before; a listing that throws refuses `503`; the engine's own call is not asked; the commit revert and the rollback read the timeline; the duplicate door's admission of each copied source; a host with no metadata store holds none; the install door and the ensure-customization door are not asked. - `packages/runtime/src/domains/packages-ensure-customization.test.ts`: a base that holds a knowledge source (a registered item and a stored row) gets a pair that holds none, and the door writes one manifest and no row. - `packages/objectql/src/knowledge-source-unserved.test.ts` (new): the boot notice. - `packages/metadata-core/src/knowledge-source-save-admission.test.ts` (new): the admission seam. ## Acceptance notes - **Governed (Tier H) and over 3000 changed lines**: draft until the maintainer's approval. The diff touches `skills/**` and declares a narrowing. - **Rulings this PR implements**: record 7192063608 on objectstack-ai#37304 (forks 6 and 4d, both A); earlier on the same card Q1 = B (the type sits in ADR-0150's bucket 3) and Q2 = B (`manage_knowledge_sources` beside `manage_metadata`, platform administrators only); and ruling A of 2026-11-27 (record 7207325373): every write door of an existing package asks the capability when the package holds a knowledge source, and install stays unasked. The ADR-0150 rows ride objectstack-ai#37545. One ADR line is edited here, with the zone's approval (claim comment 7203310811 on objectstack-ai#37304, amended by 7204020473): ADR-0084's type table gains the `knowledge_source` row its item 6 prescribes for a type registered after the ruling (AI, `ai`, 5, 高级), spelled as the `ai_context` row is. Nothing else under `docs/adr/**` changes. - **The loader's signal** is `protocol.onMetadataMutation` (a save, a publish, a delete, a revert) plus the `metadata:reloaded` hook (a package published, installed or removed, a dev reload), not `metadataService.subscribe`. After either it reads the published set again and reconciles, so a missed event is repaired by the next one. - **Guard two is not asked where no knowledge service is mounted** (there is nothing to ask, and the item is inert there), nor for a system write. - **Two package doors are not asked the new capability (limits).** The install door (`POST /packages`): a package's source arrives by that door's own admission, as the ruling leaves it. The ensure-customization door (`POST /packages/:id/ensure-customization`): it writes nothing of the base and creates an empty pair, so it creates, changes and removes no knowledge source; the seat confirmed this reading on the condition that the pair holds no source, which `packages-ensure-customization.test.ts` pins. - **The package gate reads before it answers.** For a caller without the capability the twelve doors read the package's drafts and items (and its commits, for the two timeline verbs) before the door's own request checks. A host with no metadata store at all (the table was never created, or the engine holds no `sys_metadata` object) reads as holding none, by the same rule the protocol's overlay reads use; any other failed read refuses `503`. - **The read-side author exemption** stays keyed on `manage_metadata`. - **A bare name two sources answer to** is refused `409` at the call that names it (`resolveSourceRef`), listing the candidates; both sources register. Where the host cannot place a package's namespace, the package's face is its bare name, and that name answers `409` for both sources until the package is placed. - **The four narrowings the ADR-0150 addendum asks this card to declare, each counted on this tree**: the install refusal inside a namespace (two packages of one namespace holding a source of one name): 0. The name grammar (a source whose name the grammar refuses): 0. The `409` for a bare name two packages hold: 0. The package-less row under a name a package holds: 0. The tree holds one knowledge source, `showcase_task_notes` (`examples/app-showcase/src/ai/task-notes.knowledge-source.ts`), and no first-party code registers one through the plugin door. - **`KnowledgeIndexStatusEntry.kind` is removed** with the source kinds; `packageId` is added. - **One ADR-0087 marker.** The gate allows exactly one marker per breaking changeset, so the changeset carries `registered …` and names `indexDocument` / `deleteDocument` in prose: they are runtime-interface members with no metadata form, and the compiler reports each call (`TS2339`). - **The boot notice adds one boot read** of `knowledge_source` rows on a kernel that does not hydrate from its database; it registers nothing (`plugin.integration.test.ts` pins the permitted reads and now names this one). - **pgvector `dropSource` and a concurrent build in another process**: the drop retires the active and the building generation in one transaction but does not hold the builder lock across it, so a build already running in another process could still write its generation afterwards. Not changed here; it is a candidate follow-up. - **objectstack-ai#37479 (unregistered adapter) is not folded in.** The loader runs after publish, so it is not a refusal point for publish; objectstack-ai#37442 adds the coded refusal for an unmounted adapter. - **The showcase mounts the two plugins by hand** rather than declaring `requires: ['knowledge']` (objectstack-ai#37442): the token mounts a libSQL or pgvector store, which needs a configured embedder, and the demo runs on the in-memory store with none. A host that mounts the service itself keeps its own, as objectstack-ai#37442 specifies. - **Merged with `main` three times** (no rebase). The first merge (at `45ed022b`) followed objectstack-ai#37442, objectstack-ai#37570 and objectstack-ai#37578: four textual conflicts (the migration registry template, the CLI knowledge test fixture, the pgvector adapter's search refusal, the knowledge service's reindex chain and unmounted-adapter refusal). Code and fixtures those PRs wrote against the 18 source shape follow the 19 shape here: `source.id` is `source.name`, `contentFields` is `content`, `reportUnmountedAdapters` names a source by its face, and the unmounted-adapter index test calls `reindexSource` now that `indexDocument` is gone. The second merge (at `c2bfa3ef7`) was forced by a conflict: `main` had gained its own protocol 19 conversion (`permission-view-all-fields-beside-record-bypass`), so the conversion registry, the migration registry template and the retired-key pin now carry both sets, sorted as the registry sorts them; `packages/spec/authorable-surface/ai.json` was merged three ways by hand so that this PR's removals and `main`'s new `ai/Skill:context` both stand; every generated spec surface was regenerated afterwards. The third merge (at `8b9b9d235`) was forced by objectstack-ai#37723, which moved the ADR-0150 D3 rule into `packages/metadata-core/src/package-scoped-resolution.ts`: `core`'s file is taken from `main` (a re-export) and the `knowledge_source` row with its comment sits in `metadata-core`'s `PACKAGE_SCOPED_TYPES`; `default-changes.ts` keeps both protocol 19 entries (`main`'s `ai/AIModelConfig:provider` and this PR's `ai/KnowledgeSource:refresh`); the Studio menu placement pin takes `main`'s move of `position` and keeps this PR's row. The merge is its own commit and `packages/spec/authorable-defaults/ai.json` was regenerated in the next one (`737f44341`). - **The declared default of `ai/KnowledgeSource:refresh`** sits under major 19 in `default-changes.ts` (no parsed value changes: the published JSON Schema now states the `{}` the parser always applied). - **Enumeration pins found by CI, not by the first local pass.** The first head was verified on the packages the change edits. CI then failed on tests in packages it does not edit, each a list that counts metadata types or the platform administrator's capabilities: the owner-stamp boot fixture and the unbundled-type list (`packages/metadata`), the tier list (`packages/metadata-protocol`), the type-label counts (`packages/platform-objects`), four golden grant lists (`packages/plugins/plugin-security`), and the generated `zh-Hant` locale. Each gained the one entry; no product code changed for them. The suites of those packages and the workspace type check now run locally as well (see Verification). - **Review round 1.** The contract review on `45ed21271` (comment 7206413701) read PASS with findings, and the seat ordered a rework (7206423476). This head answers it: authoring guards cover more doors and more of what a source reads (the package doors, the duplicate door, the fields `where` reads, the service lookup at the dispatcher and at MCP), the `content` member refuses the empty string, the changeset lists the twelve removed exports, and this body is corrected on the face collision and states the narrowing counts. The findings' detail is with the seat. Two nits are carried by cards the zone files under objectstack-ai#37304 (ADR-0084 prose; tombstone wording for code-door registrants). - **Existing tests edited outside the card's first surface** (claim amended by the zone, comment 7207505784 on objectstack-ai#37304), each because a package door now reads the package for a caller without the capability: - `packages-publish-drafts-request-conformance.test.ts`: the real-protocol case's caller also holds `manage_knowledge_sources` (its engine is one nothing may touch; the case pins the protocol's own order). Assertions unchanged. - `packages-publish-drafts-probe-caller-context.test.ts`: the protocol double gains a `getMetaItemsPerPackage` stub beside its `getMetaItems` stub. Assertions unchanged. - `package-state-host-store.test.ts` (a kernel with no driver) and `domains/error-passthrough.test.ts` (a protocol double that throws from every member): the caller also holds `manage_knowledge_sources`. Assertions unchanged. - `packages-ensure-customization.test.ts`, "duplicate: 400 before a row is read": **the measure changes.** The door now reads the source package's knowledge sources to admit them before the copy runs, so the case counts the reads made inside `protocol.duplicatePackage` (still 0) instead of every engine read; it also asserts the copy was entered once. - **Open PRs that will conflict with this one** (overlap-check on this head against 12 open PR heads; `main` itself merges cleanly): objectstack-ai#37422 (the generated references and `scripts/check-skills-token-ratchet.mjs`: whichever lands second re-measures the row), objectstack-ai#37366 (`packages/spec/export-origins/ai.json`). Whichever of each pair lands second merges `main`. ## Verification First files to read, by risk: 1. `packages/services/service-knowledge/src/knowledge-source-registry.ts`: the slot and face rules. 2. `packages/services/service-knowledge/src/knowledge-source-loader.ts`: what each metadata event does to an index. 3. `packages/rest/src/meta-item-read-gate.ts` (`META_TYPE_WRITE_CAPABILITIES`) and `packages/metadata-core/src/knowledge-source-save-admission.ts`: the two guards. 4. `packages/runtime/src/domains/packages.ts` (`refuseKnowledgeSourcePackageWrite`, `refuseDuplicatedKnowledgeSources`): the guards at the package doors. Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-source-registry.test.ts src/__tests__/knowledge-source-loader.test.ts`. Head `cf128e59f` (review round 1). Verified so far on this head, locally, every heavy run under `scripts/pm/os-verify-lock.sh`: build exit 0; `@objectstack/runtime` full suite exit 0 (657 files, 13676 passed, 25 skipped); `@objectstack/metadata-core` and `@objectstack/core` exit 0; `tsc --noEmit` on `packages/runtime` exit 0. Running now on the same head, and written here when they end: the other package suites, the workspace type check, the derived gates, the full dogfood battery and the ablations. CI on this head is in progress. The previous head's readings (`45ed21271`: 62 check runs green, 185 gates, the dogfood battery, six ablations) are in the os-dev report, comment 7206197293 on objectstack-ai#37304. <details><summary>Skills readings (the diff touches <code>skills/**</code>)</summary> | | Lines before | Lines after | Tokens before | Tokens after | |---|---|---|---|---| | `skills/objectstack-platform/SKILL.md` | 421 | 421 | 6151 | 6156 (ceiling 6156) | | `skills/objectstack-ai/SKILL.md` | 486 | 486 | 6799 | 6799 (ceiling 6801) | | All `SKILL.md` files together | 4961 | 4961 | | | | Ratcheted (authored) bundle | | | 199660 | 199665 (ceiling 204478) | `skills/objectstack-ai/references/_index.md` is generator-owned (53 lines to 52: the embedding module's row leaves, the knowledge source's row is reworded) and is measured, not ratcheted. "Before" is `main` at the third merge (`8b9b9d235`), read with the same script; the bundle's before figure is this tree's reading less the row's 5 tokens. </details> ## Remaining - The same reviewer's read of the round 1 delta (`45ed21271..cf128e5`), then the seat's hand-off. - `knowledge-pgvector`'s `dropSource` contract cases have not run anywhere yet: there is no pgvector in the build container, and the job with a PostgreSQL service does not run on `pull_request`. Their first run is the merge queue. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CZe3KTAXogcUJuvYEx <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CZe3KTAXogcUJuvYEx --> --------- Co-authored-by: Claude <noreply@anthropic.com>
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