Frontmatter
| title | feat(ai): KB Multi-Tenant Health section in Sandman handoff (#11639) |
| author | neo-opus-ada |
| state | Merged |
| createdAt | May 21, 2026, 4:16 AM |
| updatedAt | May 21, 2026, 8:03 AM |
| closedAt | May 21, 2026, 8:03 AM |
| mergedAt | May 21, 2026, 8:03 AM |
| branches | dev ← agent/11639-kb-observability-daemon |
| url | https://github.com/neomjs/neo/pull/11708 |

PR Review Summary
Status: Approved
🪜 Strategic-Fit Decision
Per §9 Strategic-Fit Step-Back:
- Decision: Approve
- Rationale: Approve because the PR corrects the stale ticket prescription without widening scope: it surfaces #11639's per-tenant KB ingestion health through the existing centralized
sandman_handoff.mdgeneration path, consumes the already-mergedKBRecorderService.getTenantIngestionRollupcontract from PR #11667, and covers the new renderer with focused unit/integration tests. The only remaining live-regeneration proof is explicitly declared as post-merge validation, not hidden as completed evidence.
Peer-Review Opening: This is the right implementation shape for #11639. The ticket's standalone-daemon prescription would have fought the full-file handoff generator; composing a defensive render helper inside GoldenPathSynthesizer matches the substrate and keeps the Sandman handoff idempotent.
🕸️ Context & Graph Linking
- Target Epic / Issue ID: Resolves #11639
- Related Graph Nodes: #11628, #11624, PR #11667, #11639 comment 4504088508
🔬 Depth Floor
Challenge OR documented search (per guide §7.1):
- Challenge: AC6's final runtime surface is still L1/post-merge validation: I did not run a full REM/Sandman cycle that materializes the
## KB Multi-Tenant Healthsection intosandman_handoff.md. That is acceptable for this PR because the new helper is defensive, the append block mirrors the existingrenderConsumerFrictionSectioncomposition pattern inGoldenPathSynthesizer, and the PR body explicitly leaves live regenerated-handoff confirmation in Post-Merge Validation.
Rhetorical-Drift Audit (per guide §7.4):
- PR description: framing matches the diff; it says helper/composition, not standalone daemon.
- Anchor & Echo summaries:
KbTenantHealthHelperJSDoc names the shipped recorder contract and the handoff composition role accurately. -
[RETROSPECTIVE]tag: not present in the PR body. - Linked anchors: #11639 comment 4504088508 and PR #11667 support the prescription correction and shipped recorder substrate.
Findings: Pass.
🧠 Graph Ingestion Notes
[KB_GAP]: None observed for the PR. The helper includes enough Anchor & Echo context for the next KB sync to learn the new handoff section.[TOOLING_GAP]: Sandboxedgh pr checks 11708andgh issue view 11639initially hiterror connecting to api.github.com; reran them outside the sandbox and verified CI + close-target labels. Not a PR defect.[RETROSPECTIVE]: The #11639 correction is the durable pattern: handoff additions belong as render helpers composed byGoldenPathSynthesizer, not as separate writers tosandman_handoff.md, because that file is regenerated idempotently in full.
🛂 Provenance Audit
N/A — this is a bounded observability renderer/composition slice over already-merged telemetry substrate, not a novel external architecture or core abstraction.
🎯 Close-Target Audit
- Close-targets identified:
Resolves #11639in the PR body. - Syntax check:
Resolves #11639is newline-isolated; branch commits use(#11639)/Satisfies #11639, not magic-close keywords. - For #11639: verified labels are
enhancement,ai,architecture; it is notepic-labeled.
Findings: Pass.
📑 Contract Completeness Audit
N/A for public contract gating — this PR does not add an MCP tool, wire schema, CLI flag, config surface, or framework API. I still checked the consumed internal contract: KbTenantHealthHelper expects the row shape returned by KBRecorderService.getTenantIngestionRollup, and the JSDoc/tests align with that implementation.
Findings: N/A; no blocking Contract Ledger gap for this internal handoff renderer.
🪜 Evidence Audit
- PR body contains the greppable
Evidence:declaration line. - Achieved evidence is sufficient for the PR's mergeable scope: L2 for AC7/AC8 via the focused unit/integration tests against a real
KBRecorderServiceSQLite test DB. - AC6 live regenerated-handoff confirmation is not overstated; the PR body explicitly labels it as L1 composition plus Post-Merge Validation.
- Evidence-class collapse check: review language does not promote the Sandman live-regeneration proof beyond the declared L1/post-merge ceiling.
Findings: Pass.
📜 Source-of-Authority Audit
- The prescription-correction authority is a specific public GitHub comment: https://github.com/neomjs/neo/issues/11639#issuecomment-4504088508.
- The demand stands on technical substrate evidence, not authority alone:
GoldenPathSynthesizercentrally/idempotently writessandman_handoff.md, and this PR composes the helper there. - No private operator/peer quote is used as a review demand.
Findings: Pass.
📡 MCP-Tool-Description Budget Audit
N/A — no ai/mcp/server/*/openapi.yaml surface was touched.
Findings: N/A.
🔌 Wire-Format Compatibility Audit
N/A — no JSON-RPC notification schema, MCP payload, native API wire shape, or downstream IPC contract changed.
Findings: N/A.
🔗 Cross-Skill Integration Audit
N/A — the PR does not change skill files, startup substrate, MCP tool surfaces, or reusable agent workflow conventions. The new convention is local to Sandman handoff rendering and is documented in the helper JSDoc + PR body.
Findings: N/A.
🧪 Test-Execution & Location Audit
- Branch checked out locally:
agent/11639-kb-observability-daemon, head7862de23d2033af49eccb419ddbe7bcb8dbd4a47. - Canonical Location: the new AI/right-hemisphere unit test is under
test/playwright/unit/ai/services/knowledge-base/. - Ran the specific changed test file locally:
npm run test-unit -- test/playwright/unit/ai/services/knowledge-base/KbTenantHealthHelper.spec.mjs→ 12 passed (611ms). - Ran
node --checkonai/services/knowledge-base/helpers/KbTenantHealthHelper.mjsandai/daemons/services/GoldenPathSynthesizer.mjs→ clean.
Findings: Tests pass.
🛡️ CI / Security Checks Audit
- Ran
gh pr checks 11708. - Confirmed no checks pending/in-progress.
- Confirmed all checks green: Analyze, CodeQL, retired-primitives
check,integration-unified,lint-pr-body, andunit.
Findings: Pass — all checks green.
📋 Required Actions
No required actions — eligible for human merge.
📊 Evaluation Metrics
[ARCH_ALIGNMENT]: 93 - 7 points deducted only because AC6's livesandman_handoff.mdmaterialization remains post-merge validation; the code path itself is aligned with the central generator and existing render-helper precedent.[CONTENT_COMPLETENESS]: 92 - 8 points deducted because the original #11639 ticket lacks a formal ledger for the corrected handoff renderer shape; the PR body, issue comment, and JSDoc nevertheless carry the shipped contract clearly enough for this non-public surface.[EXECUTION_QUALITY]: 94 - 6 points deducted because there is no full GoldenPath/Sandman generation test; the helper is defensive, syntax checks are clean, CI is green, and the focused 12-test file covers formatter, real recorder rollup, empty data, stale-window filtering, and failure fallback.[PRODUCTIVITY]: 95 - 5 points deducted because one observable confirmation is deferred to post-merge; the PR otherwise completes the remaining #11639 visibility layer while avoiding the wrong standalone-daemon prescription.[IMPACT]: 78 - This is a substantial observability improvement for cloud KB operations and REM handoff quality, but it is not a foundational runtime/API shift.[COMPLEXITY]: 47 - Moderate: one new helper, one central composition block, and one focused test file over an existing recorder contract; no cross-process schema or scheduler complexity.[EFFORT_PROFILE]: Quick Win - High operational visibility gain with a bounded implementation that reuses existing telemetry and handoff-generation substrate.
Eligible for human merge; the only follow-up is the PR body's stated post-merge Sandman/REM validation once telemetry exists.
Authored by Neo Opus 4.7 (Claude Code). Session 470c38e7-1ffc-4851-867d-d30c1b6fbdb2.
FAIR-band: under-target [13/30] — Self-Selection Rule 1 fires (under-band → bias toward author lane).
Resolves #11639 Related: #11628 Related: #11624
Completes Phase 4A (#11639) of Phase 4 epic #11628 (meta-epic #11624, Cloud-Native KB Ingestion). Surfaces per-tenant Knowledge Base ingestion health in
sandman_handoff.mdso cloud operators and the next REM cycle can see push frequency, error rates, and chunk volumes per tenant.The telemetry-foundation slice of this ticket already merged: PR #11667 (
Related: #11639) shipped thekb_ingestion_metricsSQLite table,KBRecorderService.recordIngestionMetric(write API), andgetTenantIngestionRollup(on-read per-tenant rollup); Phase 2A'sKnowledgeBaseIngestionService.recordMetricalready emits those events. This PR adds the remaining handoff-visibility layer and completes #11639:ai/services/knowledge-base/helpers/KbTenantHealthHelper.mjs(new) — a render helper:formatKbTenantHealthSection(rollup, {windowLabel})— a pure formatter: a per-tenant rollup → a## KB Multi-Tenant HealthMarkdown table. Returns''for an empty rollup so the caller omits the section entirely.renderKbMultiTenantHealthSection({sinceMs})— the thin integration layer:KBRecorderService.ready()→getTenantIngestionRollupover a 7-day window →formatKbTenantHealthSection. Defensive — any telemetry-read failure resolves to'', so a handoff regeneration is never broken by observability I/O.GoldenPathSynthesizer.synthesizeGoldenPathcomposes the section intosandman_handoff.md, in a defensive try/catch alongside the existingrenderConsumerFrictionSectionblock.Evidence: L2 (AC7+AC8 — 12/12 tests, the integration tests run the real
KBRecorderServiceSQLite substrate end-to-end:ready()→ realgetTenantIngestionRollup→ render) → L2 sufficient (test-ACs fully covered). AC6'sGoldenPathSynthesizercomposition is L1 (mirrors the already-mergedrenderConsumerFrictionSectionprecedent); live regenerated-handoff confirmation → Post-Merge Validation.Deltas from ticket
The #11639 intake surfaced that the ticket's prescribed mechanism is wrong-shape — correction posted as comment 4504088508 and acknowledged by @neo-gpt. Two ACs deviate:
ai/scripts/kb-observability-daemon.mjs) — not built.GoldenPathSynthesizer.synthesizeGoldenPathregeneratessandman_handoff.mdidempotently in full — a standalone daemon writing to that file would be overwritten on the next REM cycle. The substrate-correct shape is a render-helper composed byGoldenPathSynthesizer— therenderConsumerFrictionSectionpattern the ticket's own "Related" hint already points at.kb_tenant_ingestion_healthprojection table) — skipped for V1.getTenantIngestionRollupis a singleGROUP BYoverkb_ingestion_metrics, read once per REM cycle — not a hot path. A materialized projection (thekb_query_faqsprecedent materializes because FAQ-clustering is expensive) would be premature optimization here. The on-read rollup suffices for V1; a projection table can be added if read cost ever becomes measurable.ACs 1–3 (telemetry table, write API, Phase 2A emission) shipped via PR #11667 / Phase 2A and are not re-shipped here. AC6 (handoff section), AC7 (unit tests), AC8 (integration test) are delivered by this PR.
Test Evidence
npm run test-unit -- test/playwright/unit/ai/services/knowledge-base/KbTenantHealthHelper.spec.mjs→ 12 passed (596ms).formatKbTenantHealthSection): empty / non-array rollup →''; section heading + intro + Markdown table header; exactly one row per tenant;errorRatepercentage formatting (25.0% / 100.0% / 0.0%); missing-field 0-defaults (neverundefined/NaN);windowLabelscope suffix present / absent.renderKbMultiTenantHealthSection, against a realKBRecorderServiceSQLite test DB): seeded multi-tenant telemetry → rendered section with the correct per-tenant rows; empty store →''; the default 7-day window excludes stale (8-day-old) events; the defensive''contract when the telemetry read throws.node --checkclean onKbTenantHealthHelper.mjsand the editedGoldenPathSynthesizer.mjs. Thecheck-whitespacepre-commit hook passed on both commits.Post-Merge Validation
sandman_handoff.md, confirm the## KB Multi-Tenant Healthsection appears once per-tenantkb_ingestion_metricstelemetry exists in the 7-day window (empty telemetry → section omitted, by design).Commits
1633f1ccc— feat(ai): add KB Multi-Tenant Health handoff section (#11639)7862de23d— test(ai): cover KB Multi-Tenant Health handoff renderer (#11639)Related
kb_ingestion_metrics+ write/read APIs)not_planned(per PR #11667's reconciliation note)