swarm.db: one queryable SQLite trace mirror for swarm runs (status defaults to fail; kills finalise; per-run spend) #447
Labels
No labels
agent-blocked
agent-working
autopilot
bug
deferred
deploy-pending
enhancement
landing-pr
model-haiku
model-opus
model-sonnet
needs-design
needs-info
needs-triage
no-triage
out-of-scope
priority
ready-for-agent
ready-for-human
ready-for-session
rehearsal-183
snapshot-pending
standing-drive
wayfinder:grilling
wayfinder:map
wayfinder:prototype
wayfinder:research
wayfinder:task
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Matou/idss#447
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Learning L4 of
docs/research/2026-08-11-software-factory-learnings.md: reconstructing one ticket's history means greppingfive sinks (host runlog, /tmp verdict artifacts, Mattermost, worker logs,
healer evidence, journalctl). Nothing records per-run/per-issue cost (the
2026-07-25 quota exhaustion burned ~14 h invisibly), and a hung worker emits
nothing anywhere (#435 green-and-empty). SSSF streams everything into one
WAL SQLite mirror; files stay the raw record; a
processestable existsbecause "a hung agent emits nothing, which is exactly when you need its pid."
What to build
A SQLite db on the workstation (e.g.
~/swarm/state/swarm.db, NOT in-repo),written by
run-swarm.shand the worker wrapper as events happen (WAL mode,busy_timeout, one small transaction per event). This is a MIRROR — everyexisting sink stays; losing the db must lose nothing.
Tables (adapt SSSF's shape to swarm vocabulary):
runs— run id, repo, trigger (cron/label/dispatch), started/ended,verdict, verdict source line
attempts— run id, issue number, iteration, status TEXT DEFAULT'fail' (success must be earned by a verified clean exit — a crash can
never read green), commit SHAs, close-report outcome
events— attempt-scoped: gate results with evidence, limit pauses, heals,asks, rescue-branch actions
processes— run id, kind (worker container / claude pid), pid orcontainer id, command, started/ended (
ended_atNULL = believed alive) —the #435 answer: a wedge is now a row with no end and no events
spend— per attempt where extractable from Claude Code output: tokensand/or request counts; the column exists even while extraction is partial
Two invariants stolen verbatim from SSSF:
success.
nothing reads
runningforever.Reader surface: 3–4 canned queries in a
swarm-db.shhelper ("history ofissue N", "open processes", "spend by week", "runs red by stage").
Acceptance criteria
EXISTS); WAL pragmas on every connection
finalised rows (fixtures/tests)
worker_wedgedetection also writes the wedge as an unfinalisedprocessesrow + eventdependable trail when the Actions API hangs)
References
docs/research/2026-08-11-software-factory-learnings.md(L4)references/observability.md(schema + WAL pragmas + "success must beearned") in
disler/super-simple-software-factoryLanded in
a234766(onorigin/main).swarm.db — one queryable SQLite trace MIRROR for swarm runs, per L4.
New files
.sandcastle/swarm-db.py— the engine. python3 (guaranteed on every swarm host and in the worker sandbox; thesqlite3CLI is not — and python's parameter binding quotes free-text verdict lines/commands safely). WAL +busy_timeout+CREATE TABLE IF NOT EXISTSon every connection. Tablesruns/attempts/events/processes/spend;attempts.status NOT NULL DEFAULT 'fail'..sandcastle/swarm-db-lib.sh— best-effort bash writers sourced byrun-swarm.sh; every writer swallows its own failure (a mirror we cannot write must never red a run) and no-ops silently if python3 is absent..sandcastle/swarm-db.sh— reader:issue <N>|open-processes|spend-weekly|red-by-stage..sandcastle/tests/swarm-db-test.sh— 9 groups, all green.Two invariants made law
run-endnever promotes a status (test proves an earnedsuccesssurvives finalisation while an un-earned attempt readsfail).run-swarm.shnow traps SIGTERM/SIGINT and routes them through its EXIT trap, whoserun-endcloses the run row + every open attempt so nothing readsrunningforever.Acceptance
CREATE TABLE IF NOT EXISTS); WAL pragmas on every connection.worker_wedgedetection also writes the wedge as an UNFINALISEDprocessesrow +worker_wedgeevent (the #435 answer — a hung agent emits nothing, so the open row IS the evidence; surfaced byswarm-db.sh open-processes).tests/runlog-lib-test.shstill green).run-swarm.sh wiring: opens a run row up front (so an early-death/killed run still traces), events the ready-set / limit-pause / #435 wedge, records born workers as finalised proc rows, finalises in
on_exit.Follow-up (noted, not blocking): per-attempt
status+ tokenspendextraction from the worker wrapper (main.mts) — the columns exist while extraction is partial, exactly as the ticket allows.The db lives at
~/swarm/state/swarm.db(off-repo, gitignored);~/swarm/logs/run-swarm-verdicts.logand the /tmp verdict artifacts stay the raw record.