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.
Problem
Patchmill should preserve all Pi session logs for run-once executions. Today
runPiPromptcreates the Pi--session-dirinside a temporary prompt directory (/tmp/agent-issue-prompt-*) and removes that directory infinally, 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.jsonlObserved sequence:
workersubagent withasync: true.Implementation worker started for issue #88 and task todos were created.Pi output did not include a supported final JSON status.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.tscreatesdir = mkdtemp(join(tmpdir(), "agent-issue-prompt-")).sessionDiris set tojoin(dir, "sessions")when observing/streaming.finallyremovesdirwithrm(dir, { recursive: true, force: true }).Desired behavior
Patchmill should keep Pi session logs as first-class run artifacts, not temp files.
Acceptance criteria
--session-dirunder a durable Patchmill run artifact path, e.g..patchmill/runs/issue-<n>/<run-id>/pi-sessions/or equivalent.