observer + scrum: gold-standard answer corpus for compounding context
lakehouse/auditor 1 blocking issue: todo!() macro call in tests/real-world/scrum_master_pipeline.ts

The compose-don't-add discipline applied to the original ask: when big
models produce good results (scrum reviews + observer escalations),
save them into the matrix indexer so future small-model handlers can
retrieve them as scaffolding. Local model gets near-paid quality from
a fraction of the cost.

New: scripts/build_answers_corpus.ts indexes lakehouse_answers_v1
from data/_kb/scrum_reviews.jsonl + data/_kb/observer_escalations.jsonl.
doc_id prefixes ('review:' vs 'escalation:') let consumers same-file-
gate the prior-reviews case while keeping escalations broad.

observer.ts: buildKbPreamble adds lakehouse_answers_v1 as a third
retrieval source alongside pathway/bug_fingerprints + lakehouse_arch_v1.
qwen3.5:latest synthesis now compresses three lenses into a single
briefing for the cloud reviewer.

scrum_master_pipeline.ts: epilogue dispatches a fire-and-forget rebuild
of lakehouse_answers_v1 after each run so this run's accepted reviews
are retrievable within ~30s. LH_SCRUM_SKIP_ANSWERS_REBUILD=1 disables.

Verified live: kb_preamble grew 416 → 727 chars after wiring third
source; qwen3.5:latest synthesis (702 → 128 tokens) compresses
correctly; deepseek-v3.1-terminus diagnosis (301 → 148 tokens) is
sharper, citing architectural patterns (circuit breaker, adapter
files) instead of generic timeouts. Total cost per escalation
unchanged at ~$0.0002.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-04-26 18:49:36 -05:00
co-authored by Claude Opus 4.7
parent 340fca2427
commit 0844206660
3 changed files with 181 additions and 4 deletions
+24 -4
View File
@@ -193,8 +193,8 @@ async function buildKbPreamble(sigHash: string, cluster: ObservedOp[]): Promise<
if (r.ok) fingerprints = (await r.json() as any).fingerprints ?? [];
} catch {}
// Step 2: matrix retrieval against the architectural corpus we
// already maintain. Cluster summary is the search query.
// Step 2: architectural matrix (lakehouse_arch_v1) — ADRs/PRD/plan
// intent. Cluster summary is the search query.
const clusterSummary = cluster.slice(-5).map(o =>
`${o.endpoint ?? "?"} ${o.input_summary ?? ""} ${o.error ?? ""}`
).join(" | ");
@@ -203,13 +203,28 @@ async function buildKbPreamble(sigHash: string, cluster: ObservedOp[]): Promise<
const r = await fetch(`${LAKEHOUSE}/vectors/search`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ index_name: "lakehouse_arch_v1", query: `${taskClass} ${clusterSummary}`, top_k: 5 }),
body: JSON.stringify({ index_name: "lakehouse_arch_v1", query: `${taskClass} ${clusterSummary}`, top_k: 4 }),
signal: AbortSignal.timeout(5000),
});
if (r.ok) matrixChunks = (await r.json() as any).results ?? [];
} catch {}
if (fingerprints.length === 0 && matrixChunks.length === 0) return "";
// Step 3: gold-standard prior answers (lakehouse_answers_v1) — past
// scrum reviews + observer escalations. This is where the BIG-model
// results we save live; future small-model handlers retrieve them
// here as scaffolding so the cheap rung gets near-paid quality.
let answerChunks: { doc_id?: string; chunk_text?: string; score?: number }[] = [];
try {
const r = await fetch(`${LAKEHOUSE}/vectors/search`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ index_name: "lakehouse_answers_v1", query: `${taskClass} ${clusterSummary}`, top_k: 3 }),
signal: AbortSignal.timeout(5000),
});
if (r.ok) answerChunks = (await r.json() as any).results ?? [];
} catch {}
if (fingerprints.length === 0 && matrixChunks.length === 0 && answerChunks.length === 0) return "";
// Step 3: synthesis via local model (qwen3.5:latest, provider=ollama).
// Compresses the raw bundle to a 1-2 sentence briefing the cloud
@@ -226,6 +241,11 @@ async function buildKbPreamble(sigHash: string, cluster: ObservedOp[]): Promise<
`${i + 1}. [${c.doc_id ?? "?"}] ${(c.chunk_text ?? "").slice(0, 200)}`
).join("\n")
: "",
answerChunks.length > 0
? "PRIOR GOLD-STANDARD ANSWERS (similar past reviews + escalations):\n" + answerChunks.map((c, i) =>
`${i + 1}. [${c.doc_id ?? "?"}] ${(c.chunk_text ?? "").slice(0, 240)}`
).join("\n")
: "",
].filter(Boolean).join("\n\n");
const synthPrompt = `A failure cluster (sig_hash=${sigHash.slice(0, 8)}, ${cluster.length} occurrences, task_class=${taskClass}) is about to be escalated for diagnosis. Here are prior signals from our knowledge base: