Repository navigation
fix(service-knowledge): a host-mounted service with no embedder answers a search 503 naming the settings to save - #38817
Conversation
…ed refusal Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
…UNAVAILABLE (503) at its source Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 14 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 6 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 5 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 ec2c6a7ac39663c8eb96b672dec2f07f0333e923 && git checkout ec2c6a7ac39663c8eb96b672dec2f07f0333e923
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin d97aaaea9a1e4298f7db799879709fe365c2df3e a9f74fd3f3d2fd9ebb16a2979f45878cf664f52c && git checkout -B drift-repro d97aaaea9a1e4298f7db799879709fe365c2df3e && git merge --no-ff a9f74fd3f3d2fd9ebb16a2979f45878cf664f52c
node scripts/docs-audit/affected-docs.mjs --json d97aaaea9a1e4298f7db799879709fe365c2df3e
|
…ged at warn by the search round Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ Final green head · 2026-12-01T02:28Z · zone osa-ai
|
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm 席位核对 — L1 ACCEPT · head
|
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ 落地
State change: ready for review + auto-merge, by zone osa-ai (2026-12-01T02:37Z); on merge it closes #38775. |
…l round included (objectstack-ai#38798) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8WwwNJsfXjR7KkaXqjQxjFx)_ Fixes objectstack-ai#38676 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 员工在知识库里搜索、且需要补查第二轮时(例如按单位分组或权限复查后命中不足),问题现在只生成一次向量;以前补查轮会再请求一次嵌入服务(DashScope 约 200 毫秒),搜索结果本身不变,运维和管理员无感。 - 这是“知识检索慢”那张卡的第三个原因(补查轮重复生成问题向量);前两个原因已在之前的改动里修好,这次按你选定的“写进约定,一次提问只转一次”收尾。 - 若出错,碰到的是搜索知识库的员工:最坏情况是某个知识源这次搜索被拒答并写明是哪个来源,不会静默答空;“需要重建索引”这类提示照旧排在前面,不会被嵌入服务的报错盖掉;改动可以直接撤回。 - 无。 ## What changes The question of one knowledge search is embedded at most once for each adapter instance, by the adapter, and the knowledge service carries it back to every `search` call of that search, the refill round included. Built to the ADR-0161 dated note of 2026-12-01 under K8 (ruling record 7296268226 on the card, with its condition: an adapter's own refusal stays ahead of the embed). - **Contract (`@objectstack/spec/contracts`)**: `IKnowledgeAdapter` gains an optional `embedQuery(query)`, which embeds a question exactly as that adapter's `search` does (its embedder, its query prefix); it takes no source. `AdapterSearchOptions` gains an optional `queryVector`, typed as a function of no arguments answering a promise of a read-only number array (`() => Promise`, answering `readonly number[]`). It is the function, not the vector. Both docblocks cite the note and no longer say the knowledge service embeds. Both members additive and optional. - **Service (`knowledge-service-search.ts`, `knowledge-service-top-level.ts`)**: `planSearches` gives every target whose adapter instance has `embedQuery` one slot per instance for the whole search (`SearchQuestion`). The first `searchRound` call to that instance puts one memoised function in it (`memoisedQuestion`): its first call asks the instance's `embedQuery` for the query, and every later call in that search answers the same promise, a rejected one too. That one function is handed on every `search` call to that instance in that search. The service no longer embeds ahead of `search`, no longer judges whether a call embeds (the earlier `keyword` and "round ranks nothing" guards are gone) and reads no vector. A rejection is `embedQuery`'s own error, never wrapped. - **`knowledge-turso`, `knowledge-pgvector`**: each calls the handed function at the exact line where its `search` embeds the query today, in place of that call, after every gate it runs first (nothing to rank, store and embedder present, ready, active generation, the fingerprint and width refusal `KNOWLEDGE_REBUILD_REQUIRED`, `topK`, the mode, `keyword`). Absent: it embeds as before, through its own `embedQuery`. The width check is unchanged, and the answered array is never changed. A failed embed therefore fails inside `search`, where it failed on `main`, with `main`'s code and wording (pgvector's `searchRefusalOf` included). - **Contract suite (`@objectstack/service-knowledge/testing`)**: an optional `implements.embedQuery` declaration, checked against the adapter, and one case for it (below). `knowledge-turso` and `knowledge-pgvector` declare it. - **Docs**: §3.4 of `content/docs/protocol/knowledge.mdx` is rewritten to the note: the function type, where the adapter calls it, what costs no embedding call, and the suite case. - An adapter without `embedQuery` (for example `knowledge-memory`) is handed nothing and searched exactly as before. - `main` merged first (`9e729ceaad`). objectstack-ai#38817's behaviour is kept: an embedder error reaches the caller unwrapped, and its test file `unconfigured-embedder-code-38775.test.ts` is unchanged and green (6 of 6). Review findings closed by this round: M1 by the note (merged as `13a0d3fedf`); S1 by the suite case; S2 by the new shape and its pins (a refusal ahead of the embed is answered, with 0 embedder calls); N4 by the new shape (the embed is back inside `search`, so pgvector's socket wording is `main`'s again). Nits of contract review 7290045524: N1 by the new shape (the function is handed on every call, so "every call" is literal); N2 by the new shape (an embedder that answers no vector is one embedding call, memoised, and the width check refuses it, where the earlier head made two); N3 by the new shape, wording kept: on the service's path the handed vector is what the adapter's own embedder answered, so "the embedder answered" stays true; a direct caller answers for its function (the note's second diamond). ## Tests All pins count calls; none is wall-clock. - `packages/services/service-knowledge/src/__tests__/search-question-vector.test.ts` (rewritten, 11 cases, over a fake adapter shaped as the two stores): a refilled search hands both rounds one function and calls `embedQuery` once; two sources of one instance, one function for four calls, one call; the function answers the same promise on every call; two instances, two functions, one call each; two searches, two functions; `keyword` is handed the function and embeds nothing; a source the adapter refuses behind a failing embedder answers its 409 with 0 calls; no `embedQuery`, nothing handed; an uncoded embed failure fails the call that asked (503 platform sentence, text to the operator line); a coded one reaches the adapter as the same error object and keeps code and message; a failed embed is shared (one call, both sources refused). - `packages/plugins/knowledge-turso/src/__tests__/acceptance.test.ts` (one top-level describe, 6 cases, real adapter behind `KnowledgeService`): refilled search, one embedder call, prefixed; refilled search over two sources of one instance, one call; `keyword`, 0 calls; **a source that needs a rebuild (embedder model changed) behind an embedder that fails answers `KNOWLEDGE_REBUILD_REQUIRED` 409 with 0 embedder calls**; the control, the same failing embedder behind a healthy source, called once and refused 503; a handed function is ranked with, a function of another width is refused. - `packages/plugins/knowledge-pgvector/src/__tests__/question-once.test.ts` (new, 5 cases, real adapter and `KnowledgeService` over a fake pool): the same four pins as turso (the rebuild-required source is an index held under another fingerprint) and the same control. - `packages/plugins/knowledge-pgvector/src/__tests__/retrieval-modes.test.ts` (3 cases, adapter alone): `embedQuery` embeds the prefixed query; a handed function is asked once and its answer is bound into the ranking statement, embedder not called, with a control; another width is refused. - `packages/services/service-knowledge/src/testing.ts#runKnowledgeAdapterContract`, one case, run only for `implements.embedQuery`: handed a function answering its own `embedQuery`, a search answers what it answers without the member and makes no embedding call of its own; handed one answering a vector of another width (wider, then narrower), the search rejects. The count is a **spy on the instance's `embedQuery`** (review 7297709290 N1), with a control (the search without the member is seen by the spy once). It asserts a rejection, not a code (N2); no code is added. - `packages/plugins/knowledge-pgvector/bench/instrument.test.mjs`: unchanged since `56feee7fa7`, still one embed for a refilled search. <details><summary>Ablation (each through scripts/ablation-replace.mjs; landing and restore proven by blob hash, git diff HEAD empty after each)</summary> - The service calls the function ahead of `search` (the earlier head's order): service 6 failed of 11; turso 2 failed of 6 (keyword, rebuild-required); pgvector 2 failed of 5 (keyword, rebuild-required). - The function not memoised: service 5 failed of 11; turso 2 failed of 6 (refilled, two sources); pgvector 2 failed of 5 (refilled, two sources). - `knowledge-turso` ignores the handed function: the contract case fails on both libSQL cells (2 of 2). Every pin goes red under at least one ablation. The `keyword` pins also hold on `main` and on the earlier head: they guard the order, not the count. </details> <details><summary>Runs at e434583</summary> - `pnpm --filter @objectstack/service-knowledge exec vitest run`: Test Files 31 passed (31), Tests 896 passed (896). - `pnpm --filter @objectstack/knowledge-turso exec vitest run`: Test Files 6 passed (6), Tests 335 passed (335). - `pnpm --filter @objectstack/knowledge-pgvector exec vitest run`: Test Files 10 passed, 10 skipped (20); Tests 75 passed, 117 skipped (192). The live-PostgreSQL files skip here (no pgvector server in this container), so the contract case on pgvector is NOT MEASURED locally: CI's live cell runs it. - `pnpm --filter @objectstack/knowledge-memory exec vitest run src/__tests__/contract.test.ts`: 54 passed (the suite change, an adapter without the member). - typecheck of spec, service-knowledge, knowledge-turso, knowledge-pgvector: exit 0, test layers included. - `pnpm --filter @objectstack/spec build` then `check:generated`: all 14 generated artifacts up to date. - eslint over the changed source and test files: exit 0. - Derived gates (`dispatch-gates.mjs --commands`, 117 families): 116 exit 0, 1 NOT MEASURED (`check:dual-build-cjs-loads`, exit 3: needs every package built); `--ran`: 117 derived, 116 run, 1 NOT-MEASURED, 0 UNRUN. </details> ## Acceptance notes - The earlier head's note that a source with no built index cost one embed per search is gone: the adapter now asks only past its own gates. - One embed serves every source of one adapter instance, so a failed embed refuses each source of that instance that asked, with the same error, where on `main` each made its own attempt (the note says so). - The contract case counts by a spy on `embedQuery`, so it reads an adapter whose `search` embeds the query through that method, as both stores do; one that embeds by another path fails the case's control, and the suite's docblock says so. - `knowledge-memory` has no `embedQuery` and still embeds on every call; adding it there is outside this card. ## Verification Read first, by risk: 1. `packages/services/service-knowledge/src/knowledge-service-search.ts`: `memoisedQuestion` and the `queryVector` lines at the top of the loop in `searchRound`. Risk: a call of the function there, ahead of `search`, would undo the condition. 2. `packages/plugins/knowledge-turso/src/turso-adapter.ts` and `packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts`: the one changed line where `search` embeds. Risk: it must stay after every refusal above it. 3. `packages/spec/src/contracts/knowledge-adapter.ts`: the two members and their docblocks (the contract text). Two-minute check: `pnpm --filter @objectstack/knowledge-turso exec vitest run src/__tests__/acceptance.test.ts -t 'embedded at most once'` prints `Tests 6 passed`; the fourth case asserts a 409 with 0 embedder calls behind a failing embedder. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h <!-- signed: repo:objectstack#2 · os-warren · session_01JQwxbXfgA45f3y5YpDPT5h --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Yibo Wang · project thread
Fixes #38775
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
UnconfiguredEmbedder.refusal()(packages/services/service-knowledge/src/knowledge-service-plugin.ts) now carries ADR-0112SERVICE_UNAVAILABLE/status: 503, the code the held path refuses with (ADR-0161 K8, the dated note on item 12). The message is unchanged: it already names theai.embedder_*settings to save under Settings, AI and Embedder, and the restart. Both uses of the stand-in are coded, readingdimensionsandembed(). No error code, settings key or contract member is added.Measured on
origin/main0fc9eab (red run before the fix), a host-mounted service with no embedder answered a search in two different wrong ways, depending on the store's shape:search: refused 503SERVICE_UNAVAILABLEunder the platform sentence "source 'docs' could not be searched: its adapter 'vec' failed." The remedy only reached the operator'serrorline.embeddingdescriptor reads the embedder'sdimensions(the shape of the pgvector and turso stores): the planning step (planIndex, before any store is asked) threw the stand-in's plainErrorwith nocodeand nostatus.After the fix, both answer 503
SERVICE_UNAVAILABLEwith the stand-in's own sentence and remedy.Tests
New:
packages/services/service-knowledge/src/__tests__/unconfigured-embedder-code-38775.test.ts, booted the way a host boots it (LiteKernel,KnowledgeServicePluginwith noruntimeComposed,SettingsServicePluginwith nothing saved, a store plugin resolving the kernel'sembedderservice at each call). Six cases: the stand-in is what the boot registers and the service is not held;dimensionsandembed()refused coded with the remedy;searchWithRefusalson both store shapes;search()never answered empty.Red before the fix (5 of 6 failed: the 5 code/remedy cases; the "stand-in registered, not held" case passes on both trees, as expected).
Code ablation (
scripts/ablation-replace.mjs, anchor hit 1 time, so 1 to 0): removingcode: 'SERVICE_UNAVAILABLE'from the refusal turns 5 of 6 red. Restored to blobaf4477aa5a93, equal to HEAD, andgit diff HEADis empty.Updated:
knowledge-settings-contribution.test.ts, case "no settings: boot succeeds, and indexing and search answer an error naming the missing settings". That case pinned the old uncoded path, which put the stand-in's text on an operatorerrorline. Now that the refusal is coded, the search round logs that text, remedy included, atwarn. The assertion and its comment now saywarn, and nothing else in the file changed. The claim amendment on the card added this file to the surface.Package runs at a9f74fd
pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2: Test Files 30 passed (30); Tests 885 passed (885).pnpm --filter @objectstack/service-knowledge typecheck: exit 0 (test layer: 0 files, 0 errors in test-typecheck-debt.json).Acceptance notes
errorthat is nowwarn, is updated in this PR under the amended claim.TypeScript Type CheckandLint & Repo Gatesred. Both were aggregators reading acancelledlane:Type Check · consumer gatesandLint · repo & tooling gateslogged "The operation was canceled." at 01:56:35 and 01:56:47. That was the lint workflow's per-PR concurrency group cancelling the old head's run when a9f74fd was pushed; the new run started at 01:56:34. Neither lane logged a failure before it was cancelled. At a9f74fd both aggregators and both lanes are success.embedder.dimensionsin theirembeddinggetter, so with the stand-in their search is refused while it is planned, not in the search round. The new test pins that shape with a fake store. A live pgvector run is not part of this PR.Verification
Files to read first, by risk:
packages/services/service-knowledge/src/knowledge-service-plugin.ts, therefusal()hunk.packages/services/service-knowledge/src/__tests__/unconfigured-embedder-code-38775.test.ts, theEmbeddingStorePluginfixture.Two-minute check:
pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/unconfigured-embedder-code-38775.test.ts. Expect 6 passed.Local gates at 5c8d03a
dispatch-gates.mjs --ran: 74 derived, 72 run, 2 NOT-MEASURED, 0 UNRUN. Every run gate exited 0. NOT MEASURED:node scripts/check-plugin-teardown-shape.mjs --self-test(PREREQUISITE NOT MET: a positive control pinned to a commit this shallow clone cannot reach; this is a checker-health self-test only) andpnpm check:dual-build-cjs-loads(PREREQUISITE NOT MET: needs every package built). Both are left to CI.At a9f74fd the derived list is the same 74 commands. I re-ran the ratchet and test-reading families there, all exit 0: cross-package-test-inputs, test-source-alias, nul-bytes, issue-citations (both forms), doc-authoring, refd-timer-probe, logger-receiver-detach, rest-log-spy-declared, registry-log-declared, optional-error-sink, comment-mask adoption and corpus, closing-keyword-parity, engine-double-contract, where-matcher, objectql-double-limit, type-check-coverage, query-options-erasure, slot-lookup and type-check-debt. The rest of the list was not re-run, a declared narrowing: the commit changes two lines in one test file. CI at a9f74fd: 39 success, 18 skipped, 0 failure.
Signed: repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ
Generated by Claude Code