feat(tracing): add retrieval evidence child spans - #599
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
Review swarm findings (posted before fixes, per program mandate)Opposite-family swarm: 3 Claude Opus lanes (correctness / security / adversarial, SME-injected from HIGHH1 (correctness): the entire H2 (adversarial, measured): unbounded span payloads — one traced search duplicates full row content 4-5x; measured 47.6 MB serialized and 528 ms of synchronous masking on the request path. MEDIUMM1 (security + adversarial, found independently by both lanes): handler-supplied trace metadata spreads LAST in M2 (correctness + adversarial): M3 (correctness): src-tree M4 (adversarial): chosen-vs-filtered evidence is wrong for qmd rows in M5 (correctness): two stages traced in the server tree have no src-tree counterpart — LOW
INFO
Failure-proof re-verification: CONFIRMEDIndependently reproduced in a detached scratch worktree at head f2a42aa: green 54/54 first; a one-line suppression of Verdict: not mergeable as-is. H1 defeats the purpose of the PR on the production tree; H2 is a measured request-path cost. Fix lane launching next; fixes will be verified as a delta against these findings before the Review Gate box is checked. |
Wire tracing into the core01 entrypoint, bound retrieval payloads, preserve authoritative metadata, correct ranking and fallback evidence, and remove the unreachable candidate-dedupe span. Co-Authored-By: Claude <noreply@anthropic.com>
Exercise the real src search tool, bounded span degradation, metadata precedence, fallback classifications, duplicate qmd paths, fail-open summarizers, transform equivalence, concurrent attribution, and parent observation cleanup. Co-Authored-By: Claude <noreply@anthropic.com>
H1 (dead-tree instrumentation), M3 (precomputed-value spans) -> correctness; M1 (metadata spread order vs auth-derived identity) -> security; H2 (unbounded evidence payloads), M4 (collapsing selection keys) -> adversarial. Provenance: pull/599#issuecomment-5202342752.
Fix-delta verification receipt (controller-posted)Independent opposite-family verification of f2a42aa..3ccbc95 against the findings above, performed against the CODE (fix lane's report treated as untrusted). Every HIGH/MEDIUM/LOW: FIXED_VERIFIED. Verdict: mergeable. Non-vacuity was established by mutation, not by reading assertions: seven independent mutations (revert the 300-char cap; restore metadata-last spread; restore id/path selection keying; strip the child-loop try/finally; collapse the fallback drop reasons; swap ALS for a module-global store; suppress span collection) each turned exactly one named test red (63/1) and green on restore. Honestly reported non-reds, carried as residual:
New-defect sweep of the delta itself: payload bound provably cannot change retrieval results; src-tree install neither reorders registration nor double-wraps (runtime is the per-process singleton, wrapper is per-server-instance by design); shutdown drainage is deadline-bounded and never rethrows on any exit path. State per LAW 0: verified WRITTEN and suite-passing at 3ccbc95 (tsc clean; 3272 pass / 0 fail; Postgres suites skip without the DB env — the tracing tests use fake pools and did run). Nothing here is RUNNING until deployed; live Langfuse rendering remains the rollout canary before #569 closes. Review gate now satisfied: findings posted before fixes, MEDIUM+ captured into docs/sme/ (commit 5c08455), fix delta independently verified. Checking the Review Gate box; merging on green CI at the exact head. |
Part of #569
Summary
installMcpTracingwrapper; retrieval handlers can emit nested observations only while a traced MCP call is activeserver/toolsfor the local rewrite runtime andsrc/toolsfor the core01 runtime) across full retrieval execution, embedding generation, vector/keyword/graph/qmd candidate queries, fallback dedupe, RRF/federated ranking, and citation filteringVerification
bunx tsc --noEmit --project /Volumes/ThunderBolt/_tmp/open-brain/_worktrees/issue-569-retrieval-evidence/tsconfig.jsonbun testwith/Users/rico/.config/open-brain/env.release-test: 3656 pass, 35 skip, 0 fail across 237 filessrc/tools/search-braincall, two concurrent calls, throwing summarizer, payload degradation, transform equivalence, duplicate-qmd-path classification, and child-observation cleanupspan.end()in the child-observation exporter; the new test failed withExpected: 1 / Received: 0, then the implementation was restored and the focused tracing suite passedRetrieval behavior
Instrumentation only. Existing retrieval tests and the full suite pass unchanged. No retrieval bug was found while instrumenting the pipeline.
Downstream rollout
Not applicable: this does not change MCP tool names, schemas, response shapes, auth/namespace semantics, transport behavior, migrations, Python client behavior, or agent-facing guidance. It adds operator-only Langfuse observations.
Critical Self-Review
rrfMergeand both fallback-merge implementations with empty and all-equal-score inputs, and the full suite passed.parent.startObservationwill render as nested observations under the post-call tool trace; the fake sink proves emitted shape and cleanup, but this PR does not perform a live hosted Langfuse canary.OPENBRAIN_TRACING_*gate is enabled.src/index.tsserver factory; bounded evidence payloads and precompiled masking regexes; made auth/status metadata authoritative; removed the unreachable candidate-dedupe span; moved ranking work inside spans; corrected duplicate-qmd and pagination classifications; mirrored execute/fallback spans into src; returned fallback classifications from the computation; and guaranteed parent observation cleanup.Review Gate