Skip to content

feat(agent): add in-pipeline pre-PR self-review phase#263

Open
nizar-lahlali wants to merge 2 commits into
mainfrom
feat/262-pre-pr-self-review
Open

feat(agent): add in-pipeline pre-PR self-review phase#263
nizar-lahlali wants to merge 2 commits into
mainfrom
feat/262-pre-pr-self-review

Conversation

@nizar-lahlali
Copy link
Copy Markdown
Contributor

@nizar-lahlali nizar-lahlali commented Jun 4, 2026

Summary

  • Adds an optional self-review pipeline phase where the LLM critiques its own cumulative diff before the PR is created
  • New self_review.py orchestration module with run_self_review() that generates the diff, invokes run_agent() a second time with a review-focused prompt, and accumulates turns/cost
  • New prompts/self_review.py with a focused review prompt template (correctness, bugs, security, style, test gaps checklist)
  • TaskConfig extended with self_review_enabled (default False) and self_review_max_turns (default 5)
  • Fields threaded through build_config(), get_config(), server.py _extract_invocation_params(), and pipeline.py run_task()
  • NEW: Self-review summary posted as a PR comment — the review agent writes .self-review-summary.md with structured findings, the pipeline posts it via gh pr comment, then deletes the file so it never appears in the diff

Design decisions:

  • Fail-open: self-review errors never block PR creation
  • Uses remaining turns/budget from original max_turns allocation (capped at self_review_max_turns)
  • Second run_agent() call gives the model fresh context and a clean review perspective
  • Skipped for pr_review (read-only), empty diff, no remaining turns/budget
  • Feature is opt-in (disabled by default) — no behavior change for existing users
  • Summary file approach (vs. parsing trajectory): deterministic, decoupled from SDK internals
  • Comment posted after PR creation (natural ordering — PR must exist before commenting)

Closes #262

Test plan

  • All 34 unit tests pass (tests/test_self_review.py) — includes 13 new tests for summary reader and PR comment posting
  • All existing tests pass (no regressions)
  • Ruff lint passes on all new/modified files
  • Manual validation: set SELF_REVIEW_ENABLED=true in local batch mode to verify the phase executes and summary is posted
  • Integration: deploy and submit a task with self_review_enabled: true in the orchestrator payload

Adds an optional self-review phase between agent execution and post-hooks
where the LLM critiques its own cumulative diff before the PR is created.
This improves first-pass PR quality by catching bugs, style issues, and
test gaps before human review.

- New self_review.py orchestration module with run_self_review()
- New prompts/self_review.py with focused review prompt template
- TaskConfig extended with self_review_enabled and self_review_max_turns
- Fields threaded through build_config, get_config, server, pipeline
- Fail-open: self-review errors never block PR creation
- Uses remaining turns/budget from original allocation (capped)
- Feature is opt-in (disabled by default)
@nizar-lahlali nizar-lahlali requested a review from a team as a code owner June 4, 2026 17:39
After the self-review phase completes, the agent writes a structured
summary of findings to `.self-review-summary.md`. The pipeline reads
this file, posts it as a PR comment via `gh pr comment`, then deletes
it so it never appears in the PR diff. Fail-open: if the file is
missing or the comment fails to post, the pipeline continues normally.
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.

feat(agent): add in-pipeline pre-PR self-review phase

1 participant