Background sync inherits the session's working directory and keeps worktrees from being deleted on Windows

Open Beginner friendly
#219 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript

Research direction

Start by reading sync-cli.js and tracing the detached background spawn and summarizer subprocess creation described in the issue. Check how each subprocess receives its working directory and whether the sync already uses absolute paths for transcripts. Reproduce on Windows by ending a session in a temporary worktree and attempting to delete it; completion means the detached sync and summarizer use a neutral working directory and no longer keep the worktree open.

Written by the indexing model from the issue text.

Description

Version: 1.6.0, Windows 11, Claude Code started by an orchestrator that gives each agent its own git worktree.

What happens: the SessionStart hook runs episodic-memory sync --background. sync-cli.js re-spawns itself detached (spawn(process.execPath, [...], { detached: true, windowsHide: true, stdio: [...] })) without a cwd option, so the background sync inherits the session's working directory, and the summarizer's claude subprocess inherits it in turn. On Windows a process's current directory is an open handle, so that directory cannot be deleted while the sync runs (several minutes with summaries). An orchestrator that removes a worker's worktree right after the worker finishes gets "The process cannot access the file because it is being used by another process" (git unregisters the worktree, but the empty folder stays). The parent session is already gone, so nothing points at the orphaned node ... dist/sync-cli.js holding the folder.

Reproduce: start a session in a throwaway folder, end it, and try to delete the folder while node ... dist/sync-cli.js is still running; it succeeds as soon as that process (and its claude child) exits or is killed.

Suggested fix: give the detached background spawn, and the summarizer subprocesses, a neutral working directory, e.g. cwd: os.homedir() (or the index/data directory). Nothing in the sync depends on the session's directory as far as I can tell, since it reads transcripts by absolute path.

Workaround today: EPISODIC_MEMORY_DISABLE_AUTO_SYNC=1 for the agent sessions, at the cost of no auto-sync there.

Possibly related: #189 (summarizer and removed worktree cwd).

Dominant language
TypeScript
Stars
511
Forks
154
Avg merge
14d 20h
Merged PRs (30d)
6

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from obra/episodic-memory

All issues in obra/episodic-memory

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.