Repository navigation
Description
Summary
resolveDataDir() adopts <cwd>/data as a legacy store when it contains state_store.db or iii-config.yaml. The check came in with #314 (the fix for #303), the only commit that has touched src/cli-data-dir.ts, and its test treats it as data-dir migration. The capture spool (#1460) resolves its folder through the same function, with the agent session's working directory as cwd. So in a project that still has such a folder, the hooks write their capture spool into <project>/data/capture-spool, even when the daemon uses a different data dir and never reads that folder.
In my case the folder had the layout described in #303 (state_store.db and stream_store, both last modified on 2026-06-04, before #303 was closed on 2026-07-25). The daemon uses %USERPROFILE%\.agentmemory\data.
Environment: agentmemory 0.9.33 (npm), iii 0.25.1, Windows 11, Claude Code hooks, daemon started with --data-dir %USERPROFILE%\.agentmemory\data. The code references are from main (54bbb7cd351e).
Why it happens
src/cli-data-dir.ts:114-120: the legacy check runs before the platform default and usescwd. For hooks that isprocess.cwd(), the agent's working directory.spoolDir()(src/capture/spool.ts) resolves the data dir this way whenAGENTMEMORY_CAPTURE_SPOOL_DIRandAGENTMEMORY_DATA_DIRare unset, which is the normal setup for hooks.test/cli-data-dir.test.ts("adopts legacy data without sharing it with another instance", marker comment "Legacy marker recognized during data-dir migration") expects<repo>/datato be adopted. I found nothing that limits the adoption to the process that owns the store.
What I observed
- From 2026-11-09 to 2026-11-17, hook runs whose working directory was the project root spooled 828 records into
<project>/data/capture-spool(the cumulative counter in its stats file), including the records from an outage on 2026-11-17. Hook runs from other working directories used%APPDATA%\agentmemory\capture-spool, so the spool was split by working directory. - The spooled records contain tool input and output (after the hooks' redaction). They ended up inside the project tree, which in my case is a cloud-synced folder.
data/is also a common name for a project's own files; in my project, the build packages that folder. - A hook-side drain only drains the folder its own working directory resolves to, so the two folders were drained independently. The daemon's boot drain read neither of them (Windows: with a non-default data dir, the boot-time spool drain misses the hooks' default spool because APPDATA is not in the worker environment #1809).
- 43 files named
local-3111.stats.json.<pid>.tmpwere left in<project>/data/capture-spool.writeStats()(src/capture/spool.ts:228-235) swallows a failedrenameSyncand leaves its temp file behind. I assume the renames failed because the sync client heldlocal-3111.stats.json, but I did not capture the error.
Suggested change
- Do not adopt
<cwd>/datain the hooks' spool resolution. Spool to the platform default,AGENTMEMORY_DATA_DIRorAGENTMEMORY_CAPTURE_SPOOL_DIR. Hooks run in arbitrary project directories, and the daemon reads<cwd>/dataonly if it was itself started there and adopted it. Keep the adoption for the CLI, where fix(cli): add --data-dir flag + AGENTMEMORY_DATA_DIR so engine state lives outside repos #314 put it. - Smaller, related: in
writeStats(), remove the temp file when the rename fails.
I have not built or run a patched version.
Activity