DB Reset Playbook — Wipe & Rebuild coding-os Data
P: Canonical procedure for wiping the coding-os runtime state (SQLite + optional agent state, plus a legacy
.coding-os/graph_os.kuzu/dir if a consumer still has one) and verifying the auto-rebuild. R: An agent or operator needs to reset a corrupted DB, start a clean experiment, or recover from schema drift between deployments. S: Single-row corrections (use targeted UPDATE /cos task-validate). Don't nuke for a single bad observation. N: docs/engineering/state-files.md, docs/engineering/mcp-fast-path-entry.md
Nav: Playbooks Index | Docs Index
What gets wiped
| Artifact | Path | What it holds |
|---|---|---|
| SQLite main DB | .coding-os/coding-os.db |
observations, learned_patterns, tasks index, graph_nodes/edges, retrievals, embeddings, metrics, audit |
| Legacy Kùzu directory | .coding-os/graph_os.kuzu/ |
retired 2026-05-18; cos db-reset still removes the dir if a consumer has one left over |
| Agent session state | .coding-os/<agent>/ |
gates, traces, markers (one dir per agent: claude/codex) |
| Task SSOT (opt-in) | docs/tasks/TASK-*.md |
Scrumban task files — disk is the source of truth, DB is a derived index |
Default cos db-reset --confirm wipes the first two only. Use --wipe-sessions and --wipe-tasks to extend the blast radius.
When NOT to use this
- A single observation is wrong →
UPDATE observations SET … WHERE id=…; - A task file is malformed →
cos task-validate TASK-NNNand fix the YAML. - Graph extraction missed a file →
cos graph-reindex --force --path <dir>. - Schema drift after a migration was applied → roll the migration forward; never edit a past migration (Rule 9).
A full reset is a last resort. It throws away weeks of memory, retrieval quality signals, and the rolling project trajectory. Even with the backup, restoring is manual.
Command surface
cos db-stats # row counts per table, total size — read-only.
cos db-reset # DRY RUN — print targets, sizes, populated tables. No writes.
cos db-reset --confirm # Real wipe. Always backs up first unless --no-backup.
cos db-reset --confirm --wipe-sessions
cos db-reset --confirm --wipe-tasks # also deletes docs/tasks/TASK-*.md
cos db-reset --confirm --no-backup # skip backup (NOT recommended)
cos db-reset --confirm --no-reindex # skip the graph-reindex chase step
Backups land at .coding-os/backups/reset-<YYYYMMDD-HHMMSS>/. Restore is cp -r from there.
After-the-reset checklist
- Restart the agent / MCP server. The MCP server boots, runs all 27 migrations against the empty (or missing) DB, and recreates every table + index.
- Verify the schema —
sqlite3 .coding-os/coding-os.db "SELECT COUNT(*) FROM sqlite_master WHERE type='table';"should return ≥ 45. - Task sync — first agent prompt fires
auto-task-sync.sh(PostToolUse) which callstask_sync.sync_tasksto re-indexdocs/tasks/*.mdinto thetaskstable.- Manual:
python -m core.thinking_os.task_syncfrom the repo root.
- Manual:
- Graph rebuild —
cos graph-reindexwalks the repo, extracts nodes/edges, repopulatesgraph_nodes+graph_edges_v12+graph_evidence_v12. Without this step the graph stays empty andcos_graph_*tools return empty results. - Document chunks (RAG) —
cos doc-reindex(or firstcos_doc_searchcall) repopulatesdocument_chunks+embeddings. - Observations / learned_patterns / metrics — only fill via runtime activity. Expected to start empty.
What does NOT auto-fill
observations— only written whencos_observation_recordruns or a hook (e.g.capture-observation.sh) fires.learned_patterns— populated when an observation is promoted; needs activity over multiple sessions.project_trajectory— populated whencos_trajectory_snapshotruns (typically after task-done).session_summaries— written at session end.
A freshly reset DB is, by design, almost empty until the agent does real work.
Verification matrix
After a --confirm run, check:
cos db-stats # schema present, rows ~0 across the populated set
sqlite3 .coding-os/coding-os.db ".tables" | wc -w # 45+ tables
cos doctor # health checks all green
cos graph-reindex # then re-run db-stats; graph_* tables populated
Failure modes
- Backup fails (disk full / permissions) — command exits 1 before deleting anything. Free space and retry.
cosnot on PATH after wipe — the wipe doesn't touch the installedcosbinary; if it's missing, that's a separate install issue.- Sub-agent MCP server holds DB lock — kill stragglers:
pkill -f "thinking_os/server.py"then retry.
See also
- docs/engineering/state-files.md — what lives where
- docs/engineering/mcp-schema-traps.md — schema after rebuild
- docs/engineering/graph_os-queries.md — graph repopulation