Skip to content

knowledge-turso:每次检索记一行分段耗时日志;只读检索不再排队、并发执行,排队只留给写入(os-4 AI 问询慢) #39037

Todo

Description

@objectstack-fleet

repo:objectstack#2 · os-warren · session_01JQwxbZnJpLtws6kJHRZSvQ

Filing category ③ — maintainer-directed task · Source: maintainer

Grade: area:ai · Bug · user-visible latency on a customer environment · reach: os-4kjpqy.objectos.app (BrightRule, remote Turso), AI ask turns median ~41 s · evidence: read (code) + measured (logs, metrics, direct model timing) → priority:p1

维护者速读

  • 问题:os-4 上员工问制度,一轮 AI 问询中位数约 41 秒(15–73 秒)。容器是闲的(CPU 4–17%)。模型每次调用实测 7–8.5 秒,所以剩下的 20–30 秒推断在知识检索上。但检索耗时没有日志,这个推断还没法证实。
  • 原因(读代码):knowledge-turso 让同一个库上的所有检索和索引写入一个接一个排队(serial())。模型一次发出的两个检索只能串行跑,几个员工同时问也会互相排队,改记录触发的重新索引也会挡住检索。
  • 本卡做:① 每次检索记一行分段耗时日志(排队等待、嵌入、SQL、权限复查、总耗时),日志里不带问题原文;② 只读检索之间不再排队、并发执行,写入仍然独占。
  • 怎么验收:先上线 ①,在 os-4 上读出改前的分段数字;再上线 ②,对比前后。

Maintainer's words

Warren, 2026-12-02 (project thread): 「评估并立卡 给每次检索记一行耗时日志,这样能确认上面的推断;只读检索不再排队,并发执行,排队只留给写入。」

Business reason

BrightRule employees on os-4 wait about 40 s for each policy question; customers have reported the app as slow. The time is not in container capacity (scaling up would not help) and only about a third is in the model. Without a per-search timing line nobody can show where the rest goes, and the in-process queue makes every extra searcher or concurrent question slower for everyone in the environment.

Evidence (2026-12-01 reading, read-only)

  • 13 ask turns on os-4, 04:13–04:51Z: median ~41 s. A typical turn: the first search_knowledge starts ~4.5 s in (context prep + first model call); every later segment (search + next model call) takes 10–40 s.
  • The staging runtime container (1 vCPU / 6 GiB) ran at 4–17 % CPU and 1.4 GiB during those turns (Cloudflare container metrics).
  • The same model the ask surface uses (haiku-5.5, effort high), called directly through the gateway with a 44k-token prompt: 7–8.5 s per call. So 2–3 model calls account for ~15–20 s of a ~40 s turn.
  • Per-search time is NOT logged today: the only per-search line is [AI] platform embedding call, which marks a search's start. The 20–30 s left for search is an inference from those timestamps.

Mechanism (read on main c748e7dfd6)

packages/plugins/knowledge-turso/src/turso-adapter.ts: serial() (the queues WeakMap) runs every database call of every adapter on one libSQL client one at a time. searchAttempt takes the queue three times (generations, optionally hasLegacy, and the statement block); writes, builds, record sync and indexStatus take the same queue. On a remote Turso store each statement is an HTTP round trip of seconds, so:

  • two searches the model issues in one round run back to back, not side by side;
  • concurrent employees in one environment queue behind each other;
  • a record edit's re-index holds searches behind it.

The queue exists for writes: its comment says a second writer on another connection of the same process would block in SQLite's busy handler on the thread the holder needs to commit. Reads among themselves do not have that problem.

What

Part 1 — one timing line per search (ships first)

  • One structured line per search_knowledge search, at info on hosted deployments, carrying only: source id, retrieval mode, scope kind and size (term count / id count, never ids), topK, groupBy present, hits answered, refill round yes/no, and milliseconds for: queue wait, query embedding, adapter statements (count + total), permission re-check, total.
  • ⛔ No question text, no record ids, no passage text in the line (customer content).
  • Both stores emit the same line shape; knowledge-pgvector already has offline segment timing from knowledge-pgvector:检索分段计时与 PostgreSQL 基线(专题 #38703 B1) #38719 (bench only), so share the shape instead of making a second one.
  • If carrying adapter-side numbers (queue wait, statement count) back to the service needs a new field on the adapter contract (packages/spec/src/contracts/knowledge-adapter.ts), the claim declares it (Clause-②); an adapter-local line is acceptable instead.

Part 2 — reads stop queueing behind reads

  • Replace the single queue with a reader–writer discipline per client: searches (and other read-only calls such as generations, indexStatus) run concurrently with each other; any write, build step, generation switch or DDL takes the exclusive side and waits for in-flight reads; a waiting writer is not starved (new reads queue behind it).
  • The one-time keyword-index DDL inside a search (ensureKeywordIndex) must take the exclusive side.
  • Bound concurrent reads per client (a small constant, e.g. 4) so a burst does not open unbounded requests to Turso.
  • Generation consistency stays as today: the statement block re-reads the active generation and retries on a switch (SEARCH_ATTEMPTS).
  • Local file: stores keep the guarantee the current comment protects (no in-process read or write overlapping an in-process write transaction).

Acceptance

  • Tests pin structure, not wall-clock: N searches on one client with a stubbed slow execute overlap (max in-flight > 1, ≤ the bound); a write issued while reads are in flight starts only after they finish and before reads that arrived after it; a search needing the keyword-index DDL runs it exclusively; a generation switch mid-search still retries as today.
  • Part 1 line present and free of question text (test reads the logged object).
  • After each part reaches staging, the os-4 numbers are read from the new line: per-search p50/p95 and queue wait before part 2 and after, and ask-turn medians before and after. Posted on this card.

Who acts

Dispatch by the seat holding area:ai on objectstack (os-dev, one PR per part is fine). The cloud half (framework pin bump + staging deploy to read os-4) is done by the cloud seat after each merge; no separate card unless it needs cloud code.

Dedupe

gh api search/issues with repo:objectstack-ai/objectstack is:issue and open + closed: knowledge-turso serial (59), knowledge-turso queue (64), knowledge-turso concurrent (27), knowledge search latency (23), search_knowledge slow (8), knowledge search timing (70). None covers the queue or a hosted per-search timing line. Related, not duplicates: #38675 (closed; names serial() but fixed only SQL via #38693/#38697), #38676 (closed; #38798 embeds the question once), #38719 (closed; pgvector segment timing, bench only), epic #38703 (PostgreSQL scope; Turso "basic capability" — this card is the maintainer's own call on Turso).

Activity

  1. added
    priority:p1
    pm:queue
    area:ai
    domain:server
    on Dec 2, 2026
  2. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

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

    Claim: PM loop round 12 · 2026-12-02T06:55Z · zone osa-ai takes Part 1 of this card (the card's "Who acts" names the seat holding area:ai on objectstack; zone osa-ai is that seat's area:ai zone)
    Area: osa-ai
    Session: session_01WGufzeatqKfTRUzTJVa9jQ
    Account: os-support-ai
    Branch: claude/issue-39037-search-timing-line
    Worktree: objectstack-issue-39037
    Domain: domain:server
    Seat: repo:objectstack@os-support-ai
    File surface: packages/services/service-knowledge/src/knowledge-service-search.ts, packages/services/service-knowledge/src/knowledge-tools.ts (the search_knowledge path only), packages/plugins/knowledge-turso/src/turso-adapter.ts (queue-wait and statement timing only; the serial() discipline is Part 2's and stays as it is), packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts (the same line shape only, if the shared shape needs it), a new shared timing-line module under packages/services/service-knowledge/src/ if one is needed, tests beside each changed file (new files named for 39037; an existing test file only where a pin reads a changed node), .changeset/39037-search-timing-line.md. ⛔ Not packages/spec/**: the card allows an adapter-local line instead of a new adapter-contract field, and this claim takes that route; if the build finds the line cannot be written without a contract field, the dev stops and the zone brings it to the seat (Clause-② would change). Not Part 2 (the reader–writer queue). Stop on breach; explain in the report.
    Container & model: M, mode:subagent, model: default (dispatch-gates --tier: "no path-derived mandate … floor sonnet · default opus · ceiling fable"), effort: high (reason: p1, a hosted log line that must never carry customer content)
    Clause-②: no (a log line only; no authorable key, no tool input or answer changes)
    Metadata-protocol: none
    Responsibility: knowledge search in objectstack (packages/services/service-knowledge search path and packages/plugins/knowledge-turso adapter: no per-search timing is logged, so the ~20-30 s of an os-4 ask turn attributed to search is an inference) | none: the only per-search line is "[AI] platform embedding call", a start marker | every hosted environment with a knowledge source; os-4 (BrightRule) ask turns median ~41 s today
    Thread-read: none
    Premise: holds (read on main: turso-adapter.ts serial() and the absence of a per-search timing line, as the card states)
    Scope: Part of this card (Part 1). Part 2 (reads stop queueing behind reads) is claimed separately after Part 1 merges and the cloud seat reads the before numbers on os-4, as the card orders.
    Serial constraints cleared: check-handover.mjs --inflight --card=39037 over this surface: no readable in-flight surface meets it (exit 5); the one unread claim, #38415, is a pm-dispatch skills card with no path in packages/**.

  3. added
    pm:dispatched
    and removed
    pm:queue
    on Dec 2, 2026
  4. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

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

    {
     "issue": 39037,
     "status": "done",
     "branch": "claude/issue-39037-search-timing-line",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/39093",
     "session": "session_01WGufzeatqKfTRUzTJVa9jQ",
     "premise_still_valid": true,
     "summary": "Part 1 only. Every knowledge search (each search_knowledge call on every door, through KnowledgeService.searchWithRefusals) now logs one structured line when it ends, answered, refused or thrown: message '[knowledge] search timing', object under the meta field 'knowledgeSearchTiming'. It goes out at info when isCloudManaged() (OS_CLOUD_MANAGED=1) and at debug otherwise, on by default with no switch. The line carries sources[] {id as the answer names it, mode, scope {kind, terms, ids}}, topK, groupBy (boolean), hits, refused, refill, failed, statements (count), and ms {total, embed, queue_wait, statements, visible_ids, permission_recheck}; each ms value is a sum over the search and null when that segment did not run. It never carries the question, a record id, a passage or a title. The segment names follow the #38719 bench (embed, visible_ids, permission_recheck; queue_wait = the bench's pool_wait; statements = its ranking + other_sql). The turso store's numbers reach the line with no contract field and no exported-type widening. Once per search() call the adapter publishes {queueWaitMs, statements, statementMs} on the Node diagnostics channel 'objectstack:knowledge-adapter:search-timing'. Subscribers run synchronously in the publisher's async context, so the service credits each message to the search it is awaiting through its own AsyncLocalStorage, and two concurrent searches stay apart (this keeps holding under Part 2). Queue wait is measured where the adapter enters serial(): queued() hands serial() the work wrapped to add now-minus-enqueue at start, summed over entries. serial() itself and the queue order are unchanged. Requests are counted by a client proxy (execute, batch, and a transaction's open/execute/batch/commit/rollback) inside an adapter-local AsyncLocalStorage around search() only; outside a search the proxy is the client's own call. Cost of the line: a few performance.now() reads, one ALS scope per search, one synchronous channel message per store call, one log line; no DB call, no embed call, and nothing at all while nobody subscribes. pgvector gets the same shape because the service emits the line: total, embed, visible_ids and permission_recheck are filled; queue_wait and statements stay null because knowledge-pgvector does not publish. For the cloud seat: read message '[knowledge] search timing', field 'knowledgeSearchTiming'. The os-4 before/after numbers were not measured here; they are the cloud seat's after merge.",
     "tests": "Head 2e2a79729b (branch tip after merging origin/main 6354509427; the incoming commits touch docs/adr, packages/spec/src/ui and packages/cli, none of this PR's packages). pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2: 'Test Files 32 passed (32) / Tests 902 passed (902)', VERDICT command-exit 0. pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2: 'Test Files 7 passed (7) / Tests 338 passed (338)', VERDICT command-exit 0. New files: service-knowledge src/__tests__/search-timing-39037.test.ts (6 cases) and knowledge-turso src/__tests__/search-timing-39037.test.ts (3 cases). Every timing value is read off a performance.now mock; nothing sleeps. The service file pins: the exact field set and ms keys; exact segment sums; no distinctive question string, record ids, passage or title anywhere in the serialized call; null segments; sums over two sources plus the refill round; per-search attribution with two searches in flight; failed:true on a throw; info under OS_CLOUD_MANAGED=1 vs debug. The turso file runs the real KnowledgeService over a real :memory: libSQL store and pins: statements equals the requests the client saw; ms.statements equals 7 x count; queue_wait 0 when uncontended; >= 100 for a search enqueued behind a held request, while for the holder the same hold counts as statement time; and no wrap while nobody subscribes. Typecheck (tsc + check:test-typecheck) exit 0 for both packages on 6df70abf7c, not re-run after the merge, which touched neither package. Ablation on disk, restored with git checkout HEAD; hash-object equal before and after (turso-adapter.ts 2b3954e2, knowledge-service-search.ts 42605863); git status empty. (1) queued() handing serial() the bare work: turso contention case red, 'expected 0 to be greater than or equal to 100'. (2) Dropping noteSearchTargets(sources): 3 service cases red, 'sources: []'.",
     "gates": "dispatch-gates --commands (no paths, merge base 78148226f): 71 derived families; --ran with exit codes recorded: '71 derived, 70 run, 1 NOT-MEASURED, 0 UNRUN'. All run families exit 0. NOT MEASURED: pnpm check:dual-build-cjs-loads, PREREQUISITE NOT MET exit 3 (reads every package's dist; only the two packages' closure was built here), left to CI. Red on the first run, fixed on the branch, exit 0 on re-run: check:logger-receiver-detach (two-step-local logger channel), check:objectql-double-limit and check:where-matcher (the two new test doubles now filter generically, bound by limit after the filter, refuse hmBccombinators). check:query-options-erasure (301 s) and check:type-check-debt (239 s) hit the first 200 s local cap and are exit 0 on re-run. pnpm check:optional-error-sink ran (exit 0) but fell out of the derivation after the test edits. check:nul-bytes exit 0 on the merged head. CI check-runs on PR 39093 are not cited here: none had concluded at report time (NOT MEASURED, the PM reads CI convergence).",
     "mcp_calls": "0",
     "api_writes": "2 relay strokes: (1) fleet-write pr_create (run 46839266510): POST /repos/objectstack-ai/objectstack/pulls (draft) + POST /repos/objectstack-ai/objectstack/issues/39093/assignees [os-support-ai]; read back 10527 bytes sent = stored. (2) post-stamped --comment=39037: POST /repos/objectstack-ai/objectstack/issues/39037/comments (this report). Plus git push of the branch (probe + 7 pushes), which is not a REST write.",
     "classifier_refusals": [],
     "open_questions": [],
     "security_findings": "none",
     "out_of_scope_findings": [
      "carrier: #39037 (Part 2) · a turso search takes the client queue at least three times (generations, optionally hasLegacy, the statement block; ready() a fourth until isReady), and record-sync writes and indexStatus share that queue. queue_wait on the new line sums exactly these entries, so the before reading on os-4 shows how much Part 2 can win · noted, not filed",
      "carrier: #39037 · knowledge-pgvector does not publish on 'objectstack:knowledge-adapter:search-timing', so its queue_wait (pool checkout) and statements stay null. Filling them in place means wrapping its pool connect/query the way bench/instrument.mjs timedPool does from outside, in a new sibling module (pgvector-adapter.ts is 1,679 lines) · noted, not filed",
      "carrier: #39037 · the record-level freshness check (checkFreshness) and the per-hit verification read (dropUnverifiedHits) are system reads (the bench's system_read). They are inside ms.total and in no segment of their own; if the os-4 numbers show a gap between total and the named segments, that is where it lies · noted, not filed"
     ],
     "deviations": [
      "File surface: added packages/plugins/knowledge-turso/src/search-timing.ts, which the claim does not list. turso-adapter.ts is 1,907 lines, and os-dev.md rule 3 sends a new concern to a sibling module with only calls in the original. os-dev.md wins over the dispatch, so this conflict is declared here, not chosen silently. turso-adapter.ts gains 3 calls (+7/-3). knowledge-tools.ts and pgvector-adapter.ts are unchanged.",
      "Fields: refused (count) and failed (boolean) were added beyond the card's field list. Both are non-content; without them an empty answer cannot be told from a refused or thrown one.",
      "Two gate batches ran past the 10-minute foreground cap and were moved to the background by the harness. I waited for both in the same turn and read every result before going on; no monitor or job outlives this run.",
      "No gate ledger row was added."
     ],
     "files_changed": [
      ".changeset/39037-search-timing-line.md",
      "packages/plugins/knowledge-turso/src/__tests__/search-timing-39037.test.ts",
      "packages/plugins/knowledge-turso/src/search-timing.ts",
      "packages/plugins/knowledge-turso/src/turso-adapter.ts",
      "packages/services/service-knowledge/src/__tests__/search-timing-39037.test.ts",
      "packages/services/service-knowledge/src/knowledge-search-timing.ts",
      "packages/services/service-knowledge/src/knowledge-service-search.ts"
     ],
     "line_budget": "+866 / -9 over 7 files (dispatch-gates: 875 changed lines, under the 3000 human-merge threshold); no skills/** touched",
     "clause_2": "no; no exported type added or widened (neither package's index re-exports the new modules; TursoKnowledgeAdapterOptions and AdapterSearchOptions unchanged)",
     "dedupe_words": [
      "knowledge search timing line",
      "search_knowledge latency log",
      "knowledge-turso queue wait",
      "diagnostics_channel knowledge adapter"
     ]
    }
  5. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

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

    Amendment 1 to claim 7337577176 · 2026-12-02T08:15Z · zone osa-ai

    • File surface gains packages/plugins/knowledge-turso/src/search-timing.ts (new sibling module for the adapter-side timing, per os-dev.md rule 3: turso-adapter.ts is 1,907 lines and keeps only three calls into it) and packages/services/service-knowledge/src/knowledge-search-timing.ts (the shared line module the claim admitted). Neither is re-exported from its package index.
    • Unchanged and out: knowledge-tools.ts and pgvector-adapter.ts (the pgvector line comes from the service side), packages/spec/**, Part 2. Everything else in the claim stands. PR feat(knowledge): one timing line per knowledge search, with the turso store's queue wait and requests #39093, os-dev report 7339195259.
  6. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

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

    Release: zone osa-ai stands down · 2026-12-02T11:49Z · maintainer 2026-12-02T11:46Z 「各区可以下班了,下面只负责专题任务。」 (seat lease row 7344423709 on #38765)

    • Landed: Part 1, PR feat(knowledge): one timing line per knowledge search, with the turso store's queue wait and requests #39093, merged 2026-12-02T09:11Z (712b102): one [knowledge] search timing line per search, meta field knowledgeSearchTiming.
    • Branch: none in flight. Nothing unmerged; no backup branch is needed (Part 2 was never started).
    • Owed, in the card's order: (1) the cloud seat bumps the framework pin, deploys staging and posts os-4's before numbers here (per-search p50/p95, ms.queue_wait, ask-turn median); (2) Part 2 (reads stop queueing behind reads: reader–writer discipline per client, bounded concurrent reads, DDL exclusive, generation retry unchanged), then the after numbers.
    • Notes for the taker: turso-adapter.ts takes the client queue at least three times per search (generations, optionally hasLegacy, the statement block; ready() until isReady), and record-sync writes and indexStatus share it; ms.queue_wait sums exactly those entries. pgvector does not publish on the timing channel, so its queue_wait/statements stay null.
    • Labels: pm:dispatched → pm:queue, assignee cleared, with this comment.
  7. added
    pm:queue
    and removed
    pm:dispatched
    on Dec 2, 2026
  8. objectstack-fleet commented on Dec 3, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-warren · session_01JQwxbZnJpLtws6kJHRZSvQ

    Handover · 2026-12-03T01:20Z · this card moves to the repo:cloud@zhuangjianguo seat. The filing thread stops here; nothing of it is in flight.

    Maintainer, 2026-12-03T01:19Z: 「39037 也移交」.

    State as read at handover

    • Part 1 landed: PR feat(knowledge): one timing line per knowledge search, with the turso store's queue wait and requests #39093, merged 2026-12-02T09:11Z (712b102). Log line [knowledge] search timing, meta field knowledgeSearchTiming.
    • Cloud pin: cloud main .objectstack-sha = b706ec6 (contains 712b102, compare: ahead 28 / behind 0).
    • Staging: runtime container image objectos:44a7c805, rolled 2026-12-03T00:36Z; that commit's pin is the same b706ec6, so Part 1 is live on staging, including os-4kjpqy. Production (b6fdc5bb, 2026-12-01) does not matter for this card.
    • No os-4 "before" numbers yet: from 00:36Z to about 01:25Z the staging runtime logged 0 search timing lines and 0 [AI] platform embedding call lines. One ask turn ran (00:41Z, 4 tool rounds, 31.9 s) with no knowledge search. The first BrightRule policy question after the deploy will produce the first line.
    • Part 2 (reader–writer lock in knowledge-turso) is not started: no branch, no claim. Card stays pm:queue, unassigned.

    How to read the numbers (read-only, no session needed)

    • Workers Observability POST /accounts/$CLOUDFLARE_ACCOUNT_ID/workers/observability/telemetry/query, datasets: ["containers"], filter $metadata.service = a0399d14-a242-4abc-b92e-c9dd5e35a992 (staging runtime app id) and $metadata.message includes search timing. The events view caps at 100 rows, so split the window. Retention is 7 days.
    • os-4's environment id in those lines is 9395afe9-58c5-45c7-a0ac-f66748a2d149.
    • Turn context: [AI] turn ended {toolRounds, elapsedMs, conversationId} on the same app gives each ask turn's total.

    Baseline to compare against (2026-12-01 reading, before Part 1)

    • 13 os-4 ask turns, 04:13–04:51Z: median ~41 s (15–73 s). The first search starts ~4.5 s in; later search plus model segments take 10–40 s.
    • Staging runtime CPU during those turns: 4–17 %, memory 1.4 of 6 GiB (Cloudflare containersMetricsAdaptiveGroups). Container size is not the bottleneck.
    • haiku-5.5 at effort high with a 44k-token prompt, timed directly through the gateway: 7–8.5 s per call.
    • So the 20–30 s per turn attributed to search is still an inference. Part 1's line is what confirms or refutes it. Read queue wait against the statement time: queue wait that dominates is the case for Part 2.

    Owed, in order: (1) once os-4 has had BrightRule questions, post per-search p50/p95, queue wait and statement time, with ask-turn medians, on this card; (2) dispatch Part 2 per the card body (bounded concurrent reads, exclusive writes and DDL, no writer starvation, generation retry unchanged); (3) after Part 2 reaches staging, post the same numbers again for comparison.

  9. objectstack-fleet commented on Dec 4, 2026

    @objectstack-fleet
    ContributorAuthor

    director#1 · hotlong · session_f4c42f815d5e47b39de5e9fb0d6d7864

    Reading: os-4 before numbers (Part 1 live, Part 2 not started) · 2026-12-04T09:25Z · owed item (1) of handover 2026-12-03T01:20Z

    维护者速读

    • 推断不成立:检索只占一轮问询墙钟时间的中位数 27%(7–62%),不是 20–30 秒。单次检索中位数 1.9 秒,p95 11.4 秒。
    • 排队只在并发检索时出现:80 次检索里 36 次独占的排队等待合计 2 毫秒;44 次与别的检索重叠的合计 54 秒,占全部检索时间的 18.5%。对单轮的影响中位数 1.9%,最坏一轮 50%。
    • 大头是 SQL 本身:语句耗时占检索时间 60%,每条语句中位数 135 毫秒、p90 903 毫秒(远程 Turso 的长尾)。
    • 本期问询中位数 20.9 秒(27 轮),12-01 基线是约 41 秒。Part 1 只加日志,不会让它变快,这个差别来自别的改动或问题本身,不能算到本卡头上。
    • Part 2 能省下的上限就是那 18.5% 排队时间,主要落在模型一次发出多个检索的轮次上。

    Window and attribution

    • Staging runtime app a0399d14…, 2026-12-03T00:30Z → 2026-12-04T09:10Z (Workers Observability, containers dataset, split windows under the 100-row cap).
    • 80 [knowledge] search timing lines; every one names source brightrule-policy_clause (the line carries no environment id, so os-4 is identified by the BrightRule source). Two sessions: 12-03 09:55–10:11Z (31 searches) and 12-04 04:35–05:04Z (49 searches).
    • 35 [AI] turn ended lines in the window; 27 contain at least one BrightRule search inside [end − elapsedMs, end] and are counted as os-4 ask turns. That attribution is by time window, not by id.

    Per search (n = 80, ms)

    segment p50 p95 max share of summed total
    total 1914 11441 16509 —
    embed 317 465 499 8.9 %
    queue_wait 0.1 3246 15781 18.5 %
    statements 883 9234 15820 60.2 %
    visible_ids 65 1751 2697 5.7 %
    permission_recheck 183 383 692 5.4 %
    • statements per search p50 6.5, p95 8; ms per statement p50 135, p90 903.
    • mode always vector; refill on 38 of 80; refused 0; failed 0.
    • queue_wait > 100 ms on 28 searches, all of them overlapping another search; the two largest are 10.2 s and 15.8 s (a search held behind another search's slow statement block).

    Per ask turn (n = 27, ms)

    • elapsed median 20896, p95 54109, range 7948–60090; tool rounds 1–7.
    • wall-clock share inside a search (union of intervals): median 27 %, range 7–62 %.
    • summed queue_wait / turn: median 1.9 %, max 50 %.

    What this says for Part 2

    • Reads queueing behind reads is real but bounded: it costs nothing on single-search turns and up to half of the worst multi-search turn. Part 2 removes exactly that 18.5 %.
    • The larger search cost is the statement tail on remote Turso (p90 ~0.9 s per statement, ~7 statements per search); Part 2 does not touch it. Not filed here; noted for whoever reads the after numbers.
    • The remaining ~73 % of a turn is outside search (model calls and context prep).

    Owed next: (2) Part 2 dispatch per the card body, (3) after numbers. Read-only reading; no write to any environment.

  10. objectstack-fleet commented on Dec 4, 2026

    @objectstack-fleet
    ContributorAuthor

    director#1 · hotlong · session_f4c42f815d5e47b39de5e9fb0d6d7864

    Claim: direct dispatch · 2026-12-04T09:36Z · Part 2 of this card (reads stop queueing behind reads) · maintainer 「派 Part 2」 after reading the before numbers (comment 7407308628)
    Area: knowledge (area:ai)
    Session: session_f4c42f815d5e47b39de5e9fb0d6d7864 (director; the dev runs as a local subagent of this session)
    Account: hotlong
    Branch: claude/issue-39037-reader-writer-queue
    Worktree: objectstack-issue-39037-p2
    Domain: domain:server
    Seat: director#1 (the card was handed to the cloud seat on this account 2026-12-03T01:20Z)
    File surface: packages/plugins/knowledge-turso/src/turso-adapter.ts (the serial() / queues discipline and its call sites only), a new sibling module under packages/plugins/knowledge-turso/src/ for the reader–writer lock, packages/plugins/knowledge-turso/src/search-timing.ts (only if queue-wait measurement must follow the new lock), tests beside each changed file (new files named for 39037), .changeset/39037-reader-writer-queue.md. ⛔ Not packages/spec/**, not packages/services/service-knowledge/**, not knowledge-pgvector. Stop on breach; explain in the report.
    Container & model: M, mode:subagent, model: opus, effort: high (reason: p1, concurrency change on a store every hosted knowledge source uses)
    Clause-②: no (an adapter-internal scheduling change; no contract, authorable key, tool input or answer changes)
    Metadata-protocol: none
    Responsibility: knowledge-turso adapter (packages/plugins/knowledge-turso): one serial() queue per libSQL client runs reads behind reads | none | every hosted environment with a knowledge source on remote Turso; os-4 reading: 44 of 80 searches overlapped another, their queue wait summed 54 s = 18.5 % of all search time, max 15.8 s on one search
    Thread-read: none
    Premise: holds (read on origin/main 8feef82: turso-adapter.ts serial() at the queues WeakMap, SEARCH_ATTEMPTS = 3, ensureKeywordIndex called inside search)
    Scope: Part of this card (Part 2). After it reaches staging the director posts the after numbers (owed item 3).
    Serial constraints cleared: open PRs touching knowledge-turso: none (#39340 is an examples knowledge source, no path under packages/plugins/knowledge-turso).

  11. added
    pm:dispatched
    and removed
    pm:queue
    on Dec 4, 2026
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