Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 0 additions & 128 deletions orchestrator/routes/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -8375,134 +8375,6 @@ def _commit_statefiles_to_worktree(
return True


def _cleanup_agent_outputs_for_pr(
worktree_path: Path,
pipeline_id: str,
) -> None:
"""Remove ``.egg-state/agent-outputs/`` from the PR branch at PR-phase entry.

Files under ``.egg-state/agent-outputs/`` are coder→tester handoff
artifacts (e.g. ``coder-test-changes.patch``) that the tester consumes
and re-emits as real source/test files. They are ephemeral: once the
implement phase closes, nothing on the PR branch should reference them.

Leaving them on the branch causes two problems:

1. Concurrent pipelines can write different contents to the same path
(e.g. two coder runs producing divergent patches), making the
orchestrator's PR-phase worktree and ``origin/<branch>`` diverge in
a way that merge/rebase reconcile cannot auto-resolve (see #1731).
2. The PR itself then ships throwaway artifacts that add noise to
reviewers' diffs.

This helper runs once at PR-phase entry, unstages/removes any tracked
agent-outputs, and commits the cleanup. If nothing is tracked, it
no-ops. All subprocess errors are swallowed with a warning — cleanup
is best-effort.
"""
state_dir = worktree_path / ".egg-state" / "agent-outputs"
logger.info(
"_cleanup_agent_outputs_for_pr: entering",
worktree_path=str(worktree_path),
pipeline_id=pipeline_id,
agent_outputs_exists=state_dir.exists(),
)

git_base = [
"git",
"-c",
"core.hooksPath=/dev/null",
"-c",
f"safe.directory={worktree_path}",
"-C",
str(worktree_path),
]

try:
# Remove from both the index and the working tree. ``--ignore-unmatch``
# makes this a no-op when nothing is tracked under that path.
# ``-r`` recurses; ``-f`` forces removal even if files were modified.
subprocess.run(
[
*git_base,
"rm",
"-rf",
"--ignore-unmatch",
"--",
".egg-state/agent-outputs",
],
capture_output=True,
text=True,
check=True,
timeout=30,
)
except subprocess.CalledProcessError as rm_err:
logger.warning(
"_cleanup_agent_outputs_for_pr: git rm failed — continuing",
pipeline_id=pipeline_id,
stderr=rm_err.stderr,
)
return
except subprocess.TimeoutExpired:
logger.warning(
"_cleanup_agent_outputs_for_pr: git rm timed out — continuing",
pipeline_id=pipeline_id,
)
return

# Only commit when the index actually changed (idempotent on re-runs).
try:
diff_result = subprocess.run(
[*git_base, "diff", "--cached", "--quiet"],
capture_output=True,
text=True,
check=False,
timeout=30,
)
except subprocess.TimeoutExpired:
logger.warning(
"_cleanup_agent_outputs_for_pr: git diff --cached timed out — continuing",
pipeline_id=pipeline_id,
)
return
if diff_result.returncode == 0:
logger.info(
"_cleanup_agent_outputs_for_pr: nothing tracked — skipping commit",
pipeline_id=pipeline_id,
)
return

try:
subprocess.run(
[
*git_base,
"commit",
"--no-verify",
"-m",
"Remove ephemeral agent-output handoff artifacts (#1731)",
],
capture_output=True,
text=True,
check=True,
timeout=30,
)
logger.info(
"_cleanup_agent_outputs_for_pr: commit succeeded",
pipeline_id=pipeline_id,
)
except subprocess.CalledProcessError as commit_err:
logger.warning(
"_cleanup_agent_outputs_for_pr: commit failed — continuing",
pipeline_id=pipeline_id,
stderr=commit_err.stderr,
)
except subprocess.TimeoutExpired:
logger.warning(
"_cleanup_agent_outputs_for_pr: commit timed out — continuing",
pipeline_id=pipeline_id,
)


def _ensure_statefiles_on_branch(
worktree_repo_path: Path,
pipeline: Pipeline,
Expand Down
121 changes: 0 additions & 121 deletions orchestrator/tests/test_cleanup_agent_outputs_for_pr.py

This file was deleted.

Loading