supertag-cli icon indicating copy to clipboard operation
supertag-cli copied to clipboard

[BUG] supertag-mcp: index WAL grows unbounded (→20GB+, disk-full) under many concurrent MCP instances — checkpoint starved by long-lived readers

Open ryan-baum opened this issue 4 months ago • 2 comments

Summary

Running several supertag-mcp servers concurrently (one per AI-tool/editor session) can drive the SQLite index WAL (tana-index.db-wal) to tens of GB, fill the disk, and wedge the servers. The WAL never truncates because every supertag-mcp process is a long-lived reader, and SQLite cannot checkpoint-truncate a WAL while any reader still holds an older snapshot. The configured wal_autocheckpoint / journal_size_limit don't help — those bound a WAL that can be checkpointed, and here the checkpoint is blocked.

Environment

  • supertag / supertag-mcp: 2.5.11 (Homebrew, macOS Apple Silicon)
  • Index: ~/.local/share/supertag/workspaces/main/tana-index.db (~850 MB), WAL mode
  • Concurrency: 8–21 live supertag-mcp instances observed (one spawned per editor/agent session; they persist for the life of each session)

Symptom

  • tana-index.db-wal grows without bound during/after a re-index. In one incident it reached ~21 GB, filled the disk, and left the supertag-mcp processes unkillable/wedged until a reboot (which reclaimed ~26 GB once the readers died and the WAL truncated).
  • Under normal load the same WAL sits at KB–low-MB, so the growth is clearly a checkpoint failure, not legitimate write volume.

Root cause (analysis)

SQLite's WAL is truncated by a checkpoint, but a checkpoint can only reclaim WAL frames up to the oldest snapshot any active reader is still using (SQLITE_BUSY / partial checkpoint otherwise). With many supertag-mcp processes each holding a read transaction / open connection for the whole session:

  1. A heavy write (e.g. a full sync index) appends many frames to the WAL.
  2. The passive autocheckpoint runs but can't TRUNCATE past the readers' pinned snapshot, so the file never shrinks.
  3. More writes append; the WAL only grows. PRAGMA journal_size_limit can't shrink a WAL that has no truncatable tail.
  4. Repeated re-indexes with readers always present → unbounded growth → disk-full → wedged servers.

This is a known SQLite WAL-starvation failure mode under many long-lived readers; it appears to be a robustness gap in how supertag-mcp manages the shared index connection, not a Tana or OS problem.

Reproduction

  1. Open ~10+ concurrent supertag-mcp sessions against the same workspace (each holds the index open).
  2. Trigger one or more full supertag sync index runs while those readers stay connected.
  3. Watch tana-index.db-wal grow and not truncate: ls -lah ~/.local/share/supertag/workspaces/main/tana-index.db-wal.
  4. pkill -f supertag-mcp (release all readers) → the next checkpoint truncates the WAL back to near-zero — confirming the readers were blocking truncation.

Impact

  • Silent disk exhaustion (the WAL is easy to miss) → wedged servers, forced reboot, ~20 GB lost until recovery.
  • Scales with the number of concurrent sessions — worse for exactly the multi-agent / multi-editor usage supertag-mcp is designed for.

Suggested remediations (options, not prescriptive)

  • Bounded/periodic TRUNCATE checkpoint on a dedicated writer connection that isn't held by a reader — e.g. after each sync index, run PRAGMA wal_checkpoint(TRUNCATE) on a fresh connection and retry with backoff until it succeeds (or log if readers block it).
  • Don't hold a read transaction open across MCP idle — open per-request / short-lived read transactions so readers don't pin an old snapshot indefinitely, freeing the checkpoint to truncate.
  • A single shared index connection (or a small pool) owned by one coordinator process, rather than N independent long-lived readers, so the writer can checkpoint against a known reader set.
  • A WAL-size guard / self-heal: if the WAL exceeds a threshold, log a loud warning and/or force a checkpoint (and surface it in supertag doctor), so it fails loudly instead of filling the disk.
  • At minimum, document the many-instances WAL-growth risk and the pkill -f supertag-mcp + re-sync recovery.

Related

  • #97 — tana_sync MCP tool crashes supertag-mcp after successful completion (adjacent MCP + sync lifecycle issue).
  • #105 / PR #85 — delta-sync hang (different failure, same sync/MCP area).

ryan-baum avatar Jul 08 '26 01:07 ryan-baum

Fresh recurrence plus a confirmed minimal recovery, in case it's useful data for prioritizing this.

Hit this again on 2.5.11 (macOS, Homebrew): tana-index.db-wal climbed to 22.7 GB with the data volume at 95% (~23 GiB free) before it was caught. ~38 concurrent supertag-mcp instances were live (one per agent/editor session), and a re-index had appended frames the checkpoint couldn't truncate past the long-lived readers — exactly the starvation path described above.

Recovery that worked cleanly and non-destructively:

pkill -f supertag-mcp                      # release the readers pinning old snapshots
sqlite3 <workspace>/tana-index.db 'PRAGMA wal_checkpoint(TRUNCATE);'

→ WAL went 22.7 GB → 0 B, reclaiming ~23 GiB instantly. The supertag-mcp processes respawn per session afterward with no data loss, and the main DB stayed at ~880 MB throughout — confirming it's the readers blocking truncation, not write volume.

As a local stopgap I've scheduled a periodic PRAGMA wal_checkpoint(TRUNCATE) on a fresh connection (every 30 min), which caps growth by catching the windows where no reader holds a snapshot — essentially the "bounded/periodic TRUNCATE checkpoint on a dedicated writer connection" option listed above. A built-in version of that, or short-lived per-request read transactions so readers stop pinning snapshots across idle, would fully close this for multi-instance setups. Happy to share the exact job if helpful.

ryan-baum avatar Jul 12 '26 14:07 ryan-baum

Confirming on v2.6.0, upgraded from 2.5.11. The WAL hit about 850 MB during a sync index and was back to 0 B as soon as it finished. Thanks for the TRUNCATE checkpoint and the per-cycle connection.

ryan-baum avatar Nov 24 '26 18:11 ryan-baum