Skip to content

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

@nizar-lahlali

Description

@nizar-lahlali

Summary

Add an optional self-review phase to the agent pipeline that runs between agent execution and post-hooks. The LLM critiques its own cumulative diff before the PR is created, improving first-pass PR quality by catching bugs, style issues, edge cases, and test gaps that would otherwise go straight to human review.

Motivation

Post-hooks in pipeline.py run deterministic checks (build/lint) after the agent finishes, but the LLM never sees its own cumulative diff before the PR is created. Adding a self-review phase where the model critiques its own diff and iterates on fixes improves first-pass PR quality.

Acceptance Criteria

  • New agent/src/self_review.py module with run_self_review() orchestration function
  • New agent/src/prompts/self_review.py with focused review prompt template
  • TaskConfig extended with self_review_enabled (default False) and self_review_max_turns (default 5) fields
  • Fields threaded through build_config(), get_config(), server.py, and pipeline.py
  • Self-review phase inserted between cancel-check and post-hooks in pipeline
  • Skip conditions: disabled, pr_review task type, no diff, no remaining turns/budget
  • Fail-open: self-review errors do not block PR creation
  • Uses remaining turns from original max_turns allocation (capped at self_review_max_turns)
  • Progress milestones: self_review_started, self_review_complete
  • Unit tests covering all skip conditions, diff helpers, and happy path
  • Feature is opt-in (off by default) — existing tests pass without modification

Design

See the approved plan in the implementation PR for full design details including:

  • Second run_agent() call with fresh review context
  • Diff truncation at hunk boundary (60k char cap)
  • Budget/turn computation from remaining allocation
  • Fail-open error handling

Task Type

new_task

Metadata

Metadata

Assignees

Labels

approvedWhen an issue has been approved and ready

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions