Repository navigation
feat(knowledge): one timing line per knowledge search, with the turso store's queue wait and requests - #39093
Conversation
…e's queue wait and requests reported to it Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
…, segment sums and the turso store's queue wait Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
…; the test doubles hold the caller's limit Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
…inator they do not implement Claude-Session: https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 20 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 6 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 5 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 27a696562914a8c7e1b106599871ab7d88f2a097 && git checkout 27a696562914a8c7e1b106599871ab7d88f2a097
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 6354509427fab0ca2052b2b05be787f8593422ca 2e2a79729b4a0ce236f46bdfe01aa9bd53845279 && git checkout -B drift-repro 6354509427fab0ca2052b2b05be787f8593422ca && git merge --no-ff 2e2a79729b4a0ce236f46bdfe01aa9bd53845279
node scripts/docs-audit/affected-docs.mjs --json 6354509427fab0ca2052b2b05be787f8593422ca
|
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzhGA3zoCFquQgku4pm L1 review — ACCEPT on
|
|
repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ 落地
State change: ready for review + auto-merge, by zone osa-ai (2026-12-02T08:42Z). |
Requested by Yibo Wang · project thread
Part of #39037
Claim for this branch: #39037 comment 7337577176
Clause-②: no
Metadata-protocol: none
This PR is Part 1 of the card only (one timing line per search). Part 2 (reads stop queueing behind reads) stays open on the card; the turso queue keeps its order here.
维护者速读
What changes
@objectstack/service-knowledge, newknowledge-search-timing.ts;knowledge-service-search.tsgains only calls). Logged once perKnowledgeService.searchWithRefusals, which everysearch_knowledgecall makes on every door, when the search ends (answered, refused or thrown). Message[knowledge] search timing, object under the meta fieldknowledgeSearchTiming. AtinfowhenisCloudManaged()(OS_CLOUD_MANAGED=1), atdebugotherwise; on by default, no switch.sources[](idas the answer names it,mode,scope: { kind, terms, ids }counted, never listed),topK,groupBy(boolean),hits,refused,refill,failed,statements(count), andms: { total, embed, queue_wait, statements, visible_ids, permission_recheck }, each a sum over the search,nullwhen that segment did not run or the store reports nothing. No question text, no record id, no passage, no title.embed,visible_ids,permission_recheck);queue_waitis the bench'spool_waitandstatementsis itsranking+other_sql. The mapping is in the module docblock.@objectstack/knowledge-turso, newsearch-timing.ts;turso-adapter.tsgains three calls). The adapter publishes{ queueWaitMs, statements, statementMs }once persearchcall on the Node diagnostics channelobjectstack:knowledge-adapter:search-timing. A diagnostics-channel message reaches its subscribers synchronously in the publisher's async context, and the adapter publishes from inside thesearchcall the service awaits, so the service credits it to the right search from its ownAsyncLocalStorage; no id crossesAdapterSearchOptions. That keeps two concurrent searches apart, and keeps holding once Part 2 lets reads overlap. Why not the alternatives: a field onAdapterSearchOptionsor an adapter option changes the contract or widens a published type (Clause-②), and an adapter-local line correlated by a search id gives the reader two lines to join and needs a logger the adapter does not have.serial():queued()handsserial()the same work wrapped so it adds now-minus-enqueue when it starts, summed over the search's queue entries.serial()and the queue order are untouched.execute,batch, a transaction's open,execute,batch,commit,rollback) is counted and timed for it. Outside a search a request is the client's own call, unwrapped. Writes, builds, record syncs andindexStatusrun outside the search scope and are never counted, even when queued between a search's entries.performance.now()reads and oneAsyncLocalStoragescope per search, one synchronous channel message per store call, one log line. No database read, no embedding call. While no service has subscribed, the adapter measures and publishes nothing.total,embed,visible_idsandpermission_recheckare measured for it today;queue_waitandstatementsstaynull, sinceknowledge-pgvectordoes not publish on the channel. Filling them in place means wrapping its pool checkouts and statements, as the bench does from outside. That is left to this card.Log key for the cloud seat (os-4 before reading, after merge): message
[knowledge] search timing, fieldknowledgeSearchTiming; per search readms.total,ms.queue_wait,ms.embed,ms.statementswithstatements,ms.permission_recheck. This PR does not measure os-4; that reading belongs to the cloud seat after merge.Tests
packages/services/service-knowledge/src/__tests__/search-timing-39037.test.ts(6): asearch_knowledgecall (throughknowledgeTools().searchKnowledge, non-system caller, a three-id scope) logs exactly one line whose field set andmskeys are pinned, whose values are exact sums off a fake clock (performance.nowmocked; no real time is measured, nothing sleeps), and whose serialization contains none of a distinctive question string, the record ids, the passage text or the title. Further cases covernullfor segments that did not run and for a store that publishes nothing; summing over two sources and a refill round; two searches in flight at once, each credited only with its own store calls; a thrown search still loggingfailed: true; andinfounderOS_CLOUD_MANAGED=1againstdebugotherwise.packages/plugins/knowledge-turso/src/__tests__/search-timing-39037.test.ts(3), through the realKnowledgeServiceover a real:memory:libSQL store: the line'sstatementsequals the requests the client saw andms.statementsequals their summed fake-clock cost, so the channel spelling is pinned end to end. An uncontended search showsqueue_wait0. A search enqueued behind another search's held request shows that hold as its ownqueue_wait, while for the holder the same hold shows as statement time and not as queue wait. A further case pins that nothing is wrapped while no service subscribes.Acceptance notes
turso-adapter.tsfor the turso package.turso-adapter.tsis over 1,000 lines (1,907), and the dev rule sends a new concern into a sibling module. So the timing code is in a newpackages/plugins/knowledge-turso/src/search-timing.ts, andturso-adapter.tsgains three calls.knowledge-tools.tsis unchanged: the line sits in the service, which everysearch_knowledgedoor passes through.refusedandfailedwere added to the card's field list: both are counts or flags, not content, and without them an empty answer cannot be told from a refused or thrown one.IKnowledgeService.searchcaller gets the same line. Today the only caller in this tree is thesearch_knowledgeexecutor.Verification
Two-minute check:
pnpm --filter @objectstack/knowledge-turso exec vitest run src/__tests__/search-timing-39037.test.ts. Expected: 3 passed. On a hosted runtime, one[knowledge] search timinginfo line persearch_knowledgecall.Read first, by risk:
packages/plugins/knowledge-turso/src/search-timing.ts(the client proxy in the request path of every store call: the passthrough when no search is in scope),packages/services/service-knowledge/src/knowledge-search-timing.ts(content absence; thefinallythat logs a thrown search), and theknowledge-service-search.tshunks (calls only).Readings on head
2e2a79729b(branch tip after mergingorigin/main6354509; the incoming commits touchdocs/adr,packages/spec/src/uiandpackages/cli, none of this PR's packages).Tests (local, under the shared verify lock)
pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2: Test Files 32 passed, Tests 902 passed (VERDICT command-exit 0).pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2: Test Files 7 passed, Tests 338 passed (VERDICT command-exit 0).pnpm --filter @objectstack/service-knowledge typecheckandpnpm --filter @objectstack/knowledge-turso typecheck(tsc plus the test-layer check): exit 0, on6df70abf7cbefore the merge. The merge touched neither package and leftpackages/spec/src/contractsalone; not re-run.git checkout HEADwithgit hash-objectequal before and after andgit statusempty. (1)queued()handingserial()the bare work: the turso contention case goes red,expected 0 to be greater than or equal to 100. (2) DroppingnoteSearchTargets(sources): three service cases go red,sources: [].Gates (derived by dispatch-gates --commands, reconciled with --ran)
check:dual-build-cjs-loadsreports PREREQUISITE NOT MET (exit 3). It reads every package's builtdist, and this worktree built only the two packages' dependency closure, so it is left to CI.check:logger-receiver-detach(the line now callslogger.infoandlogger.debugthrough the receiver),check:objectql-double-limitandcheck:where-matcher(the two test doubles now filter generically, hold the caller'slimitafter the filter, and refuse a combinator). Each is exit 0 on re-run.check:query-options-erasure(301 s) andcheck:type-check-debt(239 s) went past a first 200 s local cap on a shared box and are exit 0 on re-run.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