Skip to content

artifact commands recreate a session folder that gc removed #198

Closed

Description

@ThomasK33

An artifact command that runs while gc removes its session brings the session folder back, holding only artifacts/. That folder has no session.json, so list --all hides it and every later gc skips it with "session manifest is missing". The folder stays until someone removes it by hand.

Cause

ensureArtifactsDir in src/storage/artifactPaths.ts runs mkdir(<session folder>/artifacts, { recursive: true }). snapshot, screenshot and record export call it before they write. When gc removed the session folder after the command read the session, the recursive mkdir creates the session folder again.

This is the same fault as #196 in a different writer. #196 fixes the manifest write only. Its PR keeps the mkdir in writeTextFileAtomic, because the artifact writes run after ensureArtifactsDir and the Home Registry needs it.

Repro

Seen on the #196 fix branch (fix/manifest-no-recreate), in an isolated verify-agent-tty run:

  1. Create a session with -- sh -c 'echo hello; sleep 0.2' and wait until it reads exited.
  2. Run snapshot <id> --json with its first events.jsonl read held: REPLAY_HOLD='snapshot:readFile:/events.jsonl:1:3000' NODE_OPTIONS="--import $PWD/.agents/skills/verify-session-lifecycle/scripts/replay-hold.mjs".
  3. Run gc --json during the hold. It removes the session folder.
  4. After the hold, snapshot exits 0 and the folder is back with artifacts/snapshot-1-structured.json and artifacts/manifest.json only. list --all shows no session. A second gc skips it: "session manifest is missing".

Direction

ensureArtifactsDir must not create the session folder. Create only the artifacts folder inside an existing session folder (a non-recursive mkdir that accepts EEXIST), and report a missing session folder as SESSION_NOT_FOUND. The lifecycle model in .agents/skills/verify-session-lifecycle leaves artifact commands out, so add them there or state the gap.

Refs #196


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageMaintainer needs to evaluate this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions