Skip to content

fix(runner): Preserve isolated verification artifacts - #2

Merged
JustinJLeopard merged 2 commits into
mainfrom
justinjleopard/fix/runner-artifact-lifecycle
Aug 10, 2026
Merged

fix(runner): Preserve isolated verification artifacts#2
JustinJLeopard merged 2 commits into
mainfrom
justinjleopard/fix/runner-artifact-lifecycle

Conversation

@JustinJLeopard

Copy link
Copy Markdown
Owner

Summary

  • Run final checks with the same sanitized PATH as action steps.
  • Preserve keep_worktree artifacts and clean allocated roots after provisioning failures.
  • Cover host-PATH independence, two isolated greeting replays, and copy-failure cleanup.

Verification

  • PYTHONDONTWRITEBYTECODE=1 /usr/bin/python3 -m pytest -q -p no:cacheprovider (53 passed)
  • Direct retained-worktree probe after run() returns

Run final checks with the same sanitized PATH as action steps and retain worktrees requested for evidence. Clean provisioned temp roots if setup fails, so failed allocation leaves no residual state.

Co-Authored-By: Codex <noreply@openai.com>
Copilot AI lite review requested due to automatic review settings August 10, 2026 11:40
Match the repository formatter so the isolated replay regression can pass the hosted CI format gate.

Co-Authored-By: Codex <noreply@openai.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2bdc1bc5b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread safe_mini/worktree.py
if self._tempdir is not None:
self._tempdir.cleanup()
if self._tempdir.exists():
shutil.rmtree(self._tempdir)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore permission-tolerant worktree cleanup

When an agent creates a directory without read/execute permissions (for example, mkdir locked && chmod 000 locked), the new plain shutil.rmtree raises PermissionError for non-root users. Because cleanup runs in the runner's finally block, this masks an otherwise valid RunResult and leaves the worktree behind; the previous TemporaryDirectory.cleanup() repaired permissions while deleting. Use similarly permission-tolerant removal for agent-controlled trees.

Useful? React with 👍 / 👎.

Comment thread safe_mini/worktree.py
Comment on lines +36 to +38
except Exception:
self.cleanup()
raise

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clean the allocated directory on interrupted provisioning

If copying is interrupted by KeyboardInterrupt or another BaseException, this handler is skipped and the raw mkdtemp directory has no finalizer, so a potentially large partial worktree remains permanently in the temp root. The former TemporaryDirectory object supplied that fallback cleanup; ensure the new allocation is also removed while propagating non-Exception interruptions.

Useful? React with 👍 / 👎.

@JustinJLeopard
JustinJLeopard merged commit 95bea4d into main Aug 10, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens worktree isolation and artifact handling in the runner by ensuring verification runs under the same sanitized environment as action steps, and by retaining/cleaning worktree directories more predictably across success and failure paths.

Changes:

  • Run final_tests_pass() with a fully sanitized PATH (matching executor behavior).
  • Change worktree provisioning to use an explicit mkdtemp() root so keep_worktree runs don’t get GC-cleaned, while still cleaning up on provisioning failures.
  • Add integration/unit tests covering host-PATH independence, isolated worktree replays, and cleanup on copy failures.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/test_worktree.py Adds a regression test ensuring failed provisioning cleans up the allocated temp root.
tests/test_runner_integration.py Adds integration coverage for host-PATH independence and repeated runs creating distinct kept worktrees without mutating the source repo.
safe_mini/worktree.py Switches from TemporaryDirectory to mkdtemp() plus explicit cleanup to preserve kept worktrees and cleanup on failures.
safe_mini/observation/policies.py Ensures final verification runs with SANITIZED_PATH instead of inheriting host PATH.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread safe_mini/worktree.py
Comment on lines 49 to 52
if self._tempdir is not None:
self._tempdir.cleanup()
if self._tempdir.exists():
shutil.rmtree(self._tempdir)
self._tempdir = None
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.

3 participants