Skip to content

fix(service-knowledge): a host-mounted service with no embedder answers a search 503 naming the settings to save - #38817

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-38775-unconfigured-embedder-code
Dec 1, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-38775-unconfigured-embedder-code

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Yibo Wang · project thread
Fixes #38775
Clause-②: no
Metadata-protocol: none

维护者速读

  • 自己挂载知识服务、却没配置向量模型的部署,管理员搜索时以前只看到“服务不可用”,现在会看到同样的 503,但附带要保存哪些设置、然后重启。
  • 属于知识库检索(RAG)的可用性收尾:让自挂载路径与运行时托管的“暂停”路径给出同一种带补救说明的答复。
  • 只影响没配置向量模型的自挂载部署;改动只是给一条已有错误补上错误码,可直接撤回。
  • 要你做什么:无。

What changes

UnconfiguredEmbedder.refusal() (packages/services/service-knowledge/src/knowledge-service-plugin.ts) now carries ADR-0112 SERVICE_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 the ai.embedder_* settings to save under Settings, AI and Embedder, and the restart. Both uses of the stand-in are coded, reading dimensions and embed(). No error code, settings key or contract member is added.

Measured on origin/main 0fc9eab (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:

  • a store that embeds the query inside search: refused 503 SERVICE_UNAVAILABLE under the platform sentence "source 'docs' could not be searched: its adapter 'vec' failed." The remedy only reached the operator's error line.
  • a store whose embedding descriptor reads the embedder's dimensions (the shape of the pgvector and turso stores): the planning step (planIndex, before any store is asked) threw the stand-in's plain Error with no code and no status.

After the fix, both answer 503 SERVICE_UNAVAILABLE with 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, KnowledgeServicePlugin with no runtimeComposed, SettingsServicePlugin with nothing saved, a store plugin resolving the kernel's embedder service at each call). Six cases: the stand-in is what the boot registers and the service is not held; dimensions and embed() refused coded with the remedy; searchWithRefusals on 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): removing code: 'SERVICE_UNAVAILABLE' from the refusal turns 5 of 6 red. Restored to blob af4477aa5a93, equal to HEAD, and git diff HEAD is 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 operator error line. Now that the refusal is coded, the search round logs that text, remedy included, at warn. The assertion and its comment now say warn, 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).
  • At 5c8d03a, before the pin update: Tests 1 failed, 884 passed (885). The failure was that pin.

Acceptance notes

  • The search round's files (held by another open PR) are untouched. The one existing pin the coded refusal changed, an operator line at error that is now warn, is updated in this PR under the amended claim.
  • CI at 5c8d03a showed TypeScript Type Check and Lint & Repo Gates red. Both were aggregators reading a cancelled lane: Type Check · consumer gates and Lint · repo & tooling gates logged "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.
  • The pgvector and turso stores read embedder.dimensions in their embedding getter, 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:

  1. packages/services/service-knowledge/src/knowledge-service-plugin.ts, the refusal() hunk.
  2. packages/services/service-knowledge/src/__tests__/unconfigured-embedder-code-38775.test.ts, the EmbeddingStorePlugin fixture.

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) and pnpm 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

…UNAVAILABLE (503) at its source

Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/service-knowledge, touching 1 documentable anchor(s).

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

  • content/docs/ai/connect-mcp.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/ai/knowledge-rag.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/api/client-sdk.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/api/error-catalog.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/api/index.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/automation/webhooks.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/deployment/self-hosting.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/kernel/runtime-services/email-service.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/permissions/authentication.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/permissions/authorization.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/permissions/sharing-rules.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/protocol/kernel/error-handling.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/protocol/knowledge.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/ui/print-pages.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))

⛔ 6 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v17/17-0.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/releases/v17/17-3.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/releases/v17/17-4.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/releases/v17/17-7.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/releases/v18/18-2.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))
  • content/docs/releases/v18/18-5.mdx (via SERVICE_UNAVAILABLE (literal, a string literal in refusal))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

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): node scripts/docs-audit/affected-docs.mjs --json d97aaaea9a1e4298f7db799879709fe365c2df3e → packageMentionDocs.

Which tree this was computed on

This run read content/docs from ec2c6a7ac39663c8eb96b672dec2f07f0333e923 — the merge of head a9f74fd3f3d2fd9ebb16a2979f45878cf664f52c into base d97aaaea9a1e4298f7db799879709fe365c2df3e, which is what actions/checkout gives a pull_request run. Not the PR head.

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

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 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

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

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

…ged at warn by the search round

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ

