opencove icon indicating copy to clipboard operation
opencove copied to clipboard

Claude Code resume binding: newest-mtime resolver binds agents to other sessions' transcripts (incl. parent dirs) and marks them verified

Open domijin opened this issue 1 month ago • 1 comments

Summary

For Claude Code agents, OpenCove finds a node's resume session by taking the newest *.jsonl transcript under the node's directory or any parent directory. It never checks that the transcript belongs to that node. The guess is then saved as resumeSessionIdVerified: true, and every agent that isn't stopped is revived on the next launch. So one restart can make many nodes resume someone else's conversation, several nodes can resume the same conversation at once, and nodes can be bound to session IDs whose transcript doesn't exist.

Observed on 0.2.0-nightly.20260509.1 (macOS, Claude Code 2.1.29x). The same code is unchanged on main (9126a04) and in v0.3.3.

The code path

  1. Newest-file guess, no ownership check. findLatestClaudeResumeSessionIdInProjectDirectoryGroup keeps every *.jsonl with mtimeMs >= startedAtMs - 6000, takes the newest, and uses its filename as the session ID. It never opens the file. It doesn't compare the transcript's recorded cwd or first prompt, doesn't skip IDs already bound to another node, and doesn't treat several candidates as ambiguous. (The Codex path does validate both ID and cwd, and selectNearestAgentSessionId already returns null on a tie. The Claude path uses neither.)
  2. Parent directories are searched. resolveClaudeWorkspacePathCandidates checks the cwd and then every parent up to /. If nothing qualifies in the node's own directory, any recently written transcript of an unrelated session in a parent directory wins.
  3. Unset means verified. isResumeSessionBindingVerified returns true for claude-code when resumeSessionIdVerified is undefined, and normalizeResumeSessionBinding saves that as true. Once guessed, a wrong ID is never re-checked.
  4. Everything not stopped is revived. isRecoverableAgentWindowStatus is status !== 'stopped'. So exited and failed agents are relaunched with claude --resume <guessed id> on every app start, and quitting the PTY doesn't stop the node.

What it looked like

These are from one workspace whose Claude sessions run in per-session git worktrees under the workspace directory, a common way to isolate parallel agents. Those transcripts live in a child directory, which the parent-only search can't see.

  • After one app restart, 13 of 15 revived agent nodes were bound to the wrong conversation. Each node's real transcript still existed, and was confirmed by matching its first user message to the node's prompt and its start time to the node's start (within 4–13 s).
  • 3 nodes resumed the same transcript at the same time: three live claude --resume <same-id> processes appending to one .jsonl.
  • 6 nodes were bound to an ID with no transcript on disk.
  • A node created today was bound and marked verified, seconds after launch, to an unrelated, actively written session in a parent directory (a separate Claude Code session running in that directory). Restarting OpenCove would have made that node resume the other session.
  • The PTY for an agent that fails at launch is recorded as failed with no last_error, which makes this hard to diagnose.

Steps to reproduce

These are derived from the code path above and match what we saw; I haven't run them as a standalone test.

  1. In a terminal, cd ~/oc-repro && claude, send one message, and keep chatting. Its transcript is written under the project folder for ~/oc-repro.
  2. In OpenCove, create a Claude Code agent whose directory is ~/oc-repro/app, where app has no Claude transcripts of its own within the 6 s window. That happens when the session runs in a subdirectory of app or hasn't written its first transcript yet.
  3. Read the node's agent_json: resumeSessionId is the terminal session's ID, with resumeSessionIdVerified: true.
  4. Quit and reopen OpenCove. The node runs claude --resume <terminal session id> and joins that conversation.

Variant (shared directory): two agents in the same directory, plus any other Claude session in that directory. After a restart, every unverified node resolves to whichever transcript was written last.

Expected

An agent resumes its own conversation or none. A guessed binding is never marked verified, and two nodes never share a session ID.

Suggested fixes (roughly in order of leverage)

  1. Don't guess at all. Generate a UUID when launching a new Claude Code agent, pass it with claude --session-id <uuid> (the CLI supports this), and store it as the verified binding.
  2. If discovery stays:
    • Search the node's cwd only, not parent directories.
    • Open the candidate and require its recorded cwd to match, as the Codex path does.
    • Exclude IDs already bound to another node.
    • Return null when more than one candidate qualifies, as selectNearestAgentSessionId already does.
  3. Treat an undefined resumeSessionIdVerified as unverified, and only stamp true after validation.
  4. When an agent launch fails, set last_error, and consider not reviving a node whose last launch failed.

Environment

  • OpenCove 0.2.0-nightly.20260509.1 (code paths re-checked on main@9126a04 and v0.3.3)
  • macOS 26 (Darwin 25.3), Apple Silicon
  • Claude Code 2.1.292–2.1.296

domijin avatar Oct 10 '26 02:10 domijin

@domijin Could you update to the latest stable release first and check whether Claude agents still resume the wrong conversation after restarting OpenCove? Please also share the exact OpenCove version you test.

DeadWaveWave avatar Oct 10 '26 06:10 DeadWaveWave