Repository navigation
Done
Copy link
Labels
area:aiAI-native — agent / tool / skill metadata, and the MCP surface an agent drivesdomain:serverDomain lane — seat card indexed by label:pm:seatpriority:p1High: required for production / M2
Description
在云端环境 os-4kjpqy.objectos.app(BrightRule 制度问询,知识存储为远程 Turso/libSQL)上,search_knowledge 只要带检索范围(scope)就稳定报错:
[knowledge] no source could be searched: source 'brightrule-policy_clause' refused (SERVICE_UNAVAILABLE): The knowledge store (libSQL) is not ready: its database did not answer in time.
不带范围的检索能返回结果,但单次也要 25 秒左右。员工在问制度页面看到的是「在知识库中查找 · 出错」,AI 回答里写成「部分检索因知识库暂时不可用而失败,所以这个结论并不完整」。
复现
2026-11-30 北京时间上午 11 点前后,用已登录的浏览器会话直接调该环境的 /api/v1/mcp → tools/call search_knowledge。五次请求依次发出,没有并发:
| # | 参数 | 耗时 | 结果 |
|---|---|---|---|
| A | 中文长问句,scope: [{object: "sys_business_unit", ids: [1 个单位]}],groupBy: "clause_hash",topK 8 |
13.2 s | 超时报错 |
| B | 同一问句,不带 scope |
25.6 s | 有结果 |
| C | 短问句「AI工具账号开通」,同 A 的单位范围 | 30.6 s | 超时报错 |
| D | scope: [{object: "brightrule_policy", ids: [3 份制度]}] |
31.8 s | 超时报错 |
| E | 同 A,但不带 groupBy |
19.2 s | 超时报错 |
另外一次单独调用 A 时,21.7 s 后报同样的错。
原始对话 conv_885e2bb7-dafe-48ec-8e38-2fbf5a49a42a 一共发了 11 次 search_knowledge,其中 2 次是这个超时,分别带单位范围和 3 份制度范围。成功的几次每批也要 20 到 38 秒。
知识源 policy_clause 每条制度条款一段,约 5.5 万段(#38671 里的统计是 59,621 段),嵌入维度 1024。
已知事实(读的是 framework main 1fef2ed)
- 报错来自
packages/plugins/knowledge-turso/src/turso-adapter.ts里的withTimeout。对远程库,每一条 SQL 的上限是DEFAULT_REQUEST_TIMEOUT_MS = 10_000(plugin.ts:148)。所以报错说明有一条检索 SQL 在 Turso 上执行超过了 10 秒,不是连接没建好。 - 所有检索在同一个 client 上用
serial()排队一条一条执行,因此同一轮里并发的几次检索会互相拖慢总耗时。不过本次复现里每次请求都是单独发的,照样超时。 - 带范围时,
WHERE里有一段按行做json_each(metadata)的子查询(单位范围是 metadata 条件),或者source_record_id IN (...)。这段条件在向量一路、关键词一路的cand、以及stats的count(*)里各算一遍。 - fix(knowledge): the keyword leg ranks unspaced Chinese, Japanese and Korean questions by 2- and 3-character pieces #38469(2026-11-29 合入)把中文问句在关键词一路切成最多 16 个二字、三字片段。三字片段走 FTS5 trigram 索引,二字片段走
content LIKE,对范围内每一行逐行匹配。那个 PR 的耗时数字是在本地 libSQL 上测的(关键词一路 p95 约 0.5 s),没有在远程 Turso 上测过。 - 近似向量索引(feat(knowledge-turso): an approximate vector index for a large source of one organization #38056)只在「单一组织」的段落表上启用。这个环境的段落表是否满足这个条件、索引有没有建起来,我们从外面看不到。
怀疑的原因(需要平台确认)
- 远程 Turso 上,带范围的那条主检索 SQL 要逐行算
json_each,或者按 id 列表匹配,再叠加 16 个关键词片段里二字片段的LIKE全扫,单条执行超过 10 秒。fix(knowledge): the keyword leg ranks unspaced Chinese, Japanese and Korean questions by 2- and 3-character pieces #38469 合入后关键词一路变重,可能是主要诱因。 - 段落表没有用上近似向量索引(多组织,或者表是靠增量同步涨过 2 万段、从来没在完整构建时建过索引),每次都走 5 万多行 1024 维向量的精确扫描。
期望
- 带范围的
search_knowledge在这个量级(约 6 万段、1024 维、远程 Turso)上能在 10 秒上限内返回,而且整体耗时回到几秒的量级。 - 报错文字别写成「store is not ready」。实际情况是单条查询超时,现在的说法会让模型和员工以为知识库挂了。
我们这边的情况
同一次对话里还有 1 次报错是模型自己传了 scope 但 ids 为空。平台的拒绝是对的,这一条由 BrightRule 自己处理,不需要平台改。
Metadata
Metadata
Assignees
Labels
area:aiAI-native — agent / tool / skill metadata, and the MCP surface an agent drivesdomain:serverDomain lane — seat card indexed by label:pm:seatpriority:p1High: required for production / M2
Activity
objectstack-fleet commentedon Nov 30, 2026
triage@os-warren · os-warren · session_01JQwxbZzZ2f5mzcvJbRrRNZ
Triage: lands in
packages/plugins/knowledge-turso(the scoped search statement and the per-statementwithTimeouton a remote libSQL client, plus the "store is not ready" wording for a statement timeout) · area:ai · domain:server · Bug · p1 · pm:queue · size M.Grade: area:ai · Bug · Broken (every scoped
search_knowledgetimed out, and the error names no workaround) · end users, daily (the hosted BrightRule policy-question page) · measured (5 serial MCP calls on the hosted environment; 4 of 4 scoped calls failed after 13–32 s, the unscoped one took 25.6 s).Rationale: the North Star table gives p1 for Broken at end-user daily reach. The repository is this one, because the cause is in the platform's knowledge-turso adapter, wherever it shows up. #38676 measures the same statement path locally (the keyword leg recomputed per statement, ANN retried under a narrow scope, the question vector embedded twice); a remote client pays each repeat with a network round trip, so a claim on this card should read #38676 first and the two are best taken by one seat. The second suspected cause (no ANN index on a multi-org passage table) is not visible from outside and is for the claiming seat to check on the environment.
objectstack-fleet commentedon Nov 30, 2026
repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu
2026-11-30T04:40Z · Claim · p1 in zone o2-A (area:ai), knowledge topic; no open PR touches
packages/plugins/knowledge-tursoat this read.Claim: PM loop round 1
Session:
session_01JQwxbXyLoBzNYY1U8SNPFuAccount:
os-warrenBranch: new, from
origin/mainat5ac1ee0bc8; the card thread's branch is named by a claim amendment on its first reportWorktree:
objectstack-issue-38675Domain:
domain:serverSeat:
repo:objectstack#2Area:
o2-A(area:ai)File surface:
packages/plugins/knowledge-turso/src/turso-adapter.ts,packages/plugins/knowledge-turso/src/sql.ts,packages/plugins/knowledge-turso/src/plugin.ts, tests underpackages/plugins/knowledge-turso/src/__tests__/, one changeset (stop on breach; explain in the report)Container & model: M, mode:thread, model: default (dispatch-gates --tier: no path-derived mandate), effort: high
Clause-②: no
Metadata-protocol: none
Responsibility: to be read by the dev (which change made the scoped statement slow on a remote store)
Thread-read: none
Premise: holds at
5ac1ee0bc8—DEFAULT_REQUEST_TIMEOUT_MS = 10_000atplugin.ts:156applies per statement to a remote libSQL URL (plugin.ts:161); the scoped and unscoped search statements live inturso-adapter.ts(1,770 lines). The card's repro is a hosted environment; the dev reproduces against a local libSQL with a remote-like latency or an equivalent row count, and says which.Serial constraints cleared: #38676 and #38671 touch the same files and are queued behind this card on the same thread;
overlap-check.mjsruns before every push.Pre-claim lane:
packages/plugins/knowledge-turso/**⇒ domain:server (file ownership only); area:ai, zone o2-A.Pre-claim deps: none.
Prior rulings read: triage 7268501315.
objectstack-fleet commentedon Nov 30, 2026
repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu
Dispatch order · #38675 (knowledge-turso:带检索范围的 search_knowledge 在远程 Turso 上超时) · zone
o2-A(area:ai, knowledge first) · 2026-11-30T04:42ZCard #38675 is held by seat 2 (
os-warren) by claim 7268984126. One card thread (mode:thread); the thread is the dev. The same thread then runs #38676 and #38671 in turn (same files); each gets its own order from the seat after this PR is up.origin/main; the thread names it to the seat on its first push, and the seat amends the claim.packages/plugins/knowledge-turso/src/turso-adapter.tsandsql.ts, the per-statementwithTimeoutandDEFAULT_REQUEST_TIMEOUT_MS(plugin.ts:156-161). Find why a scoped statement is slower than an unscoped one (query plan: index use, the scope predicate, the vector top-K shape). Reproduce against a local libSQL with a row count close to the card's environment, and say what you measured. If the cause is inservice-knowledge(the caller) rather than this plugin, stop and report:knowledge-service.tsis held by service-knowledge: split knowledge-service.ts (5,411 lines, one class) into concern modules, move-only, so knowledge cards stop queueing on one file #38660.packages/plugins/knowledge-turso/src/{turso-adapter,sql,plugin}.ts, tests underpackages/plugins/knowledge-turso/src/__tests__/, one changeset.changeset/38675-*.md. ⛔ Notpackages/services/service-knowledge/**.Clause-②:andMetadata-protocol:lines in the PR body and changeset, measured from the diff.## 席位核对record, request reviewers, mark ready, enqueue.pr_create(draft,Fixes #38675); comments, labels and PR body only via relay write tools (scripts/pm/post-stamped.mjs,scripts/pm/label-write.mjs); report both counts.mode:thread,model: default(dispatch-gates.mjs --tier: no path-derived mandate),effort: high.repo:objectstack#2 · os-warren · <the thread's session>; then one message to the seat-1 takeover thread (it runs zone o2-A) with PR, head and key points.objectstack-fleet commentedon Nov 30, 2026
repo:objectstack#2 · os-warren · session_01JQwxbaAVoqUQiPmxMVpLst
os-dev report · #38675 · 2026-11-30T05:07Z
Draft PR #38693 · head
3034d99bc4· branchclaude/project-thread-slovhl(fromorigin/mainat5ac1ee0bc8).{ "issue": 38675, "status": "done", "branch": "claude/project-thread-slovhl", "pr": "https://github.com/objectstack-ai/objectstack/pull/38693", "session": "session_01JQwxbaAVoqUQiPmxMVpLst", "premise_still_valid": true, "summary": "Premise holds; the cause is in this plugin, not in service-knowledge. A scoped statement read the whole passage table three times (vector leg, keyword candidates, keyword count), each evaluating the metadata scope term (json_each per row), and the keyword candidates CTE was inlined twice (stats and kw); a narrow scope also ran 2-3 such statements. Fix: under a record scope or metadata filter the WHERE is read once per statement into `scope AS MATERIALIZED`, every other read of the passage table is a chunk_id lookup, and `cand` is MATERIALIZED (scoped and unscoped). A request past requestTimeoutMs now answers TIMEOUT/504 'The knowledge store (libSQL) did not answer in time: a request to its database took longer than N ms.' instead of SERVICE_UNAVAILABLE/503 'is not ready'. Local repro (file: libSQL, 59,621 passages x 1024 dims, approximate index built, topK 40, 16-term Chinese question), per statement before -> after: 3 policies 0.9 s + 1.0 s -> 0.13 s + 0.08 s; leaf unit 1.0 s + 1.2 s -> 0.19 s + 0.15 s; division 1.1 s + 1.2 s -> 0.25 s + 0.31 s; root (100%) 1.27 s -> 0.9 s; unscoped 1.2 s -> 0.65 s. Remote Turso was not reachable; that the hosted statement now fits the 10 s bound is inferred from the card's ~8-10x hosted/local ratio, not measured.", "tests": "New src/__tests__/scope-plan.test.ts: 11 cases. 8 EXPLAIN QUERY PLAN pins (metadata term, record term, both, metadata filter x exact/approximate leg): one read of the passage table outside a chunk_id lookup, under MATERIALIZE scope, and one MATERIALIZE cand; 1 timeout pin (TIMEOUT/504, the new sentence, no 'not ready'); 2 equivalence cases (scoped hits = the terms' meaning; no scope set without a scope). Ablation: adapter change stashed -> 'Tests 9 failed | 2 passed (11)' (the 8 plan pins + the timeout pin). acceptance.test.ts stalled-write case updated to TIMEOUT/504. Package: 'Test Files 5 passed (5) / Tests 301 passed (301)'. pnpm typecheck OK (check:test-typecheck OK). eslint on changed files: no output.", "gates": "Local, each exit 0: check:issue-citations, check:doc-authoring, check:keyed-text-bounds, check:closed-ceremony-text, check:objectql-double-limit, check:where-matcher, @objectstack/spec check:duration-unit-keys, check:changeset-fixed, check:empty-changeset; pre-push hook ran (first push refused by check:commit-card-trailers for a Fixes trailer and a model-named co-author; reworded before publish, second push passed). Repo-wide lint/CI families: not re-run locally; the PR's check-runs are the evidence once they land.", "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm", "mcp_calls": "0", "api_writes": "2 relay writes as objectstack-fleet[bot]: pr_create (fleet-write run 46357389297, draft, assignee os-warren, body read back identical) and this comment via post-stamped.mjs", "classifier_refusals": [], "open_questions": [], "security_findings": "none", "out_of_scope_findings": [] }Notes for the seat:
packages/plugins/knowledge-turso/README.md(2 lines: therequestTimeoutMsrow named the oldSERVICE_UNAVAILABLE, and the Search section describes the WHERE). Docs follow the code in the same package; no other file.turso-adapter.tsis 1,770 lines. The change is a fix inside the existingsearchAttempt(+ thewithTimeoutrefusal), net +43 lines, no new concern, so it stays in place.SERVICE_UNAVAILABLE/503 →TIMEOUT/504 applies to every request past the bound (reads and writes), not only search.TIMEOUTis the ADR-0112 code for 504;service-knowledgepasses coded refusals through (codedRefusalOf) and nothing branches on the old code. If the message change alone is wanted, it is a one-line revert ofcode/status.candhalf of the fix here; the rest is knowledge-turso 检索慢:关键词一路随向量重试重复执行、窄范围下近似检索反而比精确扫描慢、补查轮重复生成问题向量 #38676's.objectstack-fleet commentedon Nov 30, 2026
repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu
2026-11-30T05:11Z · Claim amendment to 7268984126: it names the card thread's branch and admits the package README. Seat ruling on the dev's flagged change: no veto.
Claim: PM loop round 1 (amendment of 7268984126)
Session:
session_01JQwxbXyLoBzNYY1U8SNPFuThread session:
session_01JQwxbaAVoqUQiPmxMVpLstAccount:
os-warrenBranch:
claude/project-thread-slovhl(fromorigin/mainat5ac1ee0bc8), PR #38693Worktree:
objectstack-issue-38675Domain:
domain:serverSeat:
repo:objectstack#2Area:
o2-A(area:ai)File surface: as in 7268984126, plus
packages/plugins/knowledge-turso/README.md(2 lines, admitted)Container & model: M, mode:thread, model: default (dispatch-gates --tier: no path-derived mandate), effort: high
Clause-②: no
Metadata-protocol: none
Thread-read: none
Flagged change (report 7269378240): a statement past its bound now answers
TIMEOUT(504) instead ofSERVICE_UNAVAILABLE(503) for every request, writes included. The seat accepts it.service-knowledgeorknowledge-tursobranches on the adapter's 503. A grep on5ac1ee0bc8finds only the service's own unmounted-adapter refusals, which are unchanged.objectstack-fleet commentedon Nov 30, 2026
repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu
2026-11-30T07:42Z · Landed — card closed by the merge; seat label cleared.
PR #38693 merged at 2026-11-30T07:36Z and closed this card.
fix(knowledge-turso): a scoped search reads its passage table once a …