Skip to content

Keep all Pi session logs for Patchmill run-once #92

Description

@rochecompaan

Problem

Patchmill should preserve all Pi session logs for run-once executions. Today runPiPrompt creates the Pi --session-dir inside a temporary prompt directory (/tmp/agent-issue-prompt-*) and removes that directory in finally, which deletes the parent Pi session JSONL and can also break/debug-obscure async subagent runs.

This made issue #88 hard to debug and left Patchmill with only partial run metadata.

Evidence from issue #88 run-once

Patchmill run log:

  • .patchmill/runs/issue-88/run-2026-07-16T06-56-46-497Z.jsonl

Observed sequence:

  • The implementation Pi session dispatched a worker subagent with async: true.
  • Parent Pi stdout was only: Implementation worker started for issue #88 and task todos were created.
  • Patchmill blocked because parent Pi did not emit final JSON: Pi output did not include a supported final JSON status.
  • The async subagent then failed with:
ENOENT: no such file or directory, open '/tmp/agent-issue-prompt-vuFOip/sessions/2026-07-16T07-20-42-827Z_019f69cc-944b-7343-a59d-9f9da54b9b77.jsonl'

Surviving subagent metadata exists under:

  • /tmp/pi-subagents-uid-1000/async-subagent-runs/0732c704-7f3b-40d2-adf6-c85bd7b9d496/

But the referenced parent/session directory under /tmp/agent-issue-prompt-vuFOip/sessions/... was already deleted.

Likely code path:

  • src/cli/commands/run-once/pi.ts creates dir = mkdtemp(join(tmpdir(), "agent-issue-prompt-")).
  • sessionDir is set to join(dir, "sessions") when observing/streaming.
  • finally removes dir with rm(dir, { recursive: true, force: true }).

Desired behavior

Patchmill should keep Pi session logs as first-class run artifacts, not temp files.

Acceptance criteria

  • Store Pi --session-dir under a durable Patchmill run artifact path, e.g. .patchmill/runs/issue-<n>/<run-id>/pi-sessions/ or equivalent.
  • Preserve parent Pi session JSONL files for every run-once stage: artifact extraction, planning, development environment, implementation, review/fix stages.
  • Preserve nested/async subagent session JSONL paths, or copy/index them into the run artifact directory when the subagent completes.
  • Include relevant session log paths in the run log and blocked/final result output.
  • Do not delete session logs during prompt-temp cleanup.
  • Add regression coverage for run-once session persistence, including an async subagent/session-file scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions