[bug] The 3.1.0 transcript sweeper looking in the wrong directory
Summary
The 3.1.0 transcript sweeper installs and runs correctly but discovers zero files, because _transcript_roots() looks for <device>/agent/<dir>/.claude while Claude Desktop writes <device>/local_<uuid>/.claude.
Follow-up to #159, which this otherwise fixes. The sweeper design works; only the path walk misses.
Environment
- iai-mcp version: 3.1.0 (source checkout,
git pull+pip install .in the project venv) - macOS version: 26.6.2, arm64
- Python version: 3.12.14 (project venv; system default is 3.13, which the wheel correctly refuses)
- Node version: v26.7.0
- MCP host: Claude Desktop 1.40609.1, Cowork with local execution enabled
Steps to reproduce
iai-mcp cowork installon macOS with local Cowork sessions present.- Wait for the scheduled sweep, or run
iai-mcp transcript-sweep run --allow-live-home. cat ~/.iai-mcp/logs/transcript-sweep-stdout.log
Expected behaviour
The sweep discovers the transcripts Cowork has written under local-agent-mode-sessions/ and stages their new content.
Actual behaviour
{"files_seen": 0, "sessions_staged": 0, "lines_staged": 0, "files_failed": 0}
{"files_seen": 0, "sessions_staged": 0, "lines_staged": 0, "files_failed": 0}
{"files_seen": 0, "sessions_staged": 0, "lines_staged": 0, "files_failed": 0}
Every run, zero files. files_seen increments before any receipt check, sweep-state check or dedup, so this is discovery returning nothing rather than content being skipped.
The install itself is fine. The plist is written, scheduled, and sets both HOME and IAI_MCP_SWEEP_SCHEDULED=1, and transcript-sweep-stderr.log is empty. It runs on time and finds nothing.
The path
_transcript_roots() in transcript_sweep.py:
agent_dir = device_dir / "agent"
for ditto_dir in _safe_iterdir(agent_dir):
candidate = ditto_dir / ".claude"
so it expects:
local-agent-mode-sessions/<account>/<device>/agent/<dir>/.claude/projects/<slug>/*.jsonl
What Desktop 1.40609.1 actually writes here:
local-agent-mode-sessions/<account>/<device>/local_<uuid>/.claude/projects/<slug>/*.jsonl
There's no agent/ level. device_dir / "agent" doesn't exist, _safe_iterdir on a missing directory yields nothing, so no Cowork root becomes a candidate. That leaves only ~/.claude, which has no projects/ tree on a machine that doesn't use Claude Code CLI, and files_seen stays 0.
Concretely, one of my session homes:
.../74923e61-ca17-4711-bb15-8fb90ec50632/local_f0f24149-6386-4eb8-a482-075c9d6f1c67/.claude/projects/-sessions-zen-nifty-sagan/e2d632ee-59ee-4a19-845a-4633c44bfb31.jsonl
I have 109 session directories in that shape going back to 2026-03-05, and none of them have an agent/ parent.
Confirmation
Before 3.1.0 shipped I was running a stopgap launchd job of my own that globs
local-agent-mode-sessions/*/*/local_*/.claude/projects/*/*.jsonl
and hands each quiet transcript to capture-transcript --no-spawn. Same tree, one directory level different. It currently tracks 25 sessions and has been staging them without failures for several days, so the transcripts are present and readable by a scheduled agent under the same launchd context. Only the walk differs.
Suggested fix
Iterate the device directory's own children rather than assuming an agent/ level, or accept both:
for session_dir in _safe_iterdir(device_dir):
candidate = session_dir / ".claude"
if candidate.is_dir():
candidates.append(candidate)
That covers local_<uuid> and would still pick up an agent/<dir> layout if some builds use one.
Worth a probe in cowork status too. It currently reports the install, not the outcome. A line showing files seen on the last sweep, or the most recent transcript-sweep-<date>.log receipt, would surface this immediately instead of after reading stdout logs. Same theme as #114 and #159: the status check reports what the installer did rather than whether anything is being captured.
Fixed in v3.2.0 (pip install -U iai-pme). The transcript sweeper is now layout-agnostic — it discovers Cowork/local-agent sessions on both the newer local_<uuid>/.claude layout and the legacy agent/... one, and does a one-time backfill of the transcripts it had been missing. Thanks for the precise diagnosis, @mbusch-regis.
Confirming 3.2.0 fixes this — discovery now finds everything. One small concurrency bug turned up while verifying, worth a separate look.
The backfill run threw 49 tracebacks, all identical:
transcript sweep failed for .../local_0120ab62-.../.claude/projects/.../07f088e1-....jsonl
Traceback (most recent call last):
File ".../iai_mcp/transcript_sweep.py", line 331, in sweep_once
_write_sweep_state(
File ".../iai_mcp/transcript_sweep.py", line 215, in _write_sweep_state
os.replace(tmp_path, path)
FileNotFoundError: [Errno 2] No such file or directory:
'~/.iai-mcp/.capture-state/07f088e1-....transcript-sweep.tmp'
-> '~/.iai-mcp/.capture-state/07f088e1-....transcript-sweep'
Cause is the tmp filename in _write_sweep_state:
tmp_path = path.with_name(path.name + ".tmp")
No pid or random suffix, so two sweeps running at once on the same session id write and rename the same path. One wins the rename, the other's os.replace finds nothing.
Easy to trigger, and the docs point straight at it: cowork install fires the agent's RunAtLoad, and the natural next thing to do is run transcript-sweep run --allow-live-home to see the result immediately. I did exactly that, back to back, and got 49 collisions out of 145 files.
Nothing was lost. sweep_once stages the spool, counts events, appends the receipt and increments sessions_staged before it ever calls _write_sweep_state, so the content was already written when the exception fired — which is also why the summary overshoots: 122 staged + 49 failed > 145 seen. The run before/after pair:
{"files_seen": 145, "sessions_staged": 122, "lines_staged": 8156, "files_failed": 49}
{"files_seen": 145, "sessions_staged": 0, "lines_staged": 0, "files_failed": 0}
Store went from 207 records to 838, retrieval reaches back to March with original timestamps intact, and .capture-state/ ended up with all 145 state files and no orphaned .tmp. So this is noise rather than data loss, but it's alarming noise on a first run, and files_failed: 49 reads like a real failure until you trace it.
Suggested fix, matching what the hook scripts already do for their offset files:
tmp_path = path.with_name(f"{path.name}.tmp{os.getpid()}")
An flock on the sweep, or a guard against concurrent runs, would also work — but the pid suffix is the one-liner.
Thanks for confirming — and great catch on the concurrency race. It's already fixed for v3.2.1: _write_sweep_state now writes to a unique per-process temp file (pid + random suffix, kept digits-only so the existing stale-.tmp cleanup still matches it), so two sweeps on the same session no longer collide on the rename. As you noted, nothing was ever lost — content is staged before the state write, so the files_failed count was noise rather than data loss. No workaround needed; it ships in v3.2.1.