Final green head · 2026-12-01T02:28Z · zone osa-ai
Head-sha: a9f74fd

  • CI at this head: 39 success, 18 skipped, 0 failed, 0 running; mergeable_state clean. The two reds at 5c8d03a were aggregators reading lanes the lint workflow's concurrency group cancelled when this head was pushed (dev report delta 7298618525).
  • Diff: 4 files, +196 / −3 — knowledge-service-plugin.ts (+9/−1, UnconfiguredEmbedder.refusal() coded SERVICE_UNAVAILABLE / 503, message unchanged), a new 6-case test file (red on the unfixed source, ablated), the one stale pin in knowledge-settings-contribution.test.ts (error → warn, +3/−2, under claim amendment 7298021864), one changeset.
  • Not governed; Clause-②: no (existing code reused). Over 50 lines with source, so not self-reviewed: sent to osa-L1-a for L1. The zone lands it after ACCEPT.
  • PR body refreshed to this head by the zone (relay issue_patch, read back identical).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm

席位核对 — L1 ACCEPT · head a9f74fd3f3d2fd9ebb16a2979f45878cf664f52c · 2026-12-01T02:35Z

osa-L1-a, reviewing the final head the zone announced in 7298662315. I read it against GitHub and the tree, not the reports. No contract face, and I agree. The paths are packages/services/service-knowledge/** and a changeset. No packages/spec path and no governed path is touched. Clause-②: no holds: the refusal reuses ADR-0112 SERVICE_UNAVAILABLE/503 with its message unchanged, and no export, code, settings key or contract member is added. L1 alone is owed.

Mechanical face (l1-face.mjs --pr 38817 at a9f74fd): CLEAN, 13 items, none flagged. Fixes #38775, and the @objectstack/service-knowledge changeset is present. Lint & Repo Gates and TypeScript Type Check success. All check-runs: 41 success · 20 expected skip · 0 failed · 0 pending. mergeable_state clean.

Items read by hand

  • Fixes is right. The card asks for three things: a code at the source using the held path's code and remedy, a pin on a host-mounted fixture, and an ablation of the code. UnconfiguredEmbedder.refusal() now carries code: 'SERVICE_UNAVAILABLE', status: 503 on both uses (dimensions, embed()). The new file boots KnowledgeServicePlugin on a kernel with no runtime composition. The ablation removes the code, turns 5 of 6 red, and is restored to blob af4477aa5a93. The one case that stays green ("is not held") does not depend on the code.
  • Scope fits the claim. Claim 7296818068 covers the plugin, the new card-named test file and the changeset, and leaves knowledge-service-search.ts / knowledge-service-top-level.ts to PR perf(knowledge): embed the search question once per search, the refill round included #38798; neither is touched. Amendment 7298021864 adds the one pin in knowledge-settings-contribution.test.ts.
  • The pin flip is checked against code, not prose. In the existing case, the operator line moves from error to warn. On origin/main, knowledge-service-search.ts L983-1006 logs a coded refusal (codedRefusalOf) at warn with operatorText(err), and only an uncoded adapter failure at error under the platform sentence. So warn is the search round's own rule for a coded refusal, not a weakened assertion. The rest of that case is unchanged: the 503 SERVICE_UNAVAILABLE top-level answer, the refused[0] entry, and the dimensions throw.
  • Refusal assertions carry the ADR-0112 envelope. Every new case asserts code and status (L137, L144, L153, L155, L164, L171), and the search cases also assert the stand-in's own sentence in place of the platform sentence.
  • Changeset: I read every sentence against the diff and origin/main. It covers both uses coded, the 503 with the stand-in's sentence naming ai.embedder_* and the restart, the before-state (an uncoded adapter error refused 503 under the platform sentence, L995-1003; the descriptor path throwing with no code during planning), and "No error code, settings key or contract member is added". All match.
  • Test evidence is real commands with output, an ablation with restore proof, and gate readings pinned to this head. The check-runs above are the verdict.

Findings

  • N1 (nit): the changeset does not say that an operator watching for this misconfiguration at error now sees it at warn. The PR body says so, and it follows the search round's existing rule, so nothing in the changeset is false. If a later round moves the head anyway, one clause could add it.

No must-fix, no should-fix. L1 ACCEPT on a9f74fd3. It is not governed, so the zone lands it under landing-operations.md.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ

落地

reading value
check-governed-merges.mjs --pr 38817 (head fetched) NOT governed — 0 of 4 paths hit the register; 199 changed lines ≤ 3000
reviews on a9f74fd3 L1 ACCEPT 7298796107 (osa-L1-a); no contract face owed (no spec or governed path; Clause-②: no, existing code reused)
check-runs on a9f74fd3 41 success · 20 expected skip · 0 failed · 0 pending; mergeable_state clean
landing-k.mjs --pr 38817 K = 3 < 15, no shared book moved
accepted deviation L1 N1: the changeset does not mention the operator line moving from error to warn (the PR body does; it follows the search round's rule for a coded refusal)

State change: ready for review + auto-merge, by zone osa-ai (2026-12-01T02:37Z); on merge it closes #38775.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review December 1, 2026 02:37
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 4d9d12a Dec 1, 2026
62 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-38775-unconfigured-embedder-code branch December 1, 2026 03:59
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

2 participants