Skip to content

Add check_pr branch state for PR/thread restore#52

Closed
pokryfka wants to merge 1 commit intomainfrom
check_pr
Closed

Add check_pr branch state for PR/thread restore#52
pokryfka wants to merge 1 commit intomainfrom
check_pr

Conversation

@pokryfka
Copy link
Owner

@pokryfka pokryfka commented Mar 1, 2026

Entire-Checkpoint: c4dfc620f91d

Summary by CodeRabbit

  • New Features
    • Added pull request inspection capability, enabling the agent to fetch and analyze open PRs for the current branch.
    • Implemented checkpoint state restoration from PR data, allowing recovery of previous work via thread identifiers embedded in PR bodies.
    • Added PR review and comment retrieval to enhance decision-making with reviewer feedback.

Entire-Checkpoint: c4dfc620f91d
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

This change introduces PR inspection functionality to the agent graph. When a branch has an associated pull request, the agent now routes to a new check_pr node that fetches PR metadata, reviews, and attempts to restore prior checkpoint state from embedded thread IDs, enriching the agent's state before proceeding to setup.

Changes

Cohort / File(s) Summary
Graph & Routing
src/agent/graph.py
Added check_pr node and conditional routing via route_after_clone() to direct flow based on should_check_pr flag. Extended non-code file extensions to include .json.
State Management
src/agent/state.py, src/agent/loop.py
Expanded AgentState TypedDict with PR metadata fields (pr_url, pr_number, pr_title, pr_body, pr_review_status, pr_review_comments, restored_thread_id, checkpoint_restore_ok, restored_checkpoint_state) and checkpoint handling fields (checkpointer, should_check_pr). Added checkpointer to initial state payload in graph invocation.
PR Inspection Nodes
src/agent/nodes.py
Implemented check_pr() node with supporting helpers: _parse_thread_id_from_text(), _extract_checkpoint_values(), _restore_checkpoint_state(), _summarize_review_comments(), and _derive_review_status(). Extended clone_and_branch() to propagate should_check_pr and checkpointer in returned config.
Git Operations
src/git_ops/repo.py
Added three new public methods: fetch_open_pr_for_branch(), fetch_pr_reviews(), and fetch_pr_review_comments() for retrieving PR data via GitHub CLI.

Sequence Diagram(s)

sequenceDiagram
    participant Agent as Agent Graph
    participant Git as Git Operations
    participant GH as GitHub API
    participant CP as Checkpoint Store

    Agent->>Git: fetch_open_pr_for_branch(branch)
    Git->>GH: gh pr list
    GH-->>Git: PR metadata
    Git-->>Agent: PR data

    Agent->>Agent: _parse_thread_id_from_text(pr_body)
    Agent-->>Agent: extracted thread_id

    Agent->>CP: _restore_checkpoint_state(thread_id)
    CP-->>Agent: restored checkpoint values

    Agent->>Git: fetch_pr_reviews(pr_number)
    Git->>GH: gh api reviews
    GH-->>Git: reviews list
    Git-->>Agent: reviews

    Agent->>Git: fetch_pr_review_comments(pr_number)
    Git->>GH: gh api comments
    GH-->>Git: comments list
    Git-->>Agent: comments

    Agent->>Agent: _summarize_review_comments(comments)
    Agent->>Agent: _derive_review_status(pr, reviews)
    Agent-->>Agent: enriched state with PR data
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A PR appears upon the branch so fine, 🌿
The agent peeks to see what's in the line,
Thread IDs whisper secrets, checkpoints dance,
Reviews are gathered for the flow's advance,
State restored, enriched, the agent's stance! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add check_pr branch state for PR/thread restore' directly describes the main changes: introducing a new check_pr function and state additions to enable PR-based thread restoration via checkpoint recovery.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch check_pr

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/agent/state.py (1)

33-34: Consider marking should_check_pr as UntrackedValue for consistency.

The checkpointer field is correctly marked as UntrackedValue since it shouldn't be persisted. The should_check_pr field is derived from the immutable branch input and is only used for initial routing, so it could also be marked as Annotated[bool, UntrackedValue] for consistency with other derived control-flow values. However, this is a minor concern since the current behavior won't cause issues.

♻️ Optional: Mark as UntrackedValue
     checkpointer: Annotated[Any, UntrackedValue]
-    should_check_pr: bool
+    should_check_pr: Annotated[bool, UntrackedValue]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/agent/state.py` around lines 33 - 34, The field should_check_pr is a
derived control-flow flag and should be marked as non-persistent like
checkpointer; update the dataclass/type annotation for should_check_pr from bool
to Annotated[bool, UntrackedValue] so it is treated as
untracked/persist-excluded (refer to the existing checkpointer: Annotated[Any,
UntrackedValue] annotation and the derived branch input used to compute
should_check_pr to locate where to change the type).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/agent/state.py`:
- Around line 33-34: The field should_check_pr is a derived control-flow flag
and should be marked as non-persistent like checkpointer; update the
dataclass/type annotation for should_check_pr from bool to Annotated[bool,
UntrackedValue] so it is treated as untracked/persist-excluded (refer to the
existing checkpointer: Annotated[Any, UntrackedValue] annotation and the derived
branch input used to compute should_check_pr to locate where to change the
type).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f5cd42 and b411063.

📒 Files selected for processing (5)
  • src/agent/graph.py
  • src/agent/loop.py
  • src/agent/nodes.py
  • src/agent/state.py
  • src/git_ops/repo.py

@pokryfka pokryfka closed this Mar 1, 2026
@pokryfka pokryfka deleted the check_pr branch March 1, 2026 13:59
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.

1 participant