Skip to content

Fix #281: recreate stale default workdirs after reboot when only logs remain#282

Merged
wwind123 merged 1 commit into
mainfrom
fix/281-recreate-stale-default-workdirs
Jun 8, 2026
Merged

Fix #281: recreate stale default workdirs after reboot when only logs remain#282
wwind123 merged 1 commit into
mainfrom
fix/281-recreate-stale-default-workdirs

Conversation

@wwind123

@wwind123 wwind123 commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #281

After a machine reboot, a tool-owned default agent workdir under /tmp/coding-review-agent-loop/... can survive as a bare directory containing only tool-created artifacts (e.g., .agent-loop-logs/) with no git checkout. Previously the tool aborted with:

Default claude workdir exists but is not a git checkout: ...
Remove it or pass an explicit agent directory

This PR adds auto-recreation for that stale scenario:

  • _is_stale_default_workdir(path) — detects a dir that exists, has no .git/, and whose contents are a non-empty subset of known tool artifact names (.agent-loop-logs, .agent-loop, .agent-loop-responses). Empty dirs are intentionally excluded (no artifacts → could be any empty dir).
  • ensure_temp_checkout() — calls shutil.rmtree() on stale default-owned workdirs before the existing clone-if-missing branch, so the normal gh repo clone + validation flow runs fresh.
  • Explicit agent dirs (--claude-dir / --codex-dir / --gemini-dir) are unchanged — they still fail clearly when not a git checkout.
  • Existing dirty-checkout behavior for valid default-owned git repos is preserved.

Test plan

  • test_stale_default_workdir_only_logs_is_recreated — default auto workdir with only .agent-loop-logs/ is removed and fresh clone is triggered; log message confirms detection.
  • test_stale_default_workdir_with_unknown_files_still_fails — dir with .agent-loop-logs/ plus an unknown file is not treated as stale; error is raised.
  • test_explicit_dir_not_git_checkout_is_not_recreated — explicit (non-auto) dir with only logs still aborts with a clear error; no clone attempted.
  • All 716 existing tests continue to pass.

🤖 Generated with Claude Code

… remain

After a reboot, a tool-owned default workdir can survive as a bare
directory containing only .agent-loop-logs (or other tool-owned
artifacts) without a git checkout. The previous code aborted with
"exists but is not a git checkout".

Add _is_stale_default_workdir() to detect this condition (dir exists,
no .git/, contents are a non-empty subset of known tool artifact names),
and in ensure_temp_checkout() remove and re-clone the workdir when
this condition is met for default-owned dirs. Explicit agent dirs
(--claude-dir / --codex-dir / --gemini-dir) still fail clearly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@wwind123

wwind123 commented Jun 8, 2026

Copy link
Copy Markdown
Owner Author

Opened PR #282 to fix this.

Root cause: ensure_temp_checkout in config.py called _sync_base_branch, which raised an error whenever a default-owned workdir existed but lacked a git checkout — even if it only contained tool-created log artifacts leftover from before a reboot.

Fix: Added _is_stale_default_workdir(path) which returns True when the directory has no .git/, is non-empty, and all contents are known tool artifact names (.agent-loop-logs, .agent-loop, .agent-loop-responses). In ensure_temp_checkout, this is checked before the existing clone-if-missing branch; if stale, the directory is removed with shutil.rmtree so the normal gh repo clone + validation flow runs fresh. Explicit agent dirs (--claude-dir / --codex-dir / --gemini-dir) are unaffected.

Three new tests cover: stale-with-only-logs → re-cloned; stale-with-unknown-files → still fails; explicit-dir-with-logs → still fails (no clone attempted). All 716 tests pass.

-- Anthropic Claude

@wwind123

wwind123 commented Jun 8, 2026

Copy link
Copy Markdown
Owner Author

Review verdict: Approved

Approved; the stale default workdir recreation is limited to default-owned paths with only known tool artifacts, explicit dirs still fail, and regression coverage is in place.

-- OpenAI Codex

@wwind123

wwind123 commented Jun 8, 2026

Copy link
Copy Markdown
Owner Author

Review verdict: Approved

The PR successfully addresses the issue of stale default workdirs surviving reboots. It introduces a safe mechanism to identify and recreate default-owned agent workdirs that contain only tool-generated artifacts (logs, memory, responses) but are missing a .git directory. The implementation correctly distinguishes between default and explicit workdirs and includes comprehensive tests covering success, safety, and explicit-directory cases. All tests pass.

-- Google Gemini

@wwind123 wwind123 merged commit fe2239c into main Jun 8, 2026
1 check passed
@wwind123 wwind123 deleted the fix/281-recreate-stale-default-workdirs branch June 8, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recreate stale default temp workdirs after reboot when only logs remain

1 participant