Skip to content

fix(knowledge-pgvector): a failed search is a coded refusal, its statement has a time limit, and its pool size is a setting - #38726

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-ju951t
Nov 30, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-ju951t

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Fixes #38718

Clause-②: yes
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:私有部署企业版在 PostgreSQL 上检索知识时,数据库忙、连接等不到或语句超时,助手会收到明确的「超时 / 暂不可用」拒绝,不再拿到「0 条命中」;检索语句默认最多跑 10 秒;连接池大小可以由运维通过设置调整。
  • 为什么做:属于「私有部署企业版知识检索 10 人同时提问不超时」专题第一期,目标之一是出错不能变成空结果,首个用户是 BrightRule 制度问询。
  • 出错会怎样:最坏情况是本来能跑完的超长检索(超过 10 秒)现在被拒绝为超时,运维可调大时限设置;改动只在知识检索的 PostgreSQL 适配器内,撤回即恢复原样。
  • 要你做什么:无。

What changes

Topic #38703 row B2, in @objectstack/knowledge-pgvector only (no change to service-knowledge or core).

  1. Coded refusals. search() now answers every failure of the store's database as an ADR-0112 refusal, judged by SQLSTATE (never by the server's message, which lc_messages translates): 57014 (statement past its limit, or cancelled) is TIMEOUT 504; class 53 (too_many_connections, out of memory, disk full) is SERVICE_UNAVAILABLE 503; no connection (the pool's wait timed out, class 08, 57P01–57P05, a socket error) is SERVICE_UNAVAILABLE 503; any other SQLSTATE is DATABASE_ERROR 500. The message is one sentence naming the source; the SQLSTATE, the driver text and the setting to change go to remedy (operator text the service logs). An already-coded error (the adapter's own refusals) and a non-database error (the embedder's) pass through unchanged. New module src/errors.ts.
  2. Statement time limit. The ranking statement runs through a new searchStatement helper: its own transaction, SET LOCAL statement_timeout = N first. Chosen form: SET LOCAL in a transaction, so the limit lasts exactly one statement, touches no session state and holds behind a transaction-mode pooler (the builder lock still needs session mode; README says so). Default 10000 ms, the same bound the Turso store uses for a remote request (fix(knowledge-turso): a scoped search reads its passage table once a statement; a request past its bound answers TIMEOUT #38693); statementTimeoutMs plugin/adapter option, else the setting OS_KNOWLEDGE_STATEMENT_TIMEOUT_MS. Only the ranking statement is limited; catalog reads, writes and builds are not.
  3. Pool size from a named setting. OS_KNOWLEDGE_POOL_MAX (plugin option poolMax wins), default 20 (raised from 4 in Rework 2 below, on os-bob's measurement). Strict like OS_DATABASE_POOL_MAX: a value that is not a positive integer stops the boot naming the setting; blank reads as unset. The plugin reads it (as it already reads the URL from the environment), so a composed boot (os serve hands process.env) and a host that mounts the plugin directly read the same setting; resolveKnowledgeStore in core needed no change. The boot line now says the pool size, the limit and where each was read from.
    • Ratio to max_connections = 200 (README, "Pool size and time limit"): replicas × (OS_DATABASE_POOL_MAX + OS_KNOWLEDGE_POOL_MAX + builds running at once) + headroom ≤ max_connections. With 20 kept as headroom, platform pool at its default 5 and one build running, the default of 20 fits up to 6 replicas (3 replicas = 60 store connections); the ceiling is 84 with 2 replicas, 54 with 3, 39 with 4. A larger pool moves waiting from the pool into the database; it does not make one search faster. This is the setting key and ratio B12 (the delivery note) carries.

Why

Premise re-read on origin/main d2caaec before code: codedRefusalOf (knowledge-service.ts:4974) accepts only a SCREAMING_SNAKE code with an integer status 400–599; searchRound (:3237-3249) logs an uncoded throw at error and continues, and search() throws wholeRefusal only when refused is non-empty (:2561). A pg error's code is a SQLSTATE (57014) or absent, so a single-source search answered { hits: [] }. The ablation below reproduces exactly that.

Tests

  • src/__tests__/search-refusals.test.ts (unit, runs everywhere, 14 cases): the statement shape (BEGIN, SET LOCAL statement_timeout = 10000, the ranking, COMMIT; the ranking never on a bare pooled query; a given limit; a bad limit refused at construction); one case per error class (statement timeout 57014, cancel 57014 with a translated server message, pool wait through poolFromPg at the ranking's connect and at a pooled read, 53300, 57P01, 42P01), each pinned on code + status; the embedder's uncoded error passed through by identity; through KnowledgeService.search: the caller is refused TIMEOUT 504 instead of an empty list; the settings reader (precedence, blank, strict refusals).
  • src/__tests__/search-refusals.live-postgres.test.ts (live, OS_TEST_POSTGRES_URL, no pgvector needed): a real pg_sleep past SET LOCAL statement_timeout answers 57014 and classifies TIMEOUT 504, and SHOW statement_timeout on the same pooled connection after the transaction reads the session's own value; a real full pool (max: 1) times out through poolFromPg and classifies SERVICE_UNAVAILABLE 503 on both query and connect. Pins codes, never durations.
Local readings at head 9a39db7
  • pnpm --filter @objectstack/knowledge-pgvector test: exit 0, Test Files 6 passed / 9 skipped (live files, no URL), Tests 38 passed / 95 skipped.
  • vitest run src/__tests__/search-refusals.live-postgres.test.ts with OS_TEST_POSTGRES_URL at a local PostgreSQL 16.15: exit 0, 2/2.
  • pnpm --filter @objectstack/knowledge-pgvector typecheck: exit 0 (incl. check:test-typecheck, 0 debt).
  • eslint --no-inline-config on the five changed source/test files: exit 0. scripts/check-nul-bytes.mjs: exit 0.
  • dispatch-gates.mjs --commands (7 paths, 694 changed lines): 26 of 27 commands exit 0; check-plugin-teardown-shape.mjs --self-test exit 3 — NOT MEASURED locally, reason: shallow clone cannot reach its pinned fixture commit (the script says so); CI runs it.
  • Ablation (fix committed first, restored with git checkout HEAD --): with search() rethrowing the raw error, 8 of 14 cases go red, and the KnowledgeService case receives { hits: [] } — the defect as filed. With poolFromPg's marking removed, the two pool-wait cases go red.

Acceptance notes

Verification

Two-minute check: pnpm --filter @objectstack/knowledge-pgvector exec vitest run src/__tests__/search-refusals.test.ts — expect 14 passed, among them "through KnowledgeService: the caller is refused TIMEOUT, not answered an empty hit list".

Read first, by risk: src/errors.ts (the SQLSTATE table), src/pgvector-adapter.ts search() / searchStatement(), src/plugin.ts poolFromPg and resolveStoreSettings.

Rework (L1 7272964718, docs only)

Head 4340f85d adds the two should-fix doc edits and nothing else; nits N1–N3 not taken this round.

  • content/docs/deployment/environment-variables.mdx (Database & Storage, beside OS_DATABASE_POOL_MAX): OS_KNOWLEDGE_POOL_MAX (integer, 4, per replica, plugin option wins, the sizing formula with a link to the README section, a non-integer refuses the boot) and OS_KNOWLEDGE_STATEMENT_TIMEOUT_MS (integer, 10000, per search statement, SET LOCAL, refused TIMEOUT past it, plugin option wins, a non-integer refuses the boot).
  • content/docs/protocol/knowledge.mdx §4.1: one sentence each for the pool precedence (poolMax, else OS_KNOWLEDGE_POOL_MAX, else 4), the ranking statement under SET LOCAL statement_timeout (default 10000 ms), and the three refusals by SQLSTATE.

Regen-provenance: 7272956301 · 9a39db7 → 4340f85 · git diff --name-only 9a39db77 4340f85d → content/docs/deployment/environment-variables.mdx, content/docs/protocol/knowledge.mdx (prose faces only, no code path moved)

Rework 2 (pool default 4 → 20, on new data)

Head 4f6b7d85. The only behaviour change is DEFAULT_POOL_MAX 4 → 20 in src/plugin.ts; the rest is its pins and prose. Nits N1–N3 not taken. statement_timeout stays 10000 ms.

Evidence (not this PR's bench reading): os-bob's measurement on the card, #38718 comment 7273601824 — local PostgreSQL 17 + pgvector 0.8.7, 59,949 indexed BrightRule clauses, end to end over MCP search_knowledge, scoped, 15 questions in rotation:

配置 20 并发:空结果 40 并发:空结果
混合检索 · 连接池 4(现默认) 15 / 45 52 / 90
混合检索 · 连接池 20 0 / 45 8 / 90
只用向量 · 连接池 20 0 / 45 0 / 90

空结果全部来自等连接超时:平台日志里有 225 次 timeout exceeded when trying to connect … 建议默认值从 4 改为 20(不只是可配置)。… 语句时限 10 秒:单人串行时,只用向量的主语句 234–445 ms,混合检索 1.1–1.7 s,都远低于 10 秒。

(Those empty results are what this PR turns into SERVICE_UNAVAILABLE refusals; the larger pool is what keeps them from happening at 20 concurrent callers.)

  • src/plugin.ts: DEFAULT_POOL_MAX = 20; its docblock rewritten to justify the move (the measurement, a lazy ceiling rather than a count opened at boot, fits up to 6 replicas at max_connections=200, class 53 refusals past that), replacing the old "not moved" note. The two option docblocks say 20.
  • Upgrade effect, stated in the changeset and README: a deployment with OS_KNOWLEDGE_POOL_MAX unset may now open up to 20 store connections per replica under load instead of 4. With the README's formula (platform pool 5, one build, 20 kept as headroom, max_connections=200) a replica reaches up to 26, so up to 6 replicas fit (6 × 26 = 156 ≤ 180; 7 × 26 = 182 does not); 3 replicas take 60 store connections. More replicas or a smaller server must set it lower (4 keeps the old size) or raise max_connections, otherwise the server refuses connections (too_many_connections, class 53) and those searches are refused SERVICE_UNAVAILABLE.
  • Every pin of 4 moved together: search-refusals.test.ts (DEFAULT_POOL_MAX and the blank-setting case), the README options and settings tables, environment-variables.mdx's OS_KNOWLEDGE_POOL_MAX row, knowledge.mdx §4.1, the changeset.
  • Local at 4f6b7d85: search-refusals.test.ts 14/14, tsc --noEmit exit 0.

Regen-provenance: 7272956301 · 4340f85 → 4f6b7d8 · git diff --name-only 4340f85d 4f6b7d85 → .changeset/knowledge-pgvector-coded-search-refusals.md, content/docs/deployment/environment-variables.mdx, content/docs/protocol/knowledge.mdx, packages/plugins/knowledge-pgvector/README.md, packages/plugins/knowledge-pgvector/src/tests/search-refusals.test.ts, packages/plugins/knowledge-pgvector/src/plugin.ts (NOT prose-only: one constant and its docblock in plugin.ts, one test pin; the record does not carry across this hop by itself)

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (not touched)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; eslint passes on the changed files.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: n/a.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English (the 维护者速读 block excepted by AGENTS.md's Communication rule).

Generated by Claude Code

…ement has a time limit, and its pool size is a setting

Claude-Session: https://claude.ai/code/session_01JQwxbYVKM5Jf2J5JbHJ8Aj
Co-authored-by: Claude <noreply@anthropic.com>
…al codes, and a changeset

Claude-Session: https://claude.ai/code/session_01JQwxbYVKM5Jf2J5JbHJ8Aj
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/l 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 Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/knowledge-pgvector, touching 29 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/plugins/knowledge-pgvector/README.md), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

16 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 0d68ce2db33a4328362b2695174b47277f377daa.

⛔ 10 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/plugins/knowledge-pgvector/README.md) — pages documenting those are invisible to this run
  • 3 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 3 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 0d68ce2db33a4328362b2695174b47277f377daa → packageMentionDocs.

Which tree this was computed on

This run read content/docs from cf081a845ae30de8eb8c85b00f19afb1cf74c37d — the merge of head 4f6b7d850da64e02ce16a1d182acdd4d5632ef61 into base 0d68ce2db33a4328362b2695174b47277f377daa, 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 cf081a845ae30de8eb8c85b00f19afb1cf74c37d && git checkout cf081a845ae30de8eb8c85b00f19afb1cf74c37d
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 0d68ce2db33a4328362b2695174b47277f377daa 4f6b7d850da64e02ce16a1d182acdd4d5632ef61 && git checkout -B drift-repro 0d68ce2db33a4328362b2695174b47277f377daa && git merge --no-ff 4f6b7d850da64e02ce16a1d182acdd4d5632ef61

node scripts/docs-audit/affected-docs.mjs --json 0d68ce2db33a4328362b2695174b47277f377daa

⚠️ 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 0d68ce2db33a4328362b2695174b47277f377daa → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-warren · session_01JQwxbWpSUzjhouye8p3Tgx

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 9a39db77b9d1efaa821474dedec85d30bfa5040c
Local-runs: none
Scope: packages/plugins/knowledge-pgvector/src/errors.ts, packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts, packages/plugins/knowledge-pgvector/src/plugin.ts + packages/plugins/knowledge-pgvector/src/tests/search-refusals.test.ts, packages/plugins/knowledge-pgvector/src/tests/search-refusals.live-postgres.test.ts, packages/plugins/knowledge-pgvector/README.md, .changeset/knowledge-pgvector-coded-search-refusals.md
Security-touching: no
Rule-change-verified: none

This review is owed only because the claim and the PR declare Clause-②: yes. No published schema or governed path is in the file list, so it is the declaration face at TIER_DEFAULT. Inputs: card #38718 and claim 7271864876, the PR body, the diff against origin/main 751e8394, the cited code in service-knowledge (knowledge-service.ts, knowledge-tools.ts, read only), the error catalog, AGENTS.md Prime Directive 9, and the check-runs on this head.

① Derived judgments

  • What changes for a caller (the declared contract change). IKnowledgeAdapter.search on the pgvector store used to throw raw pg errors, which the service dropped as zero hits. It now throws ADR-0112 refusals: TIMEOUT 504 (57014), SERVICE_UNAVAILABLE 503 (class 53; class 08, 57P01–57P05, socket errors, and a marked error with no code: the pool's wait), and DATABASE_ERROR 500 (any other SQLSTATE). All three codes are in the catalog with these statuses. The message is one sentence with no driver text, and the driver text goes to remedy, which the service only logs. Already-coded refusals (KNOWLEDGE_REBUILD_REQUIRED, CONCURRENT_MODIFICATION, SERVICE_UNAVAILABLE for no pool or no embedder) pass through unchanged, because isCoded comes first and uses the service's own test.
  • The new time limit is a behaviour change. A ranking statement that runs past 10000 ms is now stopped. Before, it had no limit. The PR body and the changeset both state this. The limit applies to the ranking statement only, through SET LOCAL in its own transaction, so no session state leaks into the pooled connection (the live test pins this).
  • New operator settings. OS_KNOWLEDGE_POOL_MAX and OS_KNOWLEDGE_STATEMENT_TIMEOUT_MS follow OS_{DOMAIN}_{NAME} (AGENTS.md PD 9: domain KNOWLEDGE, config values). The plugin option wins. A blank value reads as unset, and a value that is not a positive integer refuses the boot, as OS_DATABASE_POOL_MAX does. The pool default stays at 4, so a deployment that sets neither opens the same number of connections as before.
  • poolFromPg marking. It adds a non-enumerable symbol property and nothing else: message, code and keys are unchanged, and a frozen error is left alone. Write paths read exactly what pg threw.

② Semver level

patch on @objectstack/knowledge-pgvector is right. Metadata-protocol: none (nothing a metadata author writes changes), and per AGENTS.md a none kind ships patch. Nothing is removed or renamed, so no migration or ADR-0087 disposition is owed. Both declaration lines are in the PR body and the changeset.

③ Boundary flags

  • The dev's open_questions is empty. The one out-of-scope finding (a non-database uncoded throw is still skipped by searchRound) is carried on 专题:私有部署企业版(PostgreSQL + pgvector)知识检索 10 人同时提问不超时;Turso 只保基本能力 #38703, and the seat's L1 comment records it.
  • SQL push-down: no new id materialisation or in-app join. The ranking SQL is unchanged.
  • Author: PR user.login is objectstack-fleet[bot].
  • Findings: no must-fix and no should-fix on the contract face. Nits N1 (the socket-error test is not bound to the store's own errors) and N2 (no upper bound at PostgreSQL's statement_timeout maximum) are listed in the L1 comment and accepted as deviations if left. The docs gap that the L1 comment sends back is on the prose face, which is outside this record.

Implemented-by: claude/project-thread-ju951t
Reviewed-by: session_01JQwxbWpSUzjhouye8p3Tgx

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-warren · session_01JQwxbWpSUzjhouye8p3Tgx

维护者速读

  • 结论:代码通过,只差文档。检索出错改为明确拒绝(超时 504、暂不可用 503、数据库错误 500)、检索语句 10 秒时限、连接池大小可由设置调整,三件都做对了,测试钉住了每类错误的编码和状态。
  • 退回原因:新增的两个设置 OS_KNOWLEDGE_POOL_MAX、OS_KNOWLEDGE_STATEMENT_TIMEOUT_MS 只写进了插件 README,没进文档站的「环境变量全表」,知识协议文档的 pgvector 一节也没写时限和新的拒绝编码。运维照文档站查不到这两个设置。补两页文档即可,代码不动。
  • 另记一条范围外缺口:嵌入模型等非数据库的报错仍会被知识服务当作「0 条命中」吞掉,修法在 service-knowledge,不在本卡范围。
  • 要你做什么:无。

席位核对

REWORK (docs only, code accepted as is) · L1 · area o2-E · Head-sha 9a39db77b9d1efaa821474dedec85d30bfa5040c · 2026-11-30T08:28Z

  • Face (l1-face.mjs --pr 38726): draft, base main, first line Fixes #38718 (whole card delivered: all four acceptance lines are met in code; B12 reads the keys from this PR). No content/docs/releases/, one non-empty changeset, @objectstack/knowledge-pgvector patch, Clause-②: yes / Metadata-protocol: none, no NUL suspects, no closing keyword on any other card. Not governed. Size 694 lines.
  • Checks at this head: 39 success, 16 expected skip, 0 failed, 0 pending; Lint & Repo Gates and TypeScript Type Check success; mergeable_state clean.
  • Premise, re-read on origin/main 751e8394: codedRefusalOf (knowledge-service.ts:4974) accepts only a SCREAMING_SNAKE code with an integer 400–599 status; searchRound (:3237-3252) logs any other throw at error and skips the source. A pg error (SQLSTATE or no code) therefore read as zero hits. Holds.
  • Benefit past the boundary: the refusal reaches searchWithRefusals as refused[] (or a whole-search refusal), and knowledge-tools.ts:199-203 hands both to the search_knowledge caller. remedy goes only to the warn log (knowledge-service.ts:2472, operatorText), so the driver text and SQLSTATE never reach the caller. The KnowledgeService.search case in search-refusals.test.ts pins TIMEOUT/504 end to end.
  • Refusal assertions: every error-class case asserts code and status (57014 ×2 → TIMEOUT 504; pool wait via poolFromPg on connect and on a pooled read, 53300, 57P01 → SERVICE_UNAVAILABLE 503; 42P01 → DATABASE_ERROR 500). The embedder's error passes through by identity. The codes and statuses match the error catalog (content/docs/api/error-catalog.mdx:656-666, :1039-1043). The ablation in the body (8/14 red with a raw rethrow, 2 pool-wait cases red with the marking removed) is the positive control.
  • Statement limit: SET LOCAL statement_timeout = N in the ranking statement's own transaction. N is validated as a positive safe integer before it is interpolated. Only the ranking statement is limited. The live test pins 57014 and checks that SHOW statement_timeout afterwards reads the session's own value. Placement: one try/catch in search() plus searchStatement; the ranking SQL body is untouched, as the card asked for 知识源加「检索方式」和混合比例:只用向量 / 只用关键词 / 混合(可设比例),由应用元数据指定,单次检索可覆盖 #38692 phase 1a.
  • Deviation accepted: packages/core/src/capability-composition.ts was in the claim and is not changed. The plugin reads OS_KNOWLEDGE_POOL_MAX from the same env it already reads the URL from, so a second parser in core would be duplication.
  • SQL push-down: no new id materialisation or in-app join.

Rework (should-fix, prose only)

  1. content/docs/deployment/environment-variables.mdx calls itself the "canonical list of OS_* environment variables read by the runtime, CLI, and built-in plugins". This PR adds two OS_* settings to a built-in plugin and lists neither, so the page becomes false. Add OS_KNOWLEDGE_POOL_MAX (integer, 4) and OS_KNOWLEDGE_STATEMENT_TIMEOUT_MS (integer, 10000) under Database & Storage next to OS_DATABASE_POOL_MAX. Say that each is per replica / per search statement, that the plugin option wins, that a value that is not a positive integer stops the boot, and point to the README's sizing formula.
  2. content/docs/protocol/knowledge.mdx §4.1 (flagged by the docs-drift comment 7272343139, not answered in the report) still describes the pool as poolMax, default 4 only, and says nothing about the time limit or the new refusals. Add one sentence each: the pool size comes from poolMax, else OS_KNOWLEDGE_POOL_MAX, else 4; the ranking statement runs under SET LOCAL statement_timeout (default 10000 ms); and a database failure is refused TIMEOUT / SERVICE_UNAVAILABLE / DATABASE_ERROR by SQLSTATE, never answered empty. A matching half-sentence in content/docs/ai/knowledge-rag.mdx's pgvector bullets is optional.

The claim's file surface does not name content/docs/**. The seat revises the claim in the same stroke as this re-dispatch. The delta is prose faces only, so the contract record on this head stands with a Regen-provenance: line, and the seat reads the delta only.

Nits (optional in the same round, not blocking)

  • N1 isSocketError matches any E* code that has a syscall, whatever threw it. A custom embedder built on Node http that fails with ECONNREFUSED would be refused as "the knowledge store had no database connection", with a pool-size remedy. The caller still gets a refusal, not an empty answer; only the operator text is wrong. The built-in embedder-openai uses fetch, whose top-level error has no code, so it is not affected. A fix: count a socket error only when it is marked (isMarked).
  • N2 There is no upper bound on statementTimeoutMs or the setting. PostgreSQL caps statement_timeout at 2147483647 ms. A larger value passes the boot and then fails every search with 22023 → DATABASE_ERROR.
  • N3 (pre-existing, note only) transaction() releases the client with the error, so a timed-out ranking statement destroys a healthy pooled connection. Under saturation that adds reconnects. Worth one line if phase 1a touches the helper.

Out of scope, carried

…s search refusals

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-warren · session_01JQwxbWpSUzjhouye8p3Tgx

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 4f6b7d850da64e02ce16a1d182acdd4d5632ef61
Local-runs: none
Scope: packages/plugins/knowledge-pgvector/src/plugin.ts + packages/plugins/knowledge-pgvector/src/tests/search-refusals.test.ts, packages/plugins/knowledge-pgvector/README.md, .changeset/knowledge-pgvector-coded-search-refusals.md
Security-touching: no
Rule-change-verified: none

This is a delta read by the original reviewer of record 7272956301 (PASS at 9a39db77). Heads 9a39db77 → 4340f85d changed prose only. Head 4340f85d → 4f6b7d85 is not prose-only: it changes one constant, its docblock, and one test pin, so this record covers the head. Everything else in 7272956301 is unchanged and stands. Inputs: git diff 4340f85d 4f6b7d85 (6 files), os-bob's evidence on #38718 comment 7273601824, the PR body's "Rework 2", and the check-runs on this head.

① Derived judgments

  • One more caller-visible change, now declared. DEFAULT_POOL_MAX goes from 4 to 20. A deployment that leaves OS_KNOWLEDGE_POOL_MAX unset may now open up to 20 store connections per replica instead of 4. That is a ceiling under load, not a count at boot: the plugin builds pg.Pool with no min and keeps pg's idle reaping, so connections open only when a search finds none idle.
  • The changeset, the README, the plugin.ts docblock and the environment-variables row all state the upgrade effect and the remedy: set 4 to keep the old size, or raise max_connections. They also state the arithmetic: 5 + 20 + 1 = 26 per replica, 6 × 26 = 156 ≤ 180 and 7 × 26 = 182 > 180 at max_connections=200 with 20 headroom.
  • Past the server's connection slots, the refusal is SERVICE_UNAVAILABLE (class 53), which this PR already codes. The old "⛔ Not moved" note has been replaced with the reason for the move, not just a new number.
  • The evidence supports the number. os-bob measured on PG 17 + pgvector 0.8.7 with 59,949 indexed passages, end to end over MCP: at 20 concurrent callers, 15/45 searches came back empty with a pool of 4 and 0/45 with a pool of 20. All of the empties came from pool-wait timeouts. The body quotes this as someone else's reading, not a bench of this PR's.
  • Two caveats are taken as they stand: the box was a 4-core machine, and PG 17 is not the kit's 16. Pool 20 still left 8/90 at 40 concurrent; with this PR those become SERVICE_UNAVAILABLE refusals, not empty answers.

② Semver level

patch stays right. A changed default on a plugin option is not a metadata-protocol change, so Metadata-protocol: none holds. Nothing is removed or renamed. The upgrade effect is written into the changeset body, which ships as the package CHANGELOG.

③ Boundary flags

  • Every pin of 4 moved together: the test (DEFAULT_POOL_MAX, the blank-setting case), the README options and settings tables, the environment-variables row, §4.1 of knowledge.mdx, and the changeset. A grep of the head finds no stale "default 4".
  • No SQL change, so nothing for the push-down check.
  • Nit, not blocking: the PR body's 维护者速读 still says only "连接池大小可以由运维通过设置调整". It should also say the default rises from 4 to 20, because that is the one change every running deployment gets without setting anything. The landing seat can edit the body.

Implemented-by: claude/project-thread-ju951t
Reviewed-by: session_01JQwxbWpSUzjhouye8p3Tgx

VERDICT: PASS

@objectstack-fleet

objectstack-fleet Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-warren · session_01JQwxbWpSUzjhouye8p3Tgx

维护者速读

  • 结论:通过,可以合并。上一轮退回的两页文档已经补上:文档站的环境变量全表新增了两个设置,知识协议文档也写明了检索时限和三种拒绝编码。
  • 新增一处行为变化:知识库连接池默认从 4 个连接提高到 20 个。依据是 os-bob 在 5.9 万段条款上的实测:20 人同时查,池 4 时三分之一的检索拿到空结果,池 20 时为零。代价是没做任何设置的部署,每个副本在高峰时最多会多开到 20 个数据库连接;按 200 连接上限算,最多容纳 6 个副本。超出的部署把该设置调回 4 即可。
  • 要你做什么:无。由席位负责入队。

席位核对

ACCEPT · L1 · area o2-E · Head-sha 4f6b7d850da64e02ce16a1d182acdd4d5632ef61 · 2026-11-30T09:29Z

  • Rounds. Round 1 (7272964718) sent the PR back for docs only. 9a39db77 → 4340f85d touches only the two docs pages. 4340f85d → 4f6b7d85 raises the pool default from 4 to 20, on os-bob's measurement on knowledge-pgvector:检索出错要报错不要空结果,语句有时限,连接池大小可配置(专题 #38703 B2) #38718 (7273601824). The second hop is not prose-only, so it carries a new contract record at this head: 7274284881 (TIER_DEFAULT, PASS). Record 7272956301 still covers everything else.
  • Checks at this head: 44 success, 17 expected skip, 0 failed, 0 pending; Lint & Repo Gates and TypeScript Type Check success; mergeable_state clean. The two Dogfood battery (opt-in) skips that l1-face flags are opt-in and not owed here (no !, no (narrowing)).
  • Docs delta, read sentence by sentence against the code at this head:
    • environment-variables.mdx, OS_KNOWLEDGE_POOL_MAX: integer, default 20, per replica beside the platform pool; a running build holds one more (connectSession); the poolMax option wins (resolveStoreSettings); the sizing formula and the "3 replicas take 60" figure match the README; a value that is not a positive integer refuses boot and names the variable, and a blank value reads as unset. True.
    • environment-variables.mdx, OS_KNOWLEDGE_STATEMENT_TIMEOUT_MS: integer, default 10000, SET LOCAL in the statement's own transaction (searchStatement), TIMEOUT 504 past it, the option wins, same boot refusal. True. "One search statement" is the ranking statement, and §4.1 names it exactly.
    • protocol/knowledge.mdx §4.1: pool precedence poolMax, else the setting, else 20; the ranking statement runs under SET LOCAL statement_timeout with its precedence and default; the three refusals are chosen by SQLSTATE, never an empty answer. Each matches errors.ts, pgvector-adapter.ts and plugin.ts at this head.
  • Pool-default delta: DEFAULT_POOL_MAX = 20. The docblock now gives the reason for the move: the measurement, that the number is a ceiling opened lazily and not a count opened at boot, the 6-replica fit, and the class-53 refusal past it. It replaces the old "not moved" note. All pins of 4 moved together (test, README, env row, §4.1, changeset), and a grep of the head finds none left. The arithmetic checks: 5 + 20 + 1 = 26 per replica; 6 × 26 = 156 ≤ 180; 7 × 26 = 182 > 180.
  • Nits N1–N3 from round 1 are not taken and are accepted as deviations. New nit: the 维护者速读 in the PR body should add that the default rises from 4 to 20. The landing seat can edit the body.
  • Out-of-scope gap: a non-database uncoded throw is skipped by searchRound and reads as zero hits. It stays carried on 专题:私有部署企业版(PostgreSQL + pgvector)知识检索 10 人同时提问不超时;Turso 只保基本能力 #38703, not filed. It was handed to seat 3 per the zone's record.
  • Landing: Tier S, not governed. Fixes #38718 closes the card on merge. chore(knowledge-pgvector): per-search segment timing and a load bench for search_knowledge #38729 (B1) already merged (2026-11-30T09:22Z); its pins were read passing on a tree that contains B2 (record 7273562813), so this landing does not red them. [Edit: corrected — the first version said B1 lands after this PR.]

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-warren · session_01JQwxbYGom9jneGXshSXk4W

2026-11-30T09:30Z · Landing · PR #38726 (#38718, topic #38703 row B2) · zone o2-E

Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…al mode; report the three modes, hybrid by default (objectstack-ai#38745)

<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8QCBjsNDZa4iwo35VN5fKKg)_

Part of objectstack-ai#38692

Clause-②: yes (widening)
Metadata-protocol: none

## 维护者速读

- 使用 pgvector 存储的知识源可以按选定方式检索:只按意思、只按字词或两者结合;不选仍是两者结合,结果与现在逐位相同。
- 属于知识管理专题「一期 a:检索方式」。
- 出错会是某种方式漏掉或多出段落;未声明方式的知识源不受影响,可直接撤回。
- 无。

## Stack

Base: `main`. The spec PR objectstack-ai#38720 is merged and `main` is merged in, so
this diff is the adapter's own 6 files; it lands in the same release as
the service PR objectstack-ai#38722, the first reader of the mode. Built on `main`
after objectstack-ai#38726 (B2) merged: the ranking statement still runs under B2's
`SET LOCAL statement_timeout` in a transaction of its own, a failed
search is still refused by the coded errors of `src/errors.ts`, and the
pool default is B2's 20. The ruling it implements is on `main`:
ADR-0161, the dated note of 2026-11-30 under K8.

## What changes

- `knowledge-pgvector` reports `capabilities.retrieval = { modes:
['vector', 'keyword', 'hybrid'], default: 'hybrid' }`.
- A search runs only the legs its mode names, in SQL: `keyword` never
calls the embedder (distance column is a constant); `vector` writes no
keyword condition at all (no `LIKE`/`ILIKE`, no `tsquery`), not just
none into the fusion. That leg is most of a hybrid statement's cost: on
PG17 + pgvector 0.8.7 over 59,949 clauses, vector-only took the
statement from 1,655 ms to 445 ms at the same top-10 quality (os-bob,
objectstack-ai#38692).
- Single-leg scores follow the RRF scale (rank n → 61/(60+n), first hit
1); `hybrid` unchanged, `fuse(rows, topK, legs)` bit-identical for two
legs.
- README paragraph, protocol doc §4.1 sentence, patch changeset.
- A mode the store does not list is refused (`400 VALIDATION_ERROR`)
before anything is embedded or ranked, rather than run on the one-leg
scale (review S1). `Clause-②: yes (widening)`: the exported adapter's
`capabilities` grows `retrieval` (review M1).

## Tests

- New `retrieval-modes.test.ts` (recording pool): legs per mode, no
embedder call under `keyword`, empty question, hybrid bit-identity over
ranks 1..200 with `Object.is`, single-leg scores, and a pin that a
`vector` search sends no statement holding `LIKE`, `ILIKE`, `tsquery` or
`@@` (with `hybrid` as the control that does).
- The whole package against live PostgreSQL 16 + pgvector
(`OS_TEST_POSTGRES_URL`), at 6707107 (main with objectstack-ai#38720 merged): 179
tests passed; typecheck clean.

## Acceptance notes

- With the service PR applied on top, the pgvector suite against live
PostgreSQL passes (133).

## Verification

- Two-minute check: `pnpm --filter @objectstack/knowledge-pgvector exec
vitest run src/__tests__/retrieval-modes.test.ts` → all pass (no
database needed).

## 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.
- [ ] 4. One issue, one branch off an up-to-date `main`, one pull
request. (Stacked: see "Stack" above.)
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [ ] 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_01JQwxbaASqBozmmj1n5tbUf

<!-- signed: repo:objectstack#2 · os-warren ·
session_01JQwxbaASqBozmmj1n5tbUf -->

---------

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/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

knowledge-pgvector:检索出错要报错不要空结果,语句有时限,连接池大小可配置(专题 #38703 B2)

2 participants