Skip to content

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

Description

@objectstack-fleet

repo:objectstack#2 · os-warren · session_01JQwxbYGom9jneGXshSXk4W

Filing category ④ — child card of topic #38703, row B2 · Source: topic #38703

Grade: priority:p1 · area:ai · inherits the topic's grade; phase 1 exit criterion "an error never becomes an empty result" depends on this card.

维护者速读

  • 问题:私有部署企业版在 PostgreSQL 上检索时,语句没有时限;等不到数据库连接时,助手拿到的是「0 条命中」而不是报错,用户以为制度里没有这一条。
  • 本卡做:(1) 检索语句设时限,超时报 TIMEOUT;(2) 所有数据库错误都变成带编码的拒绝;(3) 连接池大小改为可配置。
  • 不做:提速。实测调大连接池几乎不改善耗时,(3) 只为可配置。

Business reason

The topic's phase-1 target (maintainer, 2026-11-30): 「需要考虑如何尽快出第一个可用的版本」 — on a self-hosted Enterprise PostgreSQL deployment, ten people asking at once get no timeouts and no silent empty results. Today a pool-wait timeout reaches the assistant as zero hits, so the answer "no policy covers this" is indistinguishable from "the database was busy". BrightRule policy inquiry is the first customer.

Premise (read on origin/main d2caaec, 2026-11-30T07:30Z)

  • packages/plugins/knowledge-pgvector/src/plugin.ts:155-156 — the pool is fixed: max: this.opts.poolMax ?? 4, connectionTimeoutMillis: this.opts.connectTimeoutMs ?? 5000.
  • grep -rn statement_timeout packages/plugins/knowledge-pgvector/src — 0 hits: no statement time limit.
  • The topic body records (not re-measured here): resolveKnowledgeStore in packages/core/src/capability-composition.ts passes only { url }; a pool-wait timeout from pg carries no status, codedRefusalOf in service-knowledge does not recognise it, and searchRound logs one error and skips the source — the caller sees 0 hits and no refusal. The dev re-reads these call sites on the tree before writing code.

What (topic row B2, verbatim)

(1) 检索语句设时限,用 PostgreSQL 自带的 statement_timeout,超时返回编码的 TIMEOUT;(2) 适配器把检索里所有 pg 错误(等连接超时、语句被取消、连接数用尽)都转成带编码的拒绝,调用方看到拒绝而不是空结果;(3) 连接池大小从设置读取(写明设置键名、默认值、与 max_connections=200 的配比,按多副本算)。实测显示调大连接池几乎不改善耗时,(3) 只为可配置,不为提速。只改 capability-composition.ts 和 knowledge-pgvector,不改 knowledge-service.ts

Constraints from the topic

  • Only PostgreSQL's own facilities (statement_timeout, SET LOCAL in a transaction or a per-connection setting); nothing a vector database should provide is built in the knowledge engine.
  • A test pins statement shape / error code / call count, never wall-clock time.
  • A coded refusal must reach the search_knowledge caller; an empty result on error is the defect.
  • The time limit must survive a transaction-mode PgBouncer question: the delivery note (B12) states that transaction-mode PgBouncer is unsupported in front of the store; prefer a form that does not depend on session state where possible, and say which form was chosen.

Overlap

Acceptance

  • A search whose statement exceeds the limit answers a coded TIMEOUT refusal at the search_knowledge caller.
  • A pool-wait timeout, a cancelled statement and too many connections each answer a coded refusal; none answers an empty hit list. One test per error class.
  • The pool size is read from a named setting with a stated default; the PR body names the key, the default and the ratio to max_connections=200 for N replicas.
  • Feeds B12 (delivery note) with the setting key.

Dedupe

Topic #38703's dedupe (open and closed, objectstack and cloud): pgvector 11 closed objectstack cards, none on pools or time limits. This seat, 2026-11-30: repo:objectstack-ai/objectstack is:issue is:open label:area:ai knowledge pgvector — 9 hits, none on statement time limits or pool errors.

Activity

  1. added
    priority:p1
    pm:queue
    area:ai
    on Nov 30, 2026
  2. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-warren · session_01JQwxbYGom9jneGXshSXk4W

    2026-11-30T07:42Z · Claim · topic #38703 row B2, on the maintainer's 「整个专题都归你接手 38703 加速处理」 (2026-11-30T07:21Z, project thread). That order lifts the knowledge pause for this topic's phase 1. Order against #38692: seat 2 (session_01JQwxbXyLoBzNYY1U8SNPFu, holder of claim 7270621658) agreed 2026-11-30T07:32Z that B2 lands first; #38692's phase-1a pgvector PR builds from main after it (Notify: serial on merge).

    Triage (lane self-triage, fleet-filed child card): area:ai · priority:p1 (inherits the topic) · type Bug · domain:server (fix lands in packages/plugins/knowledge-pgvector and packages/core).

    Claim: PM loop round 1
    Session: session_01JQwxbYGom9jneGXshSXk4W
    Account: os-warren
    Branch: a new branch from origin/main; the card thread names it on its first push.
    Worktree: objectstack-issue-38718
    Domain: domain:server
    Seat: repo:objectstack#2
    Area: o2-E (topic #38703 zone)
    File surface: packages/plugins/knowledge-pgvector/src/plugin.ts, packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts (reason: error translation at the pool/query boundary only, not search()'s statement body), packages/plugins/knowledge-pgvector/src/errors.ts (reason: new, if a helper module is cleaner), packages/core/src/capability-composition.ts (reason: resolveKnowledgeStore passes the pool setting), packages/plugins/knowledge-pgvector/README.md (reason: the setting key and default). ⛔ Not packages/services/service-knowledge/** (held by #38700).
    Container & model: M, mode:thread, model: default tier — dispatch-gates --tier 2026-11-30: "no path-derived mandate", effort: high
    Clause-②: yes
    Metadata-protocol: none
    Responsibility: the code that produces the risk is objectstack's own (knowledge-pgvector has no time limit and no translation of pg errors; service-knowledge treats an uncoded throw as a skipped source) | no platform path covers it today | reached by every self-hosted Enterprise deployment on PostgreSQL with a knowledge source; BrightRule policy inquiry is the first user.
    Thread-read: none
    Premise: holds — on origin/main d2caaec: grep -rn statement_timeout packages/plugins/knowledge-pgvector/src 0 hits; plugin.ts:155-156 max: this.opts.poolMax ?? 4, connectionTimeoutMillis: this.opts.connectTimeoutMs ?? 5000. The topic's reading of codedRefusalOf / searchRound (an uncoded throw becomes a skipped source) is NOT re-measured here; the thread re-reads it before code.
    Serial constraints cleared: #38692 (claim 7270621658, knowledge-pgvector/src/**) — ordered after this card by its holder, 2026-11-30T07:32Z; #38700 — not touched; #38719 (B1) — disjoint (bench/** only).

  3. added
    domain:server
    pm:dispatched
    and removed
    pm:queue
    on Nov 30, 2026
  4. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-warren · os-warren · session_01JQwxbYVKM5Jf2J5JbHJ8Aj
    os-dev-report

    2026-11-30T07:58Z · card thread of claim 7271864876 (seat repo:objectstack#2).

    {
      "issue": 38718,
      "status": "done",
      "branch": "claude/project-thread-ju951t",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/38726",
      "head": "9a39db77",
      "session": "session_01JQwxbYVKM5Jf2J5JbHJ8Aj",
      "premise_still_valid": true,
      "summary": "Premise re-read on origin/main d2caaec4 and holds: codedRefusalOf (knowledge-service.ts:4974) takes only a SCREAMING_SNAKE code with an integer 4xx/5xx status, searchRound (:3237-3249) logs and skips any other throw, so a pg error (SQLSTATE code or none) answered a single-source search with zero hits; the ablation reproduces exactly that. knowledge-pgvector search() now answers every database failure as an ADR-0112 refusal judged by SQLSTATE (57014 -> TIMEOUT 504; class 53 incl. 53300 -> SERVICE_UNAVAILABLE 503; no connection: pool wait timeout, class 08, 57P01-57P05, socket errors -> SERVICE_UNAVAILABLE 503; other -> DATABASE_ERROR 500), driver text in remedy only; poolFromPg marks its errors (non-enumerable symbol) so the uncoded pool-wait timeout is recognised without message matching. The ranking statement runs in its own transaction after SET LOCAL statement_timeout (default 10000 ms; statementTimeoutMs option, else OS_KNOWLEDGE_STATEMENT_TIMEOUT_MS), chosen because it holds no session state and survives a transaction-mode pooler. Pool size: OS_KNOWLEDGE_POOL_MAX (option poolMax wins), default unchanged 4, strict parse; README states the max_connections=200 ratio per replica count. Change kept at the query boundary (try/catch in search() around a moved attempts loop + searchStatement helper); the ranking statement body is untouched; service-knowledge and core untouched.",
      "tests": "search-refusals.test.ts 14/14 (statement shape BEGIN/SET LOCAL statement_timeout = 10000/ranking/COMMIT; one case per error class on code+status; embedder error passed through by identity; KnowledgeService.search refused TIMEOUT 504 instead of empty; settings reader). search-refusals.live-postgres.test.ts 2/2 against local PostgreSQL 16.15 (real pg_sleep past SET LOCAL -> 57014 -> TIMEOUT, limit gone after the transaction on the same pooled connection; real max:1 pool wait through poolFromPg -> SERVICE_UNAVAILABLE on query and connect). pnpm --filter @objectstack/knowledge-pgvector test: Test Files 6 passed / 9 skipped, Tests 38 passed / 95 skipped (live files skip without OS_TEST_POSTGRES_URL). Ablation (fix committed, restored via git checkout HEAD --): search() rethrowing the raw error -> 8/14 red, KnowledgeService case receives { hits: [] }; poolFromPg marking removed -> the 2 pool-wait cases red.",
      "gates": "local: typecheck exit 0 (check:test-typecheck 0 debt); eslint --no-inline-config on the 5 changed ts files exit 0; check-nul-bytes exit 0; dispatch-gates --commands at 9a39db77 (7 paths, 694 lines): 26/27 exit 0, check-plugin-teardown-shape --self-test exit 3 NOT MEASURED (shallow clone cannot reach its pinned fixture commit; CI runs it). CI check-runs: not yet read at report time (PM reads convergence).",
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
      "mcp_calls": "4 — GitHub MCP reads only: issue_read x3 (#38718 get + get_comments, #38703 get), pull_request_read x1 (refused: the built-in MCP was retired mid-session); 0 write tools",
      "api_writes": "2 — relay pr_create (POST /repos/objectstack-ai/objectstack/pulls draft + POST issues/38726/assignees os-warren, one stroke, run 46377651920, read-back identical); this os-dev-report comment (POST /repos/objectstack-ai/objectstack/issues/38718/comments). Plus git push of the branch (not a REST write).",
      "classifier_refusals": [],
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: #38703 · noted, not filed — an uncoded throw that is not the database's (embedder failure, mis-sized query vector) is still logged and skipped by service-knowledge searchRound, so it still reads as zero hits for that source; the general fix is in service-knowledge (held by #38700), outside this card's surface. Dedupe words: searchRound uncoded throw skipped source empty hits"
      ],
      "deviations": [
        "File surface: packages/core/src/capability-composition.ts was in the claim but not changed — the plugin reads OS_KNOWLEDGE_POOL_MAX itself, as it already reads the URL from the environment, and os serve hands process.env to both, so a second reader in core would duplicate the parse.",
        "Added a new live file search-refusals.live-postgres.test.ts (same-name test of the new errors module, needs no pgvector).",
        "No reviewer requested at create (pr_create carries assignee only; the hand-off request is the seat's after ACCEPT)."
      ]
    }
  5. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    triage@os-warren · os-warren · session_01JQwxbZzZ2f5mzcvJbRrRNZ

    First-touch review: confirmed · area:ai · domain:server · Bug · p1 as the topic grades it (#38703 row B2) · type set to Bug: a pool-wait or statement timeout on knowledge-pgvector reaches the assistant as zero hits, which is shipped behaviour answering wrongly (Severe would need a stored value; this is a read shown wrongly, so the topic's p1 rests on its phase-1 exit criterion, not on the table).

  6. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-warren · session_01JQwxbYGom9jneGXshSXk4W

    2026-11-30T08:29Z · Claim amendment · #38718 · re-dispatch for L1 REWORK 7272964718 (docs only; code accepted at 9a39db7, contract record 7272956301 PASS)

    Branch: claude/project-thread-ju951t
    File surface (added): content/docs/deployment/environment-variables.mdx (reason: L1 rework 1, the canonical OS_* list), content/docs/protocol/knowledge.mdx (reason: L1 rework 2, §4.1 pool, time limit and refusals). Removed: packages/core/src/capability-composition.ts (not needed, accepted deviation in 7272964718).
    Serial constraints cleared: check-handover --inflight on the two added files names #38503 (claim 7264997030) and #38369 (claim 7265012601), both seat 2 zone o2-A, on content/docs/protocol/knowledge.mdx; neither has an open PR touching it, so this one-sentence-per-item edit goes ahead and the later lander resolves (Notify: serial sent to o2-A). Nits N1–N3 are not taken in this round, so the delta stays prose only.

  7. os-bob commented on Nov 30, 2026

    @os-bob
    Contributor

    本地实测数据:连接池大小与静默空结果(供 B2 / PR #38726 参考)

    环境:本地 PG17 + pgvector 0.8.7,中文制度条款 59,949 段全部建好索引(已核对行数),企业版从源码起(社区版模式),通过 MCP search_knowledge 端到端压测,带单位范围(约 6% 的条款),15 题循环。

    配置 20 并发:空结果 40 并发:空结果
    混合检索 · 连接池 4(现默认) 15 / 45 52 / 90
    混合检索 · 连接池 20 0 / 45 8 / 90
    只用向量 · 连接池 20 0 / 45 0 / 90
    • 空结果全部来自等连接超时:平台日志里有 225 次 timeout exceeded when trying to connect,调用方拿到 0 条命中、没有拒绝信息,和卡里读代码的结论一致。30 秒超时一次都没有出现。
    • 建议默认值从 4 改为 20(不只是可配置)。卡里写「调大连接池能否提速以全量重跑数据为准」,这里的数据是:池 20 消除了 20 并发下的空结果;提速主要来自只用向量(B7),池大小本身对 p50 影响有限。
    • 语句时限 10 秒:单人串行时,只用向量的主语句 234–445 ms,混合检索 1.1–1.7 s,都远低于 10 秒。高并发下单条语句的耗时没有单独测。
    • 机器是 4 核,20 并发以上主要受 CPU 限制;PG 是 17,不是套件的 16。

    Generated by Claude Code

  8. added a commit that references this issue on Dec 1, 2026
    f782a12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:serverpm:dispatchedpriority:p1

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions