Repository navigation
feat(core): requires knowledge mounts the knowledge service and one vector store - #37442
Conversation
…ne store Claude-Session: https://claude.ai/code/session_01JQwxbWZjh7mWMsJZHnGWwZ Co-authored-by: Claude <noreply@anthropic.com>
…ector store PostgreSQL gets pgvector on the same database; any other database gets turso on .objectstack/data/knowledge.db. A store URL saved in settings is held to the data directory and refused on a NUL byte before libSQL. A source naming an unmounted adapter: boot ok, index/search answer 503. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbWZjh7mWMsJZHnGWwZ
📓 Docs Drift CheckThis PR changes 7 package(s): 20 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 7 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 195 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 a4017266130017484799eddbe0df1683a03c01bd && git checkout a4017266130017484799eddbe0df1683a03c01bd
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 58570d8002dd213f7f65525d881ac935583f4050 c25cc1a488a190f156d006964a14bcfbc0275d3e && git checkout -B drift-repro 58570d8002dd213f7f65525d881ac935583f4050 && git merge --no-ff c25cc1a488a190f156d006964a14bcfbc0275d3e
node scripts/docs-audit/affected-docs.mjs --json 58570d8002dd213f7f65525d881ac935583f4050
|
…apped Claude-Session: https://claude.ai/code/session_01Utp6CYE8s5v1UX96GEfkcR Co-authored-by: Claude <noreply@anthropic.com>
…measured delta, the serve-only step entry Claude-Session: https://claude.ai/code/session_01Utp6CYE8s5v1UX96GEfkcR Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6CYE8s5v1UX96GEfkcR Co-authored-by: Claude <noreply@anthropic.com>
…ollection Claude-Session: https://claude.ai/code/session_01Utp6CYE8s5v1UX96GEfkcR Co-authored-by: Claude <noreply@anthropic.com>
…-pvvkab The one conflict, the requires-table row of skills/objectstack-platform/SKILL.md: main's provider cell kept whole, the bare knowledge token added after record-context. Priced bytes 24593 on main, 24605 here. Claude-Session: https://claude.ai/code/session_01Utp6CYE8s5v1UX96GEfkcR Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head abf337b · 2026-11-26T09:07Z |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: Inputs read: card #37102 body and all 6 comments (claim 7182935868, hand-off 7183577702, take-over 7184318627, amend 7184431271, os-dev report 7187364220, triage 7143836781); the PR body and its 38-file net diff against ① Derived judgments
② Semver level
③ Boundary flagsDev flags and reviewer notes
Security
SQL push-down
Escalation for the seat (not graded, outside the inputs)
④ Design judgment
Findings M1 (must-fix) — A saved
S1 (should-fix) — The PostgreSQL acceptance row has not executed on any commit of this PR, and the PR body says it has.
S2 (should-fix) — The arm
S3 (should-fix) —
S4 (should-fix) — "beside the dev database" is false under
N1 (nit) — N2 (nit) — With the fix for S4 aside, the settings example N3 (nit) — The step comment in Not broken, tried: path escape through Implemented-by: VERDICT: FAIL |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha:
|
…sed; the store follows OS_HOME; the libSQL store is an optional dependency Rework after the contract review of abf337b (record 7187791236). - M1: resolveStoreUrl and resolveSettingsStoreUrl refuse a control character behind a percent escape too. libSQL decodes the path it opens, so a saved file:.../k%00.db reached the native client as a NUL byte and ended the process at every boot. - S2: one real-kernel case for the file-database arm: the store opens the file the operator saved and a record write is found by search. - S3: @objectstack/knowledge-turso is an optional dependency of the CLI and of @objectstack/verify. The store's row and extra carry optional: true; verify warns and goes on where it cannot be imported, as serve does. - S4: the store's data directory follows OS_HOME (os start --home), the directory the default platform database is kept in. New option stateDir. - Docs: where the file is, more than one replica, an install without the libSQL client. Claude-Session: https://claude.ai/code/session_01Utp6CYE8s5v1UX96GEfkcR Co-authored-by: Claude <noreply@anthropic.com>
…owledge rebuild and status (objectstack-ai#37439) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ83sWXVVPC33q8uBsTDHaebw)_ Fixes objectstack-ai#37099 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 用户看到的:知识库数据源第一次部署、或换了嵌入模型 / 索引配方之后,服务启动后会在后台自动把它建好索引,不用再等每条记录被改一遍才能搜到;管理员也可以用命令行手动重建某个源、查看每个源的索引状态和进度。 - 为什么做:属于「知识检索平台化」专题,让知识源开箱即可检索;以前一个从没建过索引的源,搜索永远是空的。 - 出错会怎样:建索引会把匹配到的内容发给嵌入服务商并产生费用;默认的内存存储每次重启都会整源重建、每个节点各建一次,只有配置了共享集群锁才是一个节点建;可以用插件开关关掉开机自动建,回退就是撤掉这个改动。 - 要你做什么:无。 ## What changes **First build after boot** (`@objectstack/service-knowledge`) - `KnowledgeService.readIndexState(source)` reads ADR-0161 K7's table for one source: the adapter holds nothing, a different fingerprint, a different recipe hash, no recipe hash, current, or (an adapter without `indexStatus`) whether `listDocuments` lists anything. Each reading says whether a build is due. - `KnowledgeService.buildSourcesAtBoot()` runs from the plugin's `kernel:bootstrapped` hook, after the embedder is provided, without holding up the boot. It walks the sources one at a time and builds each one a build is due for. A source with `refresh.onRecordChange: false` (an external indexer owns it) is skipped. A state it cannot read, or an adapter that cannot say, is logged at warn and left alone; the operator rebuild is the way for those. - **One node builds.** `rebuildSource` takes the cluster lock `knowledge:build:SOURCE` (`ILock`, 60 s lease renewed every 20 s, `waitMs: 0`). A node that finds the lock held records `not-run` and builds nothing. A node that gets the lock re-reads the state first, so a node arriving after another finished builds nothing either. If the lock service errors, no build starts and the node warns. Without a `cluster` service (single process) the build runs without a lock. - Each build logs one cost line at its start (every row the source's `where` matches is read, and its content fields are sent to the embedding provider, which bills for them), progress at most every 10 s, and its totals at the end (info) or why it did not finish (warn). - New plugin option `buildAtBoot` (default `true`). `false` turns the boot pass off; the operator rebuild still works. **Operator rebuild** - Two actions on the `knowledge` settings namespace, beside `test`: `rebuild` (`{ source }`) starts a build and answers at once; `index_status` (`{ source? }`) answers each source's index reading and the last build record on this node, with its progress. Both go through the settings action door, so both need `manage_platform_settings`. A second rebuild of a source already building on this node is refused. - `os knowledge rebuild SOURCE` starts one and follows it to its end by polling `index_status` (`--no-wait` to return at once, `--interval`). It exits 1 when the build failed or did not run, or when the answer comes from a node that is not running this build. - `os knowledge status [source]` prints each source, its index state and its last build on the node that answered. **Docs**: `content/docs/ai/knowledge-rag.mdx` gains "The first build, and rebuilding a source": the K7 table, what one build costs (a warn callout), how to turn the boot pass off, and the two commands. **Rework round (seat L1 REWORK, contract record PASS with should-fix findings)** - **S3, the admin gate is pinned.** `knowledge-settings-contribution.test.ts` gains "the rebuild and index_status actions are administrator-only, at the HTTP door": a real `LiteKernel` with `KnowledgeServicePlugin` and `SettingsServicePlugin`, driven through `registerSettingsRoutes` and the real `SettingsService.runAction`. A signed-in caller without `manage_platform_settings` (an organization member holding `setup.read` / `setup.write`, or one with no capability) gets `403 SETTINGS_FORBIDDEN` for `rebuild` and `index_status`; an unauthenticated one gets `401 UNAUTHENTICATED`. No refusal names the source (id or label), and no handler method on the service (`listSources`, `getSource`, `readIndexState`, `rebuildSource`, `buildRecord`) is called. A control shows the same door lets an administrator through and then names the source, and the in-process `runAction` with an enforced member context rejects with `SETTINGS_FORBIDDEN`. The gate itself is unchanged; it still lives in the `knowledge` manifest's `writePermission`, and relaxing it now turns these pins red (ablation below). - **S4, the cost callout** in `content/docs/ai/knowledge-rag.mdx` now says the default `memory` adapter holds nothing after a restart, so with it every boot is a first build that re-embeds the whole source on every node; and that "only one node builds a source" holds only with a shared cluster lock driver, because the default `memory` cluster driver's lock is a per-process mutex. The paragraph above the callout now qualifies its "only one builds" sentence the same way and links the cluster page. The changeset says both. - **S6, the CLI reference.** `content/docs/deployment/cli.mdx` gains a `### Knowledge` section after `### MCP`, in the shape of the other command groups (overview table, one `####` per command with examples, a flag table): `os knowledge status` and `os knowledge rebuild`, their exit codes, the admin-only door, and the per-node build record. - **Nits fixed:** N2 (`os knowledge rebuild --no-wait` now prints that it reports no outcome and points at `os knowledge status`; the flag help and the CLI reference say so), N3 (`buildSourcesAtBoot` lists the sources inside a `try` and resolves with a warn when it cannot; the plugin's `void` call carries a `.catch`), N5 (an adapter reporting `{ building: true }` with no active fingerprint, a first build that never completed, now reads `nothing` with its own sentence instead of `new-fingerprint`). N1 (the optional `protocol/knowledge.mdx` pointer) stays an accepted deviation. - **Carded, not fixed here:** S1 (a lease that lapses mid-build only warns and the walk goes on unfenced; a build whose embed call never returns renews forever) is objectstack-ai#37465. S2 (build records live in memory per node, so behind a load balancer `os knowledge rebuild` can exit 1 on a poll that lands elsewhere) is objectstack-ai#37466. S5 (retiring the field gate's `title` arm) is objectstack-ai#37467. ## Why A source that was never built had an empty index until each of its rows was written again; search found nothing and nothing said why. After an embedder or recipe change the index stayed stale the same way. ADR-0161 K7 says what starts a rebuild; nothing ran it. ## Tests - `packages/services/service-knowledge/src/__tests__/knowledge-build.test.ts` (20 tests): every `readIndexState` reading; a fresh source is built at boot and search finds its rows; a built source is not rebuilt; two nodes sharing one lock build once (one `done`, one `not-run`, lock released); a node arriving late re-reads and builds nothing; a lock error starts nothing and warns; `onRecordChange: false` is skipped; a failed build is logged at warn and stays due; the `rebuild` and `index_status` actions (progress, result, an operator rebuild skipping unchanged documents, a running build refused, bad payloads refused); the plugin's `kernel:bootstrapped` pass and `buildAtBoot: false`. - `packages/cli/src/commands/knowledge/knowledge.test.ts` (7 tests): both commands against bodies written by `sendOk` / `sendError`: the route and payload, following a build to its end, exit 1 on a failed build, on a server refusal, and on an answer from a node not running this build; `--no-wait`. - Ablation: replacing `lock.acquire` with an always-granted handle fails the two-node and lock-unreachable tests. - Rework round: `knowledge-settings-contribution.test.ts` +10 tests (the admin-gate pins above); `knowledge-build.test.ts` +2 (N3: a listing that throws resolves and warns; N5: `{ building: true }` reads `nothing`); `knowledge.test.ts`: the `--no-wait` case now also asserts the line naming `os knowledge status` (N2). - Rework ablations, each mutated through `scripts/ablation-replace.mjs` (landing proved on disk, restore proved `git diff HEAD` empty): - S3: the `knowledge` manifest's `writePermission` set to `setup.write` in `@objectstack/service-settings`, package rebuilt (the pins read its `dist/`): the four member cases, the admin control and the in-process case turn red (6 failed, 4 passed); restored and rebuilt, 10/10 green, and the built manifest reads `writePermission: "manage_platform_settings"` again. - N5: the new branch disabled: its test red. N3: the listing failure rethrown: its test red. N2: the log line deleted: the `--no-wait` test red. All three green again after restore. ## Acceptance notes - **The `title` arm of the field gate is not retired here.** Per the 11-25 14:55Z comment it can go once a rebuild has run, but it is a security gate and retiring it needs proof per source at search time that the index was built under the current recipe. That is its own row, objectstack-ai#37467; this PR only makes the rebuild happen. - **Build records are per node.** `index_status` reports the build the answering node ran. Behind a load balancer, `os knowledge status` may reach a node that is not building; `os knowledge rebuild` says so and exits 1 rather than guessing. The index state itself is read from the adapter and is the same on every node. Sharing the record, or letting the CLI fall back to the index state, is objectstack-ai#37466. - **No Setup page button.** The rebuild entry is the CLI (and the action route it calls). A button on the Knowledge settings page is a separate UI row if wanted. - The CLI reference `content/docs/deployment/cli.mdx` now lists both commands (S6). `content/docs/frontend/cli.mdx` is not updated: it is outside this card's file surface. - A boot build runs sequentially per source and in the background; boot does not wait for it. - Lease fencing (stop the walk once the lease is lost, bound a build whose embed call never returns) is objectstack-ai#37465. ## Verification - `service-knowledge`: 14 test files / 436 tests pass; `tsc --noEmit` and `check:test-typecheck` pass. - CLI: the knowledge tests and the vitest tier partition test pass (29 tests). `eslint --no-inline-config` on every changed file passes. - CLI `tsc --noEmit`: **not measured locally**. This container has no built `dist/` for the CLI's workspace dependencies (563 TS2307-family errors, none in a knowledge file); CI owns it. - Real kernel run: two `LiteKernel`s sharing one `MemoryLock` over a 250-row source. Boot returned in 9 ms without waiting for the build. Node A: `done`, 250 indexed; node B: `not-run` ("another node holds the build"); `beginBuild` called once; search found row `r0007`; the state afterwards read `current`. A non-admin `runAction('knowledge','rebuild')` was refused ("requires the 'manage_platform_settings' capability"); an admin rebuild then showed `done` with 250 skipped. The log carried the cost line. - Derived gates: the local run's gates exit 0 except six that need a full build or full history (`check:skill-examples`, `check:dual-build-cjs-loads`, `check:i18n`, `check:i18n-coverage`, `check:i18n-walk-parity`, `check-plugin-teardown-shape --self-test`; that script's scan alone exits 0). Those six go to CI. - Overlap check against objectstack-ai#37102 and objectstack-ai#37004 (both touch `knowledge-rag.mdx`, objectstack-ai#37102 also `packages/cli`): clean at push time. The second to land merges main. <details><summary>Rework round readings, head 1061045</summary> - `service-knowledge` (dependency closure rebuilt first, `turbo run build --filter='@objectstack/service-knowledge^...'`, 18/18 tasks): `pnpm test` 14 files / 448 tests pass; `typecheck` (`tsc --noEmit` and `check:test-typecheck`, 0 files / 0 errors in the debt ledger) passes. - CLI: `src/commands/knowledge/knowledge.test.ts` 7/7 pass (unit layer). CLI `tsc --noEmit` not measured locally, for the reason above; CI's `TypeScript Type Check` owns it. - `eslint --no-inline-config` on the seven changed `.ts` files: exit 0. - Derived gates (`dispatch-gates.mjs --commands`, 122 commands, run on a753df9 with the changeset edit in the tree): 114 exit 0. Not measured here, left to CI: six exit 3, PREREQUISITE NOT MET, the same six the first round named (`check-plugin-teardown-shape --self-test`, whose positive control is pinned to a commit a shallow clone cannot reach, its scan exits 0; `spec check:skill-examples`, `check:dual-build-cjs-loads`, `check:i18n`, `check:i18n-coverage`, `check:i18n-walk-parity`, which read built output this container does not have); two whole-repo scans, `check:query-options-erasure` (its self-test passed) and `check:type-check-debt`, hit the 300 s per-command limit on the shared box. Re-run on 1061045: the changeset family (`check-adr-0087-registration`, `check-changeset-no-major`, `check-empty-changeset`, `check:changeset-fixed`), `check:nul-bytes`, `check:doc-anchors`, `check:cli-command-ids`, `check:cli-examples-parity`, all exit 0. - `overlap-check` before each push: clean against `origin/main`, objectstack-ai#37442, objectstack-ai#37422 (shares `content/docs/deployment/cli.mdx`) and objectstack-ai#35129. objectstack-ai#37004 has no PR open yet. </details> ## 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. (not touched) - [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_01JQwxbXkQAmjg7Hf74xDKA6 <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6Cb4BAjgQ43tqy1DvVJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
…on and switches to it (objectstack-ai#37492) <!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg3zXREECfPtgrM8TPQaxn1v)_ Fixes objectstack-ai#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 objectstack-ai#37465 (service lease), not this PR. - Carried, not fixed here (seat note 7188645663): N1 (fencing a builder that lost its lock) goes to objectstack-ai#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. <details><summary>Local test runs (head 06d53aa; PostgreSQL 16.16 + pgvector 0.8.7, a local instance, fresh database)</summary> - 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. </details> <details><summary>Ablations (each restored, git diff empty afterwards)</summary> - 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. </details> <details><summary>Derived gates (dispatch-gates, 102 families over the whole change)</summary> `--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, objectstack-ai#37477 and objectstack-ai#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. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6Cb4BAjgQ43tqy1DvVJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
…ge page's RAGFlow adapter option (objectstack-ai#37477) <!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgFiXLbrG7d8JVydkmtSf4Bt)_ Fixes objectstack-ai#37004 Clause-②: no (narrowing) — narrowed: `PUT /api/settings/knowledge` refuses `adapter: 'ragflow'` (`400 SETTINGS_VALIDATION`, field code `invalid_option`) and refuses `ragflow_base_url`, `ragflow_api_key` and `ragflow_default_dataset` (`400 UNKNOWN_KEY`), where it stored all four; `POST /api/settings/knowledge/test` answers `adapter = ragflow` as an unknown adapter (`400 SETTINGS_ACTION_FAILED`), where it answered a form check Metadata-protocol: none Skills-docs: updated here — `skills/objectstack-ai/SKILL.md` and its eval case 3 teach the `pgvector` adapter where they taught `ragflow`; `content/docs/protocol/knowledge.mdx`, `content/docs/ai/knowledge-rag.mdx` and `content/docs/ai/index.mdx` name the adapters this repository builds. ## 维护者速读 - 用户能看到什么变化:管理员在「知识库」设置页的后端下拉里不再有 RAGFlow 选项和它的三个配置项;以前选过它的环境,下拉显示为空,重新选一个后端保存即可。 - 为什么做:属于知识库平台边界整理;这个 RAGFlow 对接包发出的请求和对方接口对不上,绑定它的知识源从来搜不到内容,按裁决整包退役而不是修。 - 出错会怎样:还在用这个对接包的部署,升级后知识源搜索为空且只留一条警告日志;撤回这次合并即可恢复,已保存的配置一条都没删。 - 要你做什么:去掉它的版本发布之后,在 npm 上给这个包打弃用标记。 ## What changes Ruling 7134290286 on the decision card (objectstack-ai#36839), R1: the package is retired whole, in one PR, as a patch. - **Package.** `packages/plugins/knowledge-ragflow/` is deleted (9 files), with its `.changeset/config.json` fixed-group entry and its `pnpm-lock.yaml` importer. - **Settings page.** `knowledge.manifest.ts` loses the `ragflow` option, the RAGFlow group, its three keys and the `ragflow` branch of "Test connection". Manifest `version` goes 2 → 3 (the spec's "increment when keys are renamed/removed"). The strings go from all eleven locale bundles. - **Docs.** `content/docs/ai/knowledge-rag.mdx`, `content/docs/ai/index.mdx`, `content/docs/protocol/knowledge.mdx`, `content/docs/plugins/packages.mdx`, `CONTRIBUTING.md`, the `service-knowledge` README and package description, the `embedder-openai` README, `packages/spec/llms.txt` (78 → 77 published packages). - **Spec.** Comments only, in `knowledge-source.zod.ts`, `contracts/knowledge-adapter.ts` and `contracts/knowledge-service.ts`. No schema, no tombstone, no ADR-0087 conversion: `KnowledgeSource.adapter` stays a free string. - **Skill.** `skills/objectstack-ai/SKILL.md` and eval case 3 teach `pgvector` (H3 below). - **Scripts and ledgers.** Six scripts (comments, one self-test fixture URL, one debt row) and a comment in `.github/workflows/lint.yml`. ### Skill size | Reading | Before | After | |---|---|---| | `skills/objectstack-ai/SKILL.md` lines | 487 | 487 | | `skills/objectstack-ai/SKILL.md` tokens (ceiling 6801) | 6798 | 6798 | | All `SKILL.md` lines | 4961 | 4961 | | Ratcheted bundle tokens | 199596 | 199596 | Net lines in `skills/**`: +0. The eval fixture is measured, not ratcheted (3008 tokens after). ### `git grep -i ragflow` after this PR `git grep -i ragflow -- ':!**/CHANGELOG.md' ':!content/docs/releases/v17/**' ':!docs/audits/**'` answers 11 files. Each one: | File | Hits | Why it stays | |---|---|---| | `packages/services/service-settings/src/manifests/knowledge.manifest.ts` | 4 | The retired note beside `version: 3` | | `packages/services/service-settings/src/manifests/knowledge.manifest.test.ts` | 9 | Absence pins for the option, the group and the three keys; the stored-retired-adapter pin | | `content/docs/protocol/knowledge.mdx` | 1 | One "retired" row in the adapter table | | `.changeset/37004-retire-knowledge-ragflow.md` | 13 | This PR's release note | | `.changeset/33933-knowledge-settings-with-service.md` | 1 | A pending release note of another change, kept as written | | `.changeset/37292-skill-knowledge-split.md` | 2 | Same | | `CHANGELOG.md` (root) | 3 | Release history. The acceptance pathspec `**/CHANGELOG.md` does not match the root file | | `docs/adr/0161-…` | 13 | Deliberate history; `docs/adr/**` stays, apart from one anchor fix (Acceptance notes) | | `content/docs/releases/implementation-status.mdx` | 3 | Lines 311, 329, 446. Release-owned path, not edited in a code PR; the docs-only follow-up is filed as objectstack-ai#37481 | | `scripts/test-shard-timings.json` | 3 | Lines 88, 176, 276. Generated, do-not-hand-edit; the timings refresh workflow drops the rows. The partition self-test passes with them in place | | `scripts/partition-test-shards.mjs` | 1 | Line 3456, a frozen fixture of the 2026-11-02 refresh | ### Measurement (a): the settings page for an environment whose stored adapter is `ragflow` Measured on the settings service with the old manifest registered first (rows written through the door), then this PR's manifest registered over it. | Door | Answer | |---|---| | `GET /api/settings/knowledge` | `200`. Manifest `version` 3, adapter options `memory`, `turso`. `values.adapter` is `{"value":"ragflow","source":"global"}`: served as stored. Value keys served: `adapter`, `turso_url`, `turso_auth_token`, `chunk_target`, `over_fetch`, `enforce_rls`. No `ragflow_*` key is served; the three stored rows are still in the store | | `POST /api/settings/knowledge/test` (stored values) | `400 SETTINGS_ACTION_FAILED`, "Unknown adapter: ragflow" | | `PUT` `chunk_target: 900` | `200` | | `PUT` `adapter: 'ragflow'` | `400 SETTINGS_VALIDATION`, "Adapter must be one of: memory, turso. Received 'ragflow'.", field code `invalid_option` | | `PUT` `ragflow_api_key` | `400 UNKNOWN_KEY` | | `PUT` `adapter: 'memory'` | `200`; the next read serves `memory` | In the Console (the real `SettingsField` rendered in jsdom, not a browser): the Adapter select shows **nothing** for the stored `ragflow`, neither a label nor the "Select…" placeholder. `turso` shows its label; an unset value shows the placeholder. The page saves dirty keys only, so editing another field saves; picking an adapter and saving replaces the stored value. Left behind: the encrypted `ragflow_api_key` row and its `sys_secret` row. No settings door clears them once the key is undeclared. The changeset says how to delete them by hand. ### Measurement (b): a knowledge source declaring an unregistered adapter `KnowledgeServicePlugin` booted on a kernel with one object source declaring `adapter: 'ragflow'` and no adapter plugin. | Moment | Answer | |---|---| | Boot | Completes. One `info` line: `[knowledge] source registered: kb (adapter=ragflow, kind=object)`. No warning, no error | | `search` | `[]`, with `warn: [knowledge] source 'kb' references unknown adapter 'ragflow'; skipping.` | | `searchWithRefusals` | `{"hits":[],"refused":[]}`, same warning. The source is not reported as refused | | `indexDocument`, `reindexSource` | Throw a bare `Error` (no code, no status): `[knowledge] unknown adapter 'ragflow'. Registered: []` | | Record upsert / delete events | Resolve; `warn: [knowledge] event-sync failed for source 'kb': …` / `delete failed …` | **(b) is silent** at boot and on search. It is not changed here; the enforcement card is filed as objectstack-ai#37479. ## Tests - `knowledge.manifest.test.ts`: `version` 3 with absence pins for the three keys and the group (non-vacuity: `turso_url` is there); adapter options are exactly `memory`, `turso`; one new pin, "answers a stored retired adapter (ragflow) as a failure, complete old keys or not", with a passing `turso` call beside it. - `settings-visibility-declaration.pin.test.ts`: the predicate count goes 87 → 83 (the four `visible` predicates of the RAGFlow group and its keys). - `knowledge-settings-default-absent.pin.test.ts` and `service-knowledge`'s `knowledge-settings-contribution.test.ts`: the fixture adapter is `turso`. - The package's own test file (`ragflow-adapter.test.ts`) goes with the package. Run under the verify lock on `d3692d0c` (after the merge of `main` at `a46efa8c`): | Command | Result | |---|---| | `pnpm --filter @objectstack/service-settings test` | Test Files 77 passed (77), Tests 1521 passed (1521) | | `pnpm --filter @objectstack/service-knowledge test` | Test Files 13 passed (13), Tests 416 passed (416) | | `pnpm --filter @objectstack/embedder-openai test` | Test Files 1 passed (1), Tests 33 passed (33) | | `typecheck` of `service-settings` and `service-knowledge` | exit 0 | After the second merge of `main` (`cc38a91a`), on `cb640fb2`: `service-knowledge` Test Files 14 passed (14), Tests 448 passed (448); `service-settings` 77 files, 1521 tests, unchanged; `service-knowledge` typecheck exit 0. No ablation run: the change deletes code and edits prose. The one behaviour that moves, a stored `ragflow` reaching "Test connection", has its pin above. ## Acceptance notes - **H1 (hit count).** The tree was taken as the truth: 50 paths changed, 9 of them the package and 41 outside it. All 8 scripts were looked at: 6 edited, the timings JSON and the frozen fixture line left (see the table). - **H2 (`lint.yml` premise).** `DEBT` and `TEST_DEBT` in `scripts/check-type-check-coverage.mjs` are both `{}` on `main`, so the ledgered closure the step's comment describes was already empty before this card. The comment now says so. The step's `run:` line is unchanged; whether the step still earns its place is a workflow question outside this card. - **H3 (skill eval).** Case 3 is rewritten, not dropped: the prompt says the deployment runs PostgreSQL with pgvector and the expected answer writes `adapter: 'pgvector'` with no `split` key. Dropping it would lose the only case covering an object source with `where`, `metadataFields` and `refresh`; the in-memory adapter is already case 9. - **Size.** 50 files changed, 159 insertions, 7041 deletions against `main`, nearly all of it the deleted package and its lockfile entries. That is over the 3000-line threshold for a human merge, on top of the governed paths (`skills/**`, `.github/workflows/lint.yml`). - **ADR-0087 disposition (review round).** The changeset's marker is `not-required (runtime-export-retired @objectstack/knowledge-ragflow#*)`, the disposition ADR-0087 D9 gives a published package deleted at HEAD, with one FROM line naming the package. It was `no-migration-prescription`, which refuses a note that carries a prescription. The settings half's argument sits in the marker's reason. `check-adr-0087-registration` on `78fff74e`: exit 0, "verified: @objectstack/knowledge-ragflow#* (package)". - **ADR-0161, anchor fix, not a revision.** One table cell (the `adapterConfig` row) named a symbol anchor in the deleted package's `src/index.ts`, and `check:adr-symbol-anchors` refuses an anchor with no tracked file. The cell now names the function and the retired package in prose. No decision text is touched. Agreed with the zone. - **Serial.** objectstack-ai#37439 (zone ai-37000) landed first and is merged in (`main` at `cc38a91a`, no conflict). Its first-build callout in `content/docs/ai/knowledge-rag.mdx` listed RAGFlow among the persistent adapters; that one word is removed here. objectstack-ai#37442 (same zone) is still open: `overlap-check` against its head and `main` answers clean at `cb640fb2`. Whichever lands first, the other merges `main` once. objectstack-ai#37310 (same zone) rewrites cases 3 and 9 of `skills/objectstack-ai/evals/skills-tools-knowledge.json`, the file whose case 3 this PR rewrites; it is coordinated with this card and comes after it. - **Not edited, deliberately.** `content/docs/releases/implementation-status.mdx` (release-owned) and `scripts/test-shard-timings.json` (generated). Both agreed with the zone. - **Beyond the single hit.** `content/docs/plugins/packages.mdx`: the Plugins row swaps `knowledge-ragflow` for `knowledge-pgvector` and `knowledge-turso`, which it did not list, so its count goes 17 → 18. `embedder-openai` README: its "no knowledge adapter consumes an `IEmbedder`" paragraph was already untrue (pgvector and turso take one) and is rewritten. `packages/spec/llms.txt`: 78 → 77 published packages (`check:llms-txt` counts the workspace). - **An earlier pending note is now partly untrue.** `.changeset/33933-…` says clearing the key from Setup removes the stored RAGFlow API key. With the key undeclared that door is gone; this PR's changeset says so and gives the manual deletion. The earlier note is not edited. - **Pre-existing, not touched.** The docs describe `file` and `http` source kinds; no adapter in this repository ingests them. - **Seen, not changed here**, and where each went: - (1) Measurement (b), the silent unregistered adapter: filed objectstack-ai#37479. - (2) The Console's blank select for a stored value the manifest no longer offers, and (3) no door clearing a stored secret whose key was removed from a manifest: filed objectstack-ai#37480, one card for both. - (4) The docs-only releases follow-up: filed objectstack-ai#37481. - (5) The `lint.yml` step with an empty premise: filed objectstack-ai#37482. - (6) The three stale rows in the timings JSON: no card; the refresh workflow regenerates the file. - (7) ADR-0161 keeps `adapterConfig` in v1 "only while an adapter reads it", and after this PR no adapter in the tree does: no card; objectstack-ai#37304 already carries that removal. - (8) The earlier pending note about clearing the key from Setup: no card; this PR's changeset corrects it. ## Verification **Read first** (by risk): 1. `packages/services/service-settings/src/manifests/knowledge.manifest.ts`: the removed handler branch. A stored `ragflow` now falls through to the last line, `Unknown adapter`. 2. `skills/objectstack-ai/SKILL.md`: three small hunks in *Knowledge Sources (RAG)*; the published text an agent follows. 3. `.changeset/37004-retire-knowledge-ragflow.md`: the BREAKING paragraph and the "What to do if you used it" list. **Two-minute check:** `git grep -il ragflow -- ':!**/CHANGELOG.md' ':!content/docs/releases/v17/**' ':!docs/audits/**'` on this branch lists exactly the 11 files in the table above. <details> <summary>Local gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands` over the 50 changed paths derives 175 commands. `--ran`: 175 derived, 175 run, 0 NOT-MEASURED, 0 UNRUN, every one exit 0. - After the second merge of `main`, the derivation is the same 175; the 39 that read docs, skills or changesets were run again on `cb640fb2`, all exit 0. The rest were not repeated (CI runs them). - Review round, on `78fff74e`: the 18 derived gates that read changesets, ADR anchors or citations were run again, all exit 0. - Three were red on the way and are repaired in this PR, not waived: `check-skills-token-ratchet` (the first wording put `SKILL.md` 13 tokens over its ceiling; trimmed in the same file to 6798, its count before), `check:llms-txt` (78 → 77 published packages) and `check:adr-symbol-anchors` (the ADR-0161 anchor). - `check-plugin-teardown-shape --self-test` needs a pinned commit a shallow clone lacks; it passed (48 cases) once that commit was fetched. - `pnpm --filter @objectstack/spec check:generated`: exit 0 on the merged tree. - Full workspace build (`turbo run build` over `packages/*` and `packages/*/*`): 83 of 83 tasks, exit 0, on the merged tree. - `check-platform-checklist --changed-from origin/main`: exit 0, no anchored file in the change set. </details> <details> <summary>Dogfood battery (owed by the narrowing arm), on the final head</summary> - Head `d3692d0c919f690def1ec29b4021f69a1b3c8932`. Closure built with `pnpm turbo run build --filter=@objectstack/dogfood` (73 of 73 tasks), then `pnpm --filter @objectstack/dogfood test` under the verify lock, no shard, no path. - `VERDICT command-exit 0`. Test Files 487 passed, 3 skipped (490). Tests 4129 passed, 68 skipped (4197). Duration 2178 s. - That head is before the second merge of `main`, so the battery was run again on `cb640fb2`, same commands: `VERDICT command-exit 0`, same counts. - Current head `78fff74e1e182c3e9432329e06e8a8a3dbf0b4fd` (the review round's changeset commit), same commands: `VERDICT command-exit 0`. Test Files 487 passed, 3 skipped (490). Tests 4129 passed, 68 skipped (4197). Duration 2270 s. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CaUMCSy2q88QhyTB9f --> --------- Co-authored-by: Claude <noreply@anthropic.com>
… package customizations read (objectstack-ai#37568) <!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuBUGgrNWoBUQKbyS4GaX5vM)_ Fixes objectstack-ai#36828 Clause-②: no (published prose only; names a list the read already returns on main) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:AI 助手照平台技能文档回答「我们在已安装的应用包上改了什么」时,现在知道答案里还有一份「整体编排」清单(字段分组、记录页标签页、操作布局),以前文档没提这份清单。 - 为什么做:属于「定制已安装应用包」专题的收尾。产品已经返回这份清单,说明文档也已更新,只有技能文档还停在旧说法。 - 出错会怎样:只改文档文字,不动产品。写错的话助手会漏读或误读这份清单,撤回这次改动即可。为了不让技能文档变长,同一文件里删了四处重复说法。 - 要你做什么:这是受管的技能文件,需要审批人批准后才能合并。 ## What changes `skills/objectstack-platform/SKILL.md`, the sentence that teaches `GET /packages/hotcrm/customizations` (line 129), plus a `patch` changeset for `@objectstack/skills`. Before: "lists its overrides, extensions and switched-off items". After: "lists its overrides, extensions, switched-off items and `arrangements` (`{ object, key }` per `fieldGroups`, `relatedLists` or `actionLayout` its object extension writes; no content, no diff)". No paragraph is added. The file had 3 bytes of token headroom and the new words cost 137 bytes, so four restatements in the same file are cut to pay for them (136 bytes). Each fact keeps another home: | Cut | Bytes | Where the fact still stands | |:--|--:|:--| | "— `createHonoApp({ kernel })` reaches better-auth at `/api/v1/auth/*`" (HTTP Layer warning) | 71 | the same sentence: "(`AuthPlugin` default `/api/v1/auth`)" | | "with `create-objectstack`" in "Bundled with `create-objectstack` — no network fetch" (The Template) | 25 | the line above: "the only template `create-objectstack` offers" | | ", and it is the default" (The Template) | 23 | the same sentence ("the only template") and `references/bootstrap.md` ("blank is the default, and the only, template") | | ", after AuthPlugin" on the platform-app plugins row (Runtime Boot Sequence) | 17 | the list is headed "in this order" and the row sits directly under `AuthPlugin` | The ceiling row in the token ratchet is not moved. ## Why PR objectstack-ai#36818 added the `arrangements` list to this read and corrected the `content/docs/api/metadata-api.mdx` copy; the skill copy still named three lists. A tab list, field-group or action-layout arrangement made in the paired customization package appears only in `arrangements`, so an agent taught from the skill missed it. Shape checked against `main` (1af67b2), not the card text: - `packages/spec/src/api/package-lifecycle.zod.ts`, `GetPackageCustomizationsResponseSchema.arrangements`: a strict `{ object, key }`, `key` = `z.enum(CUSTOM_ARRANGEMENT_KEYS)`; its describe says the entry "names it and nothing more: its content is the pair's `object_extension` item, and nothing is compared with the base". - `packages/spec/src/data/field-customization.ts`: `CUSTOM_ARRANGEMENT_KEYS` = `fieldGroups`, `relatedLists`, `actionLayout`. - `packages/runtime/src/domains/packages.ts`, the customizations read producer: `arrangements.push({ object: name, key })` for each key the pair's extension body writes, sorted by object, then key. - `content/docs/api/metadata-api.mdx`: "one `{ object, key }` entry per object and key". ## Tests Prose only: no behaviour a test pins changes, so no ablation. Skills checks run on head `e00556f59b`: <details><summary>Gate readings</summary> - `node scripts/check-skills-token-ratchet.mjs` :: exit 0. "skills/objectstack-platform/SKILL.md is 6148 tokens (ceiling 6149; headroom 1)"; "61 authored bundle file(s) within their ceilings". - `pnpm check:pm-skill-id-lint`, `check:skill-identifier-liveness`, `check:skill-links`, `check:skill-top-level-keys`, `check:skill-compatibility`, `check:skill-frame-sync`, `check:doc-authoring`, `check:nul-bytes` :: exit 0 each. - `pnpm --filter @objectstack/spec run check:skill-docs` :: exit 0 ("Skill docs in sync"); `check:skill-refs` :: exit 0 ("10 generated files in sync with packages/spec"), both after `pnpm --filter @objectstack/spec build`. - `node scripts/pm/dispatch-gates.mjs --commands` derives 50 commands for this diff; reconciliation with `--ran`: 48 run with exit 0, 2 NOT MEASURED (`check:dual-build-cjs-loads`, `check:lean-entry-closure`: they need a whole-tree build and read no file of this diff; CI runs them). - `node scripts/pm/overlap-check.mjs` :: "VERDICT clean exit 0". </details> Size readings for `skills/**` (lines / bytes, `wc`; tokens in the ratchet's own convention): | | Before (1af67b2) | After | |:--|--:|--:| | `skills/objectstack-platform/SKILL.md` | 422 lines / 24613 bytes / 6149 tokens | 421 lines / 24611 bytes / 6148 tokens | | All 14 `skills/*/SKILL.md` together | 4961 lines / 261866 bytes | 4960 lines / 261864 bytes | ## Acceptance notes - The four cuts sit outside the sentence the card names. They are the only way to keep the token ratchet green without moving its ceiling; each is listed above with the place its fact still stands. - Open PRs objectstack-ai#37442, objectstack-ai#37422 and objectstack-ai#35129 also change `skills/objectstack-platform/SKILL.md`. All three text-merge cleanly with this branch, but the file is left with 1 token of headroom, so whichever lands second re-measures against the ratchet. - The skill sentence does not name `counts.arrangements`; the card asks for the list only. ## Verification Read first, by risk: 1. `skills/objectstack-platform/SKILL.md` line 129: the new clause. 2. The same file, HTTP Layer warning: the cut after "not `prefix`". 3. The same file, The Template and the boot-sequence row: the three small cuts. Two-minute check: `node scripts/check-skills-token-ratchet.mjs` prints "skills/objectstack-platform/SKILL.md is 6148 tokens (ceiling 6149; headroom 1)" and exits 0; `git grep -n "arrangements" -- skills/objectstack-platform/SKILL.md` prints one hit on line 129. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` is CI's run. - [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: not touched. - [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_01L6bhgWAbKPqt7vTgX5qgUn --------- Co-authored-by: Claude <noreply@anthropic.com>
… not a refusal (objectstack-ai#37550) Fixes objectstack-ai#37463 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:AI 用资料包读一条记录时,如果关联对象那一步因为故障(比如数据库抖动)读不出来,现在回答「内部错误」,不再谎称「无权访问」;对有权限的拒绝、以及「数据源暂不可用」这类本来就有明确说法的故障,照旧原样回答。用户无感于正常路径。 - 为什么做:属于「记录级 AI 问答」专题,替核对 AI 回答引用的一方解决分不清「没权限」和「出故障」的问题,故障时引用会被如实上报而不是悄悄丢掉。 - 出错会怎样:最坏情况是某次故障被报成「内部错误」,调用方可以重试,运维在服务器日志里每次都能看到故障原因;回答里不会多说出任何对象、字段或包的名字,改动可直接撤回。 - 要你做的:无。 ## What changes `get_record_context` (`packages/services/service-record-context`) reads each related object of a pack before it answers. At four of those reads, a throw that was **not** a refusal (an outage, a bug) was misanswered. At three of them it came back as `PERMISSION_DENIED` 403, so the citation verifier (`verifyRecordCitations`) read it as a refusal and dropped every citation without a report: | Site | Before (a failure) | After | |---|---|---| | step 4a, `assertApiExposed` failure that is not a coded refusal | 403 unnamed | 500 `INTERNAL_ERROR` | | step 4a, `servedObjectDefinitionOf(child)` throwing | 403 unnamed | 500 `INTERNAL_ERROR` | | `publishedOf`, published-definition read throwing | 403 unnamed | 500 `INTERNAL_ERROR` | | the child list query, an uncoded throw (the `/data` door answers it `500 Internal server error` and nothing else) | the raw error, which the doors answered 500 `INTERNAL_ERROR` | 500 `INTERNAL_ERROR`, the original at the foot of the stack | | the child list query, a fault the door codes (`ERR_DATASOURCE_UNAVAILABLE` 503, `DATABASE_ERROR`, `NOT_IMPLEMENTED` 501, a declared 5xx with its sentence) | the raw error, answered with the door's own code and sentence | unchanged: rethrown untouched | - **One helper, one line.** `refusedOrFailed` decides refusal vs failure at all four sites. At the three object-level sites it asks `isCodedRefusal` (in `record-context-tools.ts`, not on the package entry): the ADR-0112 line, a non-empty string `code` plus a declared 4xx status (`.status`, then `.statusCode`). The verifier imports the same function in place of its private copy. At the child list query it asks `doorAnswersItself`, which reads the `/data` door's own classifier, `mapDataError` from `@objectstack/types` (new as a dependency of this package). Before this change the doors classified that read's throw themselves, so the executor asks them rather than keeping a second reader (seat ruling, REWORK 7193191377 S2). The door answers a throw itself unless its answer is the anonymous fault: status 500, `Internal server error`, coded `INTERNAL_ERROR` or not coded, and nothing else (REWORK 7195238190 S3). - **A refusal answers as before.** At the object-level sites a coded refusal stays `PERMISSION_DENIED` 403 within the naming bound; a disabled package's `OBJECT_PACKAGE_DISABLED` (404, coded) is such a refusal. At the child list query, a throw the door answers itself is rethrown untouched, exactly as on `main`, with its own code and sentence. A sandboxed `beforeFind` hook's plain throw stays `400 HOOK_ABORTED` in the hook's words, and a `PERMISSION_DENIED` with no status stays the door's `PERMISSION_DENIED`. A fault the door codes stays the door's answer too: an unavailable datasource stays `ERR_DATASOURCE_UNAVAILABLE` 503 with its sentence (the caller keeps the retry signal), a driver error the door recognises stays `DATABASE_ERROR`, a driver's declared `NOT_IMPLEMENTED` stays 501, and a declared 5xx keeps its code and the sentence or `userMessage` its producer declared. `INTERNAL_ERROR` 500 applies there to an uncoded failure only. - **What an uncoded failure answers, and what it logs.** The code is `INTERNAL_ERROR` 500, not `SERVICE_UNAVAILABLE` 503. With a 5xx, `SERVICE_UNAVAILABLE` is on `CAPABILITY_ABSENCE_CODES` (`packages/types/src/server-fault-log.ts`), and the doors' fault line logs that code once per route per process, at `warn`, without the error (record 7193179486, M1). With `INTERNAL_ERROR`, each door logs the failure at `error` on every call. The fault line prints an error's message and stack and never its `cause` (both the console sink and `ObjectLogger`), so the failure's stack ends in `Caused by:` plus the original's stack. The original is also on `cause` for an in-process host; the verifier hands it to `onError`. A stack never reaches the wire. - **What an MCP caller sees for an uncoded failure (S1).** On either door the caller gets `{ code: 'INTERNAL_ERROR', status: 500 }` with the message `Internal server error`. The doors withhold a 5xx's own sentence, so the executor's `readFailed` sentence (en and zh-Hans; it names the pack and the root only) is read in-process only. Measured on `mapDataError`: the answer is `500 INTERNAL_ERROR` `Internal server error` whatever `cause` holds. Tried with no cause, a plain error, a SQLite and a Postgres unique violation, `SQLITE_BUSY`, and a coded 403. - `verify-citations.ts`: the docblock paragraph that this change made false is rewritten (claim amendment 7192997436). ### ADR-0160 (card item 3) No ADR-0160 sentence fixes 403 for a failed read. The two sentences closest are about refusals only: > Every such refusal carries one code — `PERMISSION_DENIED`, the code objectstack-ai#35145 uses — so the code does not tell a hidden object from a refused one. (D4, "The naming bound") > An object-level refusal names the refused object only when the caller's served schema shows it, and every such refusal carries one code. (point 12) D3 "Object level" covers refusals by gates and says nothing on reads that fail. So no ADR text has to change for this PR; whether to add a sentence on failures stays with objectstack-ai#37490. ## Tests - `record-context-tools.test.ts` has a new `describe`, "a read of a related object that fails is a failure, not a refusal". It has one uncoded-throw case per site: 500, the exact `readFailed` sentence, none of the outage's names, the original on `cause`, and `Caused by:` plus the original's stack in the failure's stack. It has a refusal control per object-level site (`OBJECT_PACKAGE_DISABLED` 404 stays `PERMISSION_DENIED` 403, unnamed) and for the child query (a coded refusal is rethrown unchanged). For S2: a sandboxed hook's plain throw (`innerMessage`) and a status-less `PERMISSION_DENIED` at the child query are rethrown untouched, while the same throws at an object-level read fail the call. A sandboxed body that crashed (a native error name) is a fault at the door, so it fails the call. At an object-level read, a driver errno with no status, a coded 5xx, a status with no code, and a thrown string are failures too. For S3, at the child query: an unavailable datasource (503), a driver error the door answers `DATABASE_ERROR`, a declared `NOT_IMPLEMENTED` 501, and a declared 5xx with its sentence or a `userMessage` are rethrown as the same object; each case first asserts the door's own answer for it (`mapDataError`). The controls there (a status-less 500, a coded `INTERNAL_ERROR` 500, an errno the door does not recognise, a thrown string), which the door answers with nothing of its own, fail the call. The sentence follows the caller's locale. - `verify-citations.test.ts`: an uncoded throw at the child's served-definition read drops the citation and is reported once through `onError` (500, cause is the outage). A coded refusal there drops it and reports nothing. A control verifies the same citation. - `packages/runtime/src/mcp-record-context-tools-bridge.test.ts` is the real-kernel harness, run on both doors. Outage: the related-list read of `rc_revision` throws an uncoded error in `engine.find`. Asked twice, there are four `[5xx] 500` error lines (two doors times two calls), each carrying `INTERNAL_ERROR` and `Caused by: Error: OUTAGE_TEXT` (the thrown outage) in its stack, and no capability-absence warning. Both doors answer the same bytes, `INTERNAL_ERROR` 500, with no object name and no outage text. S2, at the same read: a sandboxed hook's plain throw answers `HOOK_ABORTED` 400 in the hook's words, and a status-less `PERMISSION_DENIED` answers `PERMISSION_DENIED` and never a 5xx. S3, at the same read: an `ERR_DATASOURCE_UNAVAILABLE` throw answers `ERR_DATASOURCE_UNAVAILABLE` 503 with its sentence on both doors, each door logs one `[5xx] 503` line, and no line carries `INTERNAL_ERROR`. Each case has a control that reads once the spy is removed. ## Acceptance notes - A refusal the door answers at the child list query is rethrown as on `main`, so the citation verifier still reports a status-less one (`PERMISSION_DENIED` with no status, or a hook abort with no code) through `onError`, as it did on `main`. The verifier's rule (a string `code` plus a declared 4xx) is unchanged. - The naming-probe read inside the step 4a exposure catch (`servedObjectDefinitionOf(...).catch(() => null)`) still treats a throw as "not shown". The refusal is a real one, so a throw there only leaves out the object's name. - Every uncoded failure is `INTERNAL_ERROR` 500, a bug included (N2 is accepted by the seat). - The child query's predicate asks the classifier with the child's name, where the door asks with the root's; only the classifier's name-dependent 404 arm reads it (N3, accepted by the seat). ## Verification Read first, by risk: 1. `record-context-tools.ts`: `refusedOrFailed`, the four `catch` sites that call it, and `doorAnswersItself`, the child list query's predicate. 2. `record-context-tools.ts` `isCodedRefusal`, and `verify-citations.ts` importing it. 3. `packages/services/service-record-context/package.json` and `pnpm-lock.yaml`: one workspace dependency, `@objectstack/types`. Two-minute check: `pnpm --filter @objectstack/service-record-context exec vitest run --maxWorkers=2 src/__tests__/record-context-tools.test.ts`. Expect the new `describe` to pass, every case. Readings at head `007615908a` (this container, shared box): <details><summary>Package suites, ablations, local gates, CI</summary> - `pnpm --filter @objectstack/service-record-context test` + `typecheck`: Test Files 4 passed (4), Tests 174 passed (174); tsc clean; check:test-typecheck OK. `pnpm --filter @objectstack/runtime test` (whole suite): Test Files 649 passed (649), Tests 12065 passed, 25 skipped. Lock VERDICT command-exit 0. - Ablation S3, via `scripts/ablation-replace.mjs`: the child list query's predicate reverted to the round-2 line, "the door answers below 500" (blob 756d303 to cb3d0801619c), rebuilt, marker present in dist (preflight exit 0). Service 5 failed / 145 passed (the five coded-fault cases), harness 1 failed / 27 passed (the `ERR_DATASOURCE_UNAVAILABLE` case: the answer was `INTERNAL_ERROR`). Restore leg: blob back to 756d303, equal to HEAD; `git diff HEAD` empty; rebuilt; marker absent (preflight `--absent` exit 0); 150/150 and 28/28 pass. - The round-2 ablations (M1, S2) were run at `bd03a37ed8` and not rerun at this head; this commit changes only the child query's predicate. There, M1 failed the harness at the fault-line pin and S2 failed all four S2 cases. - `dispatch-gates --ran`: 83 derived, 82 run with exit 0, 1 NOT MEASURED: `check:dual-build-cjs-loads`, exit 3, PREREQUISITE NOT MET (it needs every package's dist). The derivation warned the tree is 23 commits behind `origin/main` with 7 gate files changed there; CI runs the current gates. - Overlap check: VERDICT clean (`origin/main`, objectstack-ai#37442 on `pnpm-lock.yaml`, objectstack-ai#35129 on `package.json`). - CI on `007615908a`: 69 check-runs, 60 success, 9 skipped, 0 failure. Every required context is green, the UI ones and Check Changeset included. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc --> --------- Co-authored-by: Claude <noreply@anthropic.com>
…t page, and a stalled build is cancelled (objectstack-ai#37570) <!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg3zXREECfPtgrM8TPQaxn1v)_ Fixes objectstack-ai#37465 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:多节点部署里,知识源重建时构建锁中途失效,构建会在下一页停下,状态显示为"租约丢失";嵌入调用卡住 15 分钟无进展,构建会被取消并释放锁,状态显示为"超时",不必重启即可再次重建。 - 为什么做:属于知识检索(RAG)落地这条线,替运维省掉两个节点重复花的嵌入费用,也解决卡死后只能重启的问题。 - 出错会怎样:最坏情况是构建的收尾一步(切换到新索引)一直不返回,这个知识源会一直显示"运行中",直到它返回或进程重启;已写入的内容保留,下次重建会跳过已写部分;改动可直接撤回。 - 要你做什么:无。 ## What changes **Cluster lease fence (service-knowledge).** `rebuildSource` now runs its walk under a build fence (`startBuildFence`, `knowledge-build.ts`), and `walkObjectSource` asks the fence before each page: - The lease is lost when the handle reports `isHeld() === false`, when a renewal failed and the handle no longer holds the lease, or when no renewal has succeeded within `BUILD_LEASE_MS`. The last case covers a lock store that does not answer, or a renewal that hangs. - When the lease is lost, the walk stops before the next page's read: nothing more is embedded, purged or completed. The record's status is `lease-lost` and the lease is released. - A lease lost after the last page also skips the purge and `completeBuild`. **Stall bound (service-knowledge).** `BUILD_STALL_LIMIT_MS` is 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. - Past the bound, the build is cancelled: its status is `timed-out`, the lease is released, and nothing is purged or completed. - The walk races every store and engine call it waits on before the completion against the bound: `beginBuild`, the document listing, each page's `engine.find`, `adapter.upsert` and `adapter.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). - Each purge deletion restarts the bound (the `serialize` hook in `walkObjectSource` ticks the fence when each candidate settles), so a large, healthy purge is never cut short. - `rebuildSource` also races the whole walk. That covers what the walk does not fence: the wait in the source's queue behind another walk, and `planIndex`. - **The completion is not a page.** The private `completeBuild` helper 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 calls `fence.completing()`, which disarms the bound for the rest of the build, and awaits `adapter.completeBuild` without a race. A switch that began before the bound passed therefore still commits, and the record reads `done` or `failed`, never `timed-out` over a switched index. pgvector's sweep of the replaced generation runs inside that call, so it is not cut short either. - The source's walk chain (`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's `finally` (which clears the adapter's `builds` entry 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 build `running` until it answers or the process restarts. **pgvector builder-lock fence.** - Each build write and removal (`ctx.reason === 'reindex'`, for a build this adapter began) first checks in `pg_locks`, on the lock's own session, that the source's advisory lock is still held. If it is not, the write is refused with `LOCK_CONFLICT` (409) before anything is embedded. - `completeBuild` completes only the build this adapter began, and only the generation that build began. Otherwise it is refused with `LOCK_CONFLICT` and switches, records and deletes nothing. - A lock kept from an earlier build is re-checked at `beginBuild`, so a lock whose session ended is no longer kept. - **Behind a transaction-mode pooler** the advisory lock does not stay with the session that took it, so the check reads a held lock as lost. Such a deployment was already unsupported; before this change its builds ran with a release warning, and now every complete build is refused at its first page. The refusal's remedy and the changeset name the pooler and the fix: a direct or session-mode endpoint. **N3.** A pgvector search that meets three generation switches is refused with `CONCURRENT_MODIFICATION` (409). The rows for `CONCURRENT_MODIFICATION` and `LOCK_CONFLICT` leave `scripts/error-status-unpinned-baseline.json`. `check:error-status-conformance` required the `LOCK_CONFLICT` removal too, because the new pgvector refusals declare its status. **N2.** Measured live: `beginBuild` under 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 (`readIndexState` reads `current`), 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`, and `beginBuild` sweeps only under a freshly checked lock. **knowledge-turso (measured, not changed).** It has no builder lock: `beginBuild` takes up any generation under the same fingerprint, so there is no builder identity for an "own generation" check beyond the fingerprint, which `completeBuild` already requires. Its cluster-lease protection is the service-level fence in this PR. **CLI.** The CLI's `KnowledgeBuildView.status` type and the `rebuild.ts` comments list `lease-lost` and `timed-out`. No runtime change: a followed rebuild already exits 1 on any status other than `done`. **Docs.** `content/docs/ai/knowledge-rag.mdx` adds 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's `lease-lost` sentence 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 objectstack-ai#37442 edits. **Widening.** The exported `KnowledgeBuildRecord.status` gains `lease-lost` and `timed-out`. Nothing else becomes newly exported from the package entry. ### Files to read first (by risk) 1. `packages/services/service-knowledge/src/knowledge-service.ts`, `rebuildSource` and the private `completeBuild` helper: the race on `fence.cancelled`, the status taken from `fence.stop()` when the walk returns `ok: false`, and `fence.completing()` before the unraced `adapter.completeBuild`. 2. `packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts`: `holdsBuilderLock` (the `pg_locks` key split into `classid`/`objid`) and the `completeBuild` own-generation check. 3. `packages/services/service-knowledge/src/knowledge-build.ts`, `startBuildFence`: the local lease expiry (`heldUntil`) for a renewal that never settles, and `completing()` (the bound disarmed for good). ### Two-minute verification `pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/knowledge-build-fence.test.ts` should report 14 passed. The first case shows 1 page embedded of 3 and `lease-lost`. The stall case shows `timed-out` at 15 minutes of fake time, then a next build that completes. The completion case shows a build still `running` at 30 minutes, then `done`, with the second `beginBuild` only after it. ## Tests <details><summary>Local readings</summary> - `knowledge-build-fence.test.ts` (new, 14 cases): - lapse mid-walk: 1 of 3 pages embedded, `find` called once, `completeBuild` 0, `lease-lost`, released once; - lapse after the last page: no purge and no complete; - lapse during the purge: no complete, `lease-lost`; - renewals that hang past the lease: `lease-lost`; - an embed call that never answers: `timed-out` at the bound, lease released, the next build `done`; - a slow build with progress inside each bound: `done`; - a completion that answers only after twice the bound: the build stays `running` with its lease kept; a rebuild asked meanwhile answers the same running record; a complete walk asked meanwhile does not call `beginBuild` until the completion settles; then `done`, the lease released once, and the queued walk's `beginBuild` runs second; - a purge of three deletions, each taking most of the bound: `done`, `purged: 3`; - a hung listing: `timed-out` with no complete, then a second build `done`; - a hung purge removal, with a store that keeps listing the document until a removal lands: the first build `timed-out`; the second build also `timed-out` at its purge, with no second removal call and no complete; once the hung removal answers, the document is gone and a third build is `done`; - a build queued behind a plain reindex (no fence) whose upsert never answers: `timed-out` at the bound, lease released, no `beginBuild`; - no cluster service: bound only; - fence unit: the first stop kept, and `close()` disarms the bound; - fence unit: after `completing()`, `cancelled` never settles and `progressed()` does not re-arm the bound. - service-knowledge full suite at e5bac7e: Test Files 15 passed, Tests 462 passed; typecheck exit 0. - CLI: typecheck exit 0; `src/commands/knowledge/knowledge.test.ts` 7 passed. - knowledge-pgvector against a local PostgreSQL 16.16 with pgvector 0.8.7 (`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) and `search-switches.test.ts` (1). Typecheck exit 0. - Ablations, each a mutation on disk then `git restore`: - per-page lease check disabled: 2 fence cases red; - pgvector `fenceBuild` disabled: 2 live cases red; - the fence check in the private `completeBuild` helper disabled: the lease-lost-during-purge case red. - the `fencedCall` around 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 around `completeBuild` restored: the completion case red each time. - the purge-deletion tick removed: the large-purge case red. - both `unbounded` guards in the fence removed: the `completing()` unit case red. - the per-document chain around purge deletions removed: the hung-purge-removal 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 unfenced `planIndex` and tenancy reads. </details> ## Acceptance notes - The bound is per page (and per purge deletion), not per build. A whole-build ceiling would cut a large, healthy build. A page holds at most 100 rows, so 15 minutes without one finishing means a call is not answering. The value matches pgvector's default `buildLockIdleMs`. - The completion is not bounded, by the seat's ruling. A completion that never answers keeps the build `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. - A call the build stopped waiting on cannot be withdrawn. `AdapterContext` has 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. - N2 remainder: after a revert, `readIndexState` reads `current`, so no build runs and the stale building generation stays until the next build. Retiring it without a build would need `indexStatus` or a read-time sweep. Not done here. - Turso N3 sibling: knowledge-turso's three-switch search refusal is coded, but as `SERVICE_UNAVAILABLE` 503 ("the store is not ready"), while pgvector now answers `CONCURRENT_MODIFICATION` 409 for the same condition. Parity card objectstack-ai#37597 (p3, sub of objectstack-ai#37465) codes it `CONCURRENT_MODIFICATION` 409; this PR leaves turso alone. - A purge removal that never answers is abandoned at the bound, but it still holds that one document's own sync chain, which is per document and separate from the source's walk chain. The removal never landed, so the store still lists the document. Every later complete build therefore reaches it in its purge, queues behind the hung removal, and is cancelled `timed-out` in 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.ts` edits stay inside `walkObjectSource` and `rebuildSource`, plus the import block, a one-parameter pass-through in `reindexWith` that threads the fence, and the private `completeBuild` helper (its fence check and `fence.completing()`). None of these touches the regions objectstack-ai#37442 edits; overlap-check reports a clean merge. ## Verification - overlap-check at e5bac7e: `VERDICT clean exit 0` against origin/main (54d6726), objectstack-ai#37442 and objectstack-ai#37578 (which shares `rebuild.ts`). No merge of main was needed. - The derived gates at e5bac7e (112 with `--repo objectstack-ai/objectstack`): `--ran` reconciliation reports 111 run and 1 NOT MEASURED, `check-plugin-teardown-shape --self-test`, a recorded exit 3 (PREREQUISITE NOT MET: shallow clone). - PR check-runs at e5bac7e: 40 success, 15 skipped, 0 failure. Every required context is green. Temporal Conformance (live PG + MySQL) runs only in the merge queue. This round did not touch knowledge-pgvector; its last local live reading is 83/83 on PostgreSQL 16.16 with pgvector 0.8.7, at fda121f. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6Cb4BAjgQ43tqy1DvVJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
…above its measurement (objectstack-ai#37747) <!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DG44bgtJm8kWx4oK68re6GX)_ Fixes objectstack-ai#37630 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户无感:这是仓库内部的技能长度检查,发布给客户的技能文字一个字都没改。 - 为什么做:属于技能长度管控。以前文件变短后上限还停在原处,多出来的额度没人发现,后来的改动可以悄悄用掉;现在会直接报错,并给出该降到的数字。 - 出错会怎样:最坏是技能相关的 PR 被误拦,作者照提示把上限降到实测值即可;整个改动可直接撤回。 - 要你做的:无。 ## What changes `scripts/check-skills-token-ratchet.mjs` used to fail a row only when the measured tokens were over its ceiling. A row whose file later shrank passed and printed its headroom. On PR objectstack-ai#37442 that left a row 1 token above the merged measurement, and only the reviewer's arithmetic caught it. - **The per-row check** (`verdict()`) now fails a row whose ceiling is above its measurement. The message names the row, the measurement, the ceiling and the gap, and tells the author to lower the row to the measurement in the same PR. Lowering is the author's own act, so this message carries no `⛔ MAINTAINER-ONLY` token. The over-ceiling refusal is byte-for-byte unchanged. - **The header's shrink-only bullet** now says the PR that shrinks a file lowers its row to the new measurement in that PR. A row left above its measurement is red. - **37 CEILINGS rows are lowered to their measurement.** On `origin/main` ce4d8c7, 37 of the 61 authored rows sat above their measurement, 4813 tokens in all. The largest gaps were `objectstack-api/SKILL.md` (981), `objectstack-query/SKILL.md` (940) and `objectstack-data/rules/indexing.md` (746). Each row's number changes and gains a `-N to the measurement (was C)` note, and one block comment sits on the prose side of the CEILINGS doc comment (the placement note says to keep new prose there). No `skills/**` text changes and no ceiling is raised. ### Failure or warning **I chose failure.** Reasons: 1. With the 37 stale rows lowered, every row on main sits at its measurement, so a failure reds nothing that exists today. 2. A warning would be one more line in a log of 100-plus lines. A log line is how the 1-token gap on PR objectstack-ai#37442 got through. The card's failure mode is a reading nobody looks at, and a warning is still a reading nobody looks at. 3. The header already has the gate's rule: every path that moves a row pins it AT the measurement. Headroom left by a shrink is not budget. Failing on it makes that rule hold mechanically, just as failing over the ceiling does. 4. No header-documented reservation exists today. The header's one reservation is `pending10402` (headroom held for an approved PR), and its own record says it is spent ("`objectstack-data` measured 13817 against a 13817 ceiling … exactly zero"). So nothing needs an exemption. A future reservation of that kind would need this gate changed, and the header now says so. **How unchanged rows on main are treated:** they are lowered in this PR, not given a warning tier. Lowering is always legitimate under the header. Header lines that bound this change, quoted for the skills-lane reviewer: - Record 6139629628 item 2 (the A2′ stamp exclusion), as the header quotes it: "counts authored content only: the frontmatter `version:` line that the release bot rewrites is excluded from the count … ceilings stay shrink-only and the current headroom (0 and 1 tokens) stays as it is." I read this as bounding the A2′ re-pin, which lowered every stamped row by exactly 5 so that no file's headroom moved. I do not read it as protecting headroom against a later lowering. - The `strippedInternalIds` note in `CEILING_BASIS`: "That is the ratchet working as designed: shrink-only means a ceiling may be lowered to the measurement whenever one is taken, not merely by the size of the day's deletion." This is the authority for lowering all 37 rows in one PR. - The raise paths, all pinned at the measurement: ruling record 6513306068 ("may move the row by the measured remainder, pinned AT the measurement"), and ruling A on record 6819475461, made standing by record 6840575378 ("may raise that file's row by the row's own measured delta and by no more"). **Side effect for the reviewer:** in failure mode every count change to a skills file must edit its row. So two skills PRs that change one file's count now always conflict on that row; before, only raises did. This is the intended serialisation, because the merged measurement differs from both branches. It is still new load on skills PRs. **Overlap:** open draft PR objectstack-ai#36158 rewrites five of the lowered rows: `objectstack-data` `SKILL.md`, `rules/field-types.md` (together with the adjacent `rules/indexing.md`), `rules/relationships.md`, `rules/validation.md` and `references/examples-objects.md`. That PR already conflicts with main on its own skills files and re-measures those rows when it rebases. overlap-check: origin/main, objectstack-ai#37676 and objectstack-ai#37422 merge cleanly. ## Tests <details><summary>Self-test, gate, ablation and reverse reading (head d1295a6)</summary> - `node scripts/check-skills-token-ratchet.mjs --self-test`: exit 0, `✓ check-skills-token-ratchet self-test: 111 cases pass.` The roster grew 104 to 111, and the floor was raised to match. `under the ceiling -> green` became `under the ceiling -> red (a ceiling above its measurement)`, and the shrink-direction row now pins red-until-lowered. Seven new batteries: the red names the row, the measured count, the ceiling and the gap; it tells the author to lower the row; it is not the over-ceiling red (no `over by`, no authority token); one token above the measurement is red. Each new case reads the verdict and its text together. - `node scripts/check-skills-token-ratchet.mjs`: exit 0, `61 authored bundle file(s) within their ceilings`, and `ratcheted (authored) 199660 / 199660 (+0)`. On main it read `199660 / 204473 (-4813)`. - Ablation (`scripts/ablation-replace.mjs`, the new branch's `if` disabled, anchor x1 to x0): self-test exit 1, `9 failure(s)`, which is exactly the nine above-measurement batteries. After restore the blob matched HEAD and `git diff HEAD` was empty. - Reverse reading: main's CEILINGS judged by the new verdict, 37 of 61 rows red, gap 4813. </details> ## Acceptance notes - The card's acceptance asks the gate to report a row whose ceiling exceeds its measured tokens, naming the row, the measurement and the ceiling. It does that, as a failure; the choice is argued above for the reviewer. A test pins the new reading. The existing over-ceiling refusals are unchanged. - `skip-changeset`: the only file changed is a root `scripts/` gate in the private monorepo root package, so nothing ships. ## Verification <details><summary>Local gates (head d1295a6)</summary> - All 34 commands from `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` exited 0. Each exit code was captured before any pipe. They include `check-skills-token-ratchet` with its `--self-test`, `check:ratchet-remedy-authority`, `check:doc-authoring` and `check:nul-bytes`. - `--ran` reconciliation: `34 derived, 34 run, 0 NOT-MEASURED, 0 UNRUN`. - `check:pm-dispatch-gates` exited 0 on the previous head, ebc8fae. The last commit touches only ratchet self-test lines. - `check-published-list-mirrors` exited 0. - The control-byte self-scan found 0. </details> **Read first:** `verdict()`, the new below-ceiling branch (the one behaviour change). Then the header's "ratchet discipline" bullet. Then a sample of the lowered rows against the gate's printed counts. **Two-minute check:** run `node scripts/check-skills-token-ratchet.mjs`. Expect exit 0 and the line `ratcheted (authored) 199660 / 199660 (+0)`. Then raise any row by 1 locally and re-run. Expect a red that names that row, its measurement and the ceiling, ending in `Lower the row to N`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP --------- Co-authored-by: Claude <noreply@anthropic.com>
…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>
…d once at boot (objectstack-ai#37951) repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Fixes objectstack-ai#37479 Clause-②: no Metadata-protocol: none ## 维护者速读 - 运维人员看启动日志时,一个指向未挂载存储的知识源从两行告警变为一行错误,错误里写明知识源、存储名和可选的已挂载存储;用户无感。 - 属于知识检索平台(AI 检索)史诗,替看启动日志的运维人员去掉重复噪音。 - 出错只会让这条错误多一行或少一行,检索与建索引的行为不变,可直接撤回。 - 无。 ## What changes - `packages/services/service-knowledge/src/knowledge-service.ts` `buildIfDue`: at boot, a source whose adapter is not mounted is skipped by the first-build pass without a line. Before, the pass read its index state, `getAdapter` threw the unmounted-adapter refusal, and the pass logged it at `warn` as "is not built at boot: what the adapter holds could not be read (...)", beside the `error` that `reportUnmountedAdapters` already prints at `kernel:bootstrapped`. Now the boot says it once, at `error`, naming the source, the adapter and the mounted adapters. - On reload (a `knowledge_source` item added while the process runs) nothing changes: no boot reading runs then, so the reload build's `warn` is still the one line that names the source. - Indexing and searching such a source still answer the coded `SERVICE_UNAVAILABLE` 503 (PR objectstack-ai#37442); not touched. This is item 1 of the re-scope (card comment 7187970703). Item 2, a publish or `os validate` refusal of an adapter name no deployment can serve, is NOT in this PR: it would narrow what is accepted, and the area decides. Options are in the dev report on the card. That is why this PR says `Part of` and leaves the card open. ## Tests - New pin in `src/__tests__/knowledge-build.test.ts`: with a data engine bound, one mounted source and one naming `pgvector` (not mounted), the boot pass plus the boot reading produce exactly one log line naming `'docs'` across debug/info/warn/error. That line is at `error` and names the adapter as not mounted. The mounted source is still built (`status: 'done'`). - Ablation: with the new guard line replaced by a comment, the pin goes red: `expected [ [ 'warn', …(1) ], [ 'error', …(1) ] ] to have a length of 1 but got 2` (1 failed, 22 passed). With the line restored, the file is green (23 passed). <details><summary>Package test and typecheck (head 13f32fc)</summary> `pnpm --filter @objectstack/service-knowledge test && pnpm --filter @objectstack/service-knowledge typecheck` under the verify lock: `VERDICT command-exit 0`, Test Files 17 passed (17), Tests 529 passed (529). `typecheck` is `tsc --noEmit && pnpm check:test-typecheck`, so the test files are type-checked too. </details> ## Acceptance notes - Item 2 of re-scope 7187970703 (a publish or `os validate` refusal) is closed by area decision D, with no publish-time refusal added. The refusal point is boot: `reportUnmountedAdapters` prints a coded error naming the source and the adapter. `searchWithRefusals` lists such a source as refused (`knowledge-service.ts` near :1882), and index and search answer the coded 503 (PR objectstack-ai#37442 and this PR). Options A (save-time admission) and B (a `ragflow` tombstone) stay in the dev report on the card, for a future card. - The claim's file surface pointed at `:372` as "the boot build pass's kept(...) line". On origin/main 73d5e34, `:372` is `dropMetadataSource`'s `kept(...)`, which runs when a source is removed, not at boot. The second boot line comes from `buildIfDue` (the `warn` of an `unreadable` index reading). The fix sits there, and `dropMetadataSource` is not touched. - Public surface: no exported type, export or wire shape changes. No dependent package owes a test. ## Verification Read first: `knowledge-service.ts` `buildIfDue` (the one added guard line), then the new pin. Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-build.test.ts` should show 23 passed. Delete the guard line `if (trigger === 'boot' && !this.adapters.has(entry.handed.adapter)) return;` and the pin fails with 2 lines (warn, error) where it expects 1. <details><summary>Derived gates (local, head 13f32fc): 68 exit 0, 2 NOT MEASURED</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 70 families from the 3 changed paths. All 70 ran; `--ran` with recorded exit codes: "70 derived famil(ies) accounted for — 68 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)". - NOT MEASURED: `check:dual-build-cjs-loads`, reason: PREREQUISITE NOT MET, it needs every package's `dist/` (a whole-tree build). CI runs it. - NOT MEASURED: `check:type-check-debt`, reason: its re-measure build did not get a turn on the shared verify lock (queue-timeout 99). CI runs it. The package-wide scans (`pnpm lint` and the rest of the farm) are CI's. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP Co-authored-by: Claude <noreply@anthropic.com>
Requested by Warren · project thread
Fixes #37102
Clause-②: yes
Metadata-protocol: added
Skills-docs: follow-up #37310
维护者速读
What changes
knowledgeinPLATFORM_CAPABILITY_TOKENS/PLATFORM_CAPABILITY_PROVIDERS(provider@objectstack/service-knowledge, editionopen) and in coreCAPABILITY_PROVIDERS.@objectstack/core):resolveKnowledgeStore/resolveCapabilityExtras+KNOWLEDGE_STORE_PROVIDERS. PostgreSQL (driverpostgresor apostgres(ql)://URL) →KnowledgePgvectorPluginon the same URL;:memory:→ in-memory turso; anything else →KnowledgeTursoPluginonknowledge.dbin the data directory (.objectstack/data/, or<OS_HOME>/data/whenOS_HOMEis set) withurlFromSettings.knowledge-memoryis never mounted.os servereads the primary database it resolved and mounts the one store; an extra that cannot be imported or constructed now warns instead of being skipped silently. A host that mounts the service or a store itself keeps its own (hasPluginMatchingon the identities).@objectstack/verifyconstructServedProviderstakes an optionaldatabase(default in-memory SQLite) and mounts the same store as serve.service-knowledge): service mounts, boot does not fail; atkernel:bootstrappedoneerrorline per such source naming the mounted adapters; index and search of that source answerSERVICE_UNAVAILABLE503 with the same message (existing code, no new error code). A multi-source search keeps the other sources' hits and names the refused one.knowledge-turso): under the token the store URL comes from settings (knowledge.turso_url/turso_auth_token).resolveSettingsStoreUrlholds a savedfile:URL to the realpath'd.objectstack/data/(symlink escape,.., the directory itself and the platform DB file are refused) and refuses a NUL or other control character, all beforecreateClient.resolveStoreUrlrefuses control characters too.kernel:bootstrapped, not instart()(knowledge-turso, fix round). The settings service answers a saved value only once its data engine is bound, in its ownkernel:readyhook; a read instart()saw the manifest default while the saved row sat unread, so the store opened the default file whatever the operator had saved (check:settings-bind-windownamed it; reproduced on a real kernel, see Verification). UnderurlFromSettingsthe adapter is now registered instart()with no database and answersSERVICE_UNAVAILABLE503; the plugin registers itskernel:bootstrappedhandler ininit(), so it runs ahead of every handler a plugin registers instart(): the knowledge service's embedder, its reading of unmounted adapters, and the first build of service-knowledge: a source that was never built gets built, and an operator can start a rebuild #37099 find the store open. A store givenurlorclientopens instart()as before. The plugin'soptionalDependencieskeep only the knowledge service: no ordering edge moves astart()read past the settings bind.knowledge-turso).resolveStoreUrlandresolveSettingsStoreUrltested the raw URL only, so a savedfile:…/k%00.dbpassed both; libSQL decodes the path it opens and its native library ends the process on the NUL byte, at every boot. Both now read each%XXescape as the character it encodes and refuse a control character in either spelling, before anything touches the disk or the client. The check is inresolveStoreUrl, so the plugin's ownurloption holds too.@objectstack/knowledge-tursois an optional dependency of@objectstack/cliand@objectstack/verify(it was a hard one in the first round). Its libSQL client is a native module with anos/cpulist; as a hard dependency it would refuse the whole CLI install outside that list.KNOWLEDGE_STORE_PROVIDERS.tursoand itsCapabilityExtracarryoptional: true.os servealready warns when an extra cannot be imported and boots on;constructServedProvidersnow does the same for an optional extra (any other provider it cannot load is still a thrown boot error).OS_HOME(os start --homesets it):resolveKnowledgeStorehands the storestateDir, and the data directory is then<OS_HOME>/data/, the directory the boot keeps the default platform database in (resolveDatabaseStateDir's order). The settings confinement moves with it, so an operator can keep the file on the volume. WithoutOS_HOMEnothing changes. New plugin optionstateDir;dataDirectoryOfanddefaultStoreUrltake it as a second argument. A database named by URL does not move the store (documented).knowledge-rag.mdx): where the file is, what more than one replica means on MySQL, MongoDB or remote libSQL (one local file per replica, each indexing only its own writes: use a sharedlibsql://store or PostgreSQL), and an install without the libSQL client.knowledge-turso, commit 664bd70).turso_auth_tokenis the second settings value handed to the libSQL client. A token with a NUL byte, a line break or another control character is refused in the plugin's one open path (open()), for the saved setting and for theauthTokenoption alike, before the client is created; the store answersSERVICE_UNAVAILABLEwith a reason that never quotes the token. It is read as written, with no percent-decoded reading: the client percent-decodes a URL (anauthTokenin a URL's query is already covered by M1's check), never this option, so%00in a token is three characters. Probed on the installed@libsql/client0.18.0 before the change, to know what the check prevents: on afile:URL a NUL or a line break in the token opens and answers a query (exit 0, no abort: the native open ignores the token without a sync URL); onhttp://every request is rejected with a catchableTypeError(invalid header value); onws://the connection was refused before the token was used, so that arm is unmeasured. So no process abort was found; the check turns a failure at every call into one refusal that names the setting. N4: theknowledge.manifest.tsjsdoc now names the state directory's data directory and both spellings of a control character.turso_urlexample path is nowfile:./.objectstack/data/knowledge.db.content/docs/ai/knowledge-rag.mdxgains "Turning it on:requires: ['knowledge']"; the old "Wiring" section is now "Wiring by hand".CAPABILITY_ROWSline inpackages/spec/scripts/lib/platform-catalog.tsand its regenerated pageskills/objectstack-project/references/platform-catalog.md(gen:skill-refs, no hand edit), and the bareknowledgetoken added to the@objectstack/service-+ token cell of therequires:table inskills/objectstack-platform/SKILL.md. No teaching, examples or evals: those ride skills/objectstack-ai and the MCP authoring contract teach knowledge_source as metadata: name, an explicit content list, no wildcard, the retired keys, and a create seed #37310.skills/objectstack-platform/SKILL.md(scripts/check-skills-token-ratchet.mjs): priced text 24591 to 24603 bytes (+12), 6148 to 6151 tokens (ceil(24591 / 4) = 6148, ceil(24603 / 4) = 6151).main's row is 6149, with 1 token of headroom since docs(skills): objectstack-platform names the arrangements list of the package customizations read #37568 took 2 bytes out of the file; that token is absorbed, so the ceiling moves 6149 to 6151 (+2), pinned at the measurement. History of the number: on the first three merges ofmain(4925039, cc38a91, 5dbcc02) the base was 24593 priced bytes and the row read 6152 (24605 bytes); docs(skills): objectstack-platform names the arrangements list of the package customizations read #37568 then landed, and after the fourth merge (758e145) the row is re-pinned at 6151 (S5 of delta record 7196043543). The delta of the row itself is 12 bytes throughout.packages/spec/scripts/platform-catalog.test.ts): 6902 to 6939 bytes (+37), ceiling 1726 to 1735 tokens, pinned at the measurement. The row was first shortened from 50 to 37 bytes ("knowledge search and its vector store").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."main758e145 (lines; tokens as the ratchet prices them):skills/objectstack-platform/SKILL.md421 to 421 lines, 6148 to 6151 tokens;skills/objectstack-project/references/platform-catalog.md(generated) 160 to 161 lines, 2878 to 2898 tokens; allSKILL.mdfiles together 4961 to 4961 lines; the whole shipped bundle reads 299348 tokens, of which this PR adds 23 (3 + 20).packages/cli/src/utils/boot-preparation-parity.test.ts:resolveCapabilityExtrasis aSERVE_ONLYentry (the declaration boot reads a row'sextrasitself and composes no knowledge store: a store'sinit()declares nothing, its tables are its own). Editing the file put it incheck:test-source-alias's changed-file scope, so it now pays six dynamic imports its step modules reach at collection (six module-top side-effect imports, the gate's printed remedy).Tests
packages/verify/src/harness.required-providers.test.ts:requires: ['realtime','knowledge']on SQLite boots the service + turso (not pgvector), a record write is indexed andsearchfinds it, a pgvector source is refused 503 while boot succeeds; no token → no service andsettings.getNamespace('knowledge')rejectsSETTINGS_UNKNOWN_NAMESPACE; host-mounted service unchanged.packages/plugins/knowledge-pgvector/src/__tests__/capability-mount.live-postgres.test.ts(new, live cell): the token's resolution on PostgreSQL picks pgvector on the same URL; a record write is indexed andsearch_knowledgefinds it. It has not run in CI on any commit of this PR: the job with a PostgreSQL service,temporal-conformance, does not run onpull_request, and Test Core collects the file with both cases skipped. Its first CI run is the merge queue (the PR touchespackages/plugins/knowledge-pgvector/**, which is in thetemporal_livefilter). It did run locally in the rework round, against PostgreSQL 16.15 with pgvector 0.6.0 from the distribution's package (CI pins pgvector 0.8.7): see Verification.packages/core/src/capability-composition.test.ts: store selection arms (pg driver/URL, other DBs, in-memory, env fallback) and extras.packages/plugins/knowledge-turso/src/__tests__/plugin.test.ts:resolveSettingsStoreUrl(NUL/control, inside, outside, symlink escape, platform file) and the plugin never reaching a mockedcreateClientwith a refused URL. Fix round: the settings double now answers a saved value only once bound, as the real service does, and the cases run a boot in kernel order (init(),start(), the bind,kernel:bootstrapped). New case: nothing is read and no file is made ininit()orstart(), the mounted adapter answersSERVICE_UNAVAILABLE/ 503 until the boot completes, then the saved file opens and the default file is never made.plugin.test.ts:%00,%0a,%0A,%7f, afile://form and alibsql://URL are refused by both resolvers, with a control (%20and a doubly encoded%2500are names, not control characters); a saved%00or%0aURL never reaches a mockedcreateClient; a state directory moves the default file and the confinement.harness.required-providers.test.ts: a real-kernel case for the file-database arm (constructServedProviderswith afile:database under a temporaryOS_HOME, aturso_urlsaved from akernel:readyhandler: the store is healthy on the saved file, neither default file is made, a record write is found by search); an install without the store (the package made unimportable: the service is constructed, the store is not, one warning); the dependency pin now requires anoptionalstore to be an optional dependency and nothing else.capability-composition.test.ts:OS_HOMEis handed to the file arm asstateDir, and to no other arm.plugin.test.ts: a token with a NUL byte, a trailing line break, a CR LF or U+007F never reaches a mockedcreateClient, through the settings door (on alibsql://URL and on a file inside the data directory) and through theauthTokenoption; no log line quotes the token; controls: a JWT-shaped token and one with%00in it reach the client as written.packages/services/service-knowledge/src/__tests__/knowledge-service.test.ts: boot reading, coded index/search refusals, the plugin hook.packages/cli/test/serve-capability-identity.test.ts: identity rows for the service and both stores.Acceptance notes
skills/**, so this PR stays draft until the maintainer's approval.packages/spec/scripts/platform-catalog.test.ts,skills/objectstack-platform/SKILL.md,scripts/check-skills-token-ratchet.mjs,packages/cli/src/utils/boot-preparation-parity.test.ts), and the maintainer approved editing them in the card thread.kernel:readyandkernel:bootstrappeda store whose URL is the operator's setting has no database yet: a record written by another plugin'skernel:readyhandler is not indexed into it (the call answers 503). The knowledge service's own settings-configured embedder is provided at the same phase, so a deployment without a host-registered embedder indexed nothing in that window before either. The first build of service-knowledge: a source that was never built gets built, and an operator can start a rebuild #37099, now onmainand merged here, builds the source after the store has opened and so covers such rows.@objectstack/knowledge-tursois an optional dependency of@objectstack/cliand@objectstack/verify(S3). On an install without itrequires: ['knowledge']on a non-PostgreSQL database boots with the service and a warning, and sources namingtursoanswer 503.file::memory:and an emptywasm-sqlite:URL take the file arm; N2, the settings examplefile:./.objectstack/data/knowledge.dbis read from the working directory and names the project's directory, so underOS_HOME, or from another working directory, it is refused with a message naming the right directory (it fails closed; the example text lives in the manifest and 11 locales). N3, theci.ymlstep comment still says three*.live-postgres.test.tsfiles where there are now five:.github/workflows/**is outside this card's surface, so it is not edited here.mainis merged here and the first-build path re-checked. Its after-boot build starts in the knowledge service'skernel:bootstrappedhandler and reachesgetAdapterthroughreadIndexState, inside that method's owntry. Read on a real kernel (see Verification): a store whose URL is a saved setting is open before the build starts (its handler is registered ininit(), the service's instart()), and the build of its source endsdone; a source naming an unmounted adapter is read asunreadable, is not built, and the boot goes on. Such a source is logged twice at boot, once aterrorby this PR's reading of unmounted adapters and once atwarnby the build pass; one line would do (carried by service-knowledge: a knowledge source that names an unregistered adapter fails silently (boot clean, search answers [], index throws a bare Error) #37479, not changed here).mainfour times (scripts/pm/os-regen-merge.sh, no rebase): at 4925039 for a GitHub conflict in therequires:table row ofskills/objectstack-platform/SKILL.md(resolved by keepingmain's provider cell whole and adding the bareknowledgetoken afterrecord-context), at cc38a91 once feat(service-knowledge): build a never-built source after boot; os knowledge rebuild and status #37439 had landed (no conflict), in the rework round at 5dbcc02 once fix(settings)!: retire @objectstack/knowledge-ragflow and the Knowledge page's RAGFlow adapter option #37477 and feat(knowledge-pgvector): a changed fingerprint builds a new generation and switches to it #37492 had landed (no conflict), and at 758e145 for S5 once docs(skills): objectstack-platform names the arrangements list of the package customizations read #37568 had editedskills/objectstack-platform/SKILL.md(auto-merged, no conflict). After each,git diff origin/mainnames this PR's 38 files and nothing else;gen:skill-refsandcheck:generatedleave the tree clean.scripts/check-skills-token-ratchet.mjs. Whichever lands second re-measures theskills/objectstack-platform/SKILL.mdrow.Verification
First files to read, by risk:
packages/plugins/knowledge-turso/src/plugin.ts:init()/start()/openFromSettings(when the store opens, and what it answers before).packages/core/src/capability-composition.ts:resolveKnowledgeStore(which store, with what argument).packages/services/service-knowledge/src/knowledge-service.ts:getAdapter/reportUnmountedAdapters(the coded refusal).Two-minute check:
pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2 src/__tests__/plugin.test.ts: expect 22/22, including "refuses a percent-encoded control character too" and "reads the settings at kernel:bootstrapped, never in init() or start()".Local runs (under scripts/pm/os-verify-lock.sh): the rework round on 806c55d, the token round on 664bd70, and what ran again on head c25cc1a
pnpm install --frozen-lockfile: exit 0.pnpm turbo run build --concurrency=2 --filter='./packages/**' --filter='./examples/**': exit 0, 85/85 tasks.gen:skill-refsthencheck:generated: exit 0, tree clean.pnpm --filter @objectstack/knowledge-turso test: exit 0, 3 files, 155/155.typecheck: exit 0.pnpm --filter @objectstack/core exec vitest run --maxWorkers=2 src/capability-composition.test.ts: exit 0, 21/21.pnpm --filter @objectstack/core typecheck: exit 0.pnpm --filter @objectstack/verify exec vitest run --maxWorkers=2 src/harness.required-providers.test.ts: exit 0, 15/15 (19.0 s of tests locally; the header's budget is re-derived to 28).pnpm --filter @objectstack/verify typecheck: exit 0.pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2 src/utils/boot-preparation-parity.test.ts test/serve-capability-identity.test.ts src/commands/knowledge/knowledge.test.ts: exit 0, 3 files, 143/143.pnpm --filter @objectstack/cli typecheck: exit 0. The rest of the cli suite is left to CI.pnpm --filter @objectstack/service-knowledge test: exit 0, 14 files, 452/452.pnpm --filter @objectstack/service-settings test: exit 0, 77 files, 1521/1521 (after fix(settings)!: retire @objectstack/knowledge-ragflow and the Knowledge page's RAGFlow adapter option #37477's edits to the same manifest and locales).scripts/platform-catalog.test.ts(spec): exit 0, 20/20.OS_TEST_POSTGRES_URL=postgres://postgres:postgres@127.0.0.1:5432/postgres OS_EXPECT_LIVE_DIALECT_MATRIX=1 pnpm --filter @objectstack/knowledge-pgvector exec vitest run live-postgres: exit 0, 5 files, 65/65, none skipped (4 files, 59/59 before the merge ofmainbrought feat(knowledge-pgvector): a changed fingerprint builds a new generation and switches to it #37492's file). Server: PostgreSQL 16.15 with thevectorextension 0.6.0 (the distribution'spostgresql-16-pgvector), not CI's pinned pgvector 0.8.7 image.knowledge-turso, one comment in the settings manifest, the docs page and the changeset):pnpm --filter @objectstack/knowledge-turso test: exit 0, 3 files, 156/156 (plugin.test.ts22/22); itstypecheck: exit 0;turbo run buildof@objectstack/knowledge-tursoand@objectstack/service-settings: exit 0, 20/20 tasks. Everything above this line was run on 806c55d and not again.pnpm install --frozen-lockfile: exit 0.pnpm --filter @objectstack/spec build,gen:skill-refs, thenpnpm --filter @objectstack/spec check:generated: exit 0, tree clean.scripts/platform-catalog.test.ts: exit 0, 20/20 (catalog ceiling 1735 unchanged).node scripts/check-skills-token-ratchet.mjs: exit 0,skills/objectstack-platform/SKILL.md6151 / 6151. No package test was run again on this head.Rework round: each new test turns red without its fix
carriesControlCharacter(the raw test alone, as on abf337b):plugin.test.ts2 failed / 19 passed, "refuses a percent-encoded control character too" and "a saved URL with a NUL byte, or outside the data directory, never reaches the libSQL client". Restored (byte-identical to the committed file): 21/21.stateDirandoptional: trueremoved from core and core rebuilt:harness.required-providers.test.ts3 failed / 12 passed. The file-database case answers{ ok: false }(the saved file underOS_HOMEis outside the app's data directory); the missing-store case throws the "could not load it" boot error; the dependency pin reports@objectstack/knowledge-tursoas not a dependency. Restored and rebuilt: 15/15.acceptsAuthTokencheck removed fromopen():plugin.test.ts1 failed / 21 passed, "an auth token with a control character never reaches the libSQL client, saved or given; the reason never quotes it". Restored withgit checkout(the committed file): 22/22.Fix round: reverse verification of the settings read (one-off, no file kept)
A throwaway
@objectstack/verifycase booted a real kernel withKnowledgeServicePlugin,KnowledgeTursoPlugin({ urlFromSettings: true })and a plugin that savesknowledge.turso_urlfrom itskernel:readyhandler (ordered after the settings bind).start()answerssource: 'default'; after the boot the store is healthy on the saved file andknowledge.dbwas never made. Probe 1/1 green.plugin.tsrestored to 969b372 (the pre-fix file),knowledge-tursorebuilt (dist marker absent): the probe is red, the saved file was never made and the defaultknowledge.dbwas opened;plugin.test.ts3 failed / 16 passed (the two saved-URL cases and the new phase case).HEAD(blob hash equal,git diff HEADempty), rebuilt (dist marker present): probe green again.The first build of #37099 on a real kernel, after the second merge (one-off, no file kept)
A throwaway
@objectstack/verifycase booted a real kernel withKnowledgeServicePlugin,KnowledgeTursoPlugin({ urlFromSettings: true })and an app plugin that registers an embedder, a source onturso, a source naming the unmountedpgvector, and savesknowledge.turso_urlfrom itskernel:readyhandler. 1/1 green; readings after the boot:tursosource:buildRecordis{ trigger: 'boot', status: 'done', result: { ok: true, failed: 0 } }, thenreadIndexStateanswerscurrent("same fingerprint, same recipe hash"). The store is healthy on the saved file and the defaultknowledge.dbwas never made.pgvectorsource: no build record;readIndexStateanswers{ state: 'unreadable', due: false }with the coded refusal's text ("adapter 'pgvector' is not mounted (mounted: turso)"). Boot log: oneERRORline from the reading of unmounted adapters, oneWARNline "is not built at boot" from the build pass.Derived gates (node scripts/pm/dispatch-gates.mjs --commands, 166 commands)
check-skills-token-ratchet.mjsand its self-test,check:skill-docs,check:skill-examples,check:skill-refs,check:skill-identifier-liveness,check:skill-links,check:skill-top-level-keys,check:ratchet-remedy-authority). The other 129 were not run again locally on this head; CI runs them on the merge.overlap-checkbefore the push:origin/main(758e145) merges cleanly; exit 1 only for open PR feat(spec)!: form is a metadata type of its own, and the form doors read a form over both types #37422 (conflict inscripts/check-skills-token-ratchet.mjs).Remaining
Clause-②: yes, then the maintainer's approval (Tier H).🤖 Generated with Claude Code