mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-10-25 06:33:13 +08:00
DELETE /api/project removed the project's .db file but never told the watcher; the zombie watch kept polling the repo and the next change silently resurrected the deleted DB (#803). Wire the watcher into the UI HTTP server (non-owned ref; created before the server, freed after it) and unwatch after a successful unlink and on ENOENT (clears an already-orphaned watch, still 404). Invalid name stays a plain 404 with no unwatch; a non-ENOENT unlink failure stays 500 and keeps the watch. The cbm_file_exists pre-check is replaced by unlink-errno handling, removing the TOCTOU window. Distilled from #830, rebased over the defer_state_free refactor (#817): the OOM hardening of the deferred-free path moves into defer_state_free itself so BOTH unwatch and stale-root prune get it. On pending-free realloc failure the helper no longer frees the state immediately (a potential use-after-free against an in-flight poll_once snapshot) — it logs watcher.unwatch.oom and returns failure, and the callers keep the entry registered; the prune path retries on the next poll cycle. Carries six httpd regression tests from #830 driving the live UI server with a real watcher wired in. Closes #803. Co-authored-by: Dustin Persek <dustin.persek@protonmail.com> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>