KB orphan heal
ADMINISTRATOR Re-maps quarantinedcl_knowledge_base rows whose target_code no longer exists in the active Master, against the active Master, at Jaccard ≥ 0.72.Why orphans exist
Two paths:
- The active Master changed (cascade) and some KB target codes vanished
- Migration
0089quarantined the historical 2,419 / 2,952 orphan rows
Endpoints
GET /api/admin/kb-orphan-count
POST /api/admin/kb-orphan-heal { dryRun?: boolean = true }Algorithm
SELECT cl_knowledge_base WHERE quarantined=1
For each orphan:
candidates = SELECT FROM ucs_master_list
WHERE component_name LIKE '%<token>%'
AND version_id IN (SELECT id FROM ucs_foundation_versions WHERE is_active=1)
best = argmax(jaccard(orphan.target_code_text, candidate.component_name))
if best.score >= 0.72:
UPDATE cl_knowledge_base SET target_code = best.code, quarantined = 0
sampleHeals.push (cap 10)
else:
sampleUnhealed.push (cap 10)
on D1 error:
errorSamples.push (cap 10) with raw e?.messageResponse shape
json
{
"scanned": 2419,
"healed": 1873,
"unhealed": 532,
"errors": 14,
"sampleHeals": [...],
"sampleUnhealed": [...],
"errorSamples": [...]
}Operator workflow
- Always dryRun first.
POST /api/admin/kb-orphan-heal { "dryRun": true } - Inspect
sampleHeals— does the Jaccard match make sense? - Inspect
errorSamples— any SQLITE schema-drift errors? If so, fix the heal SQL before live run (see incident playbook for v2.31.0.20) - Live run:
{ "dryRun": false } - The completion posts an
ai-statusmessenger thread (no dedupe — admin-triggered).