plateprocess.dev · PLATE release v0.12.0

Babysit Base Branch Out Of Sync Merge Resolution

Research: Babysit Base Branch Out-of-Sync Merge Resolution

Issue: #197 - Babysit agent does not handle out-of-sync base branch Epic: #112 - CLI-driven PR Feedback Babysitting Date: 2026-05-30 Status: Implemented

Problem Statement

The plate pr babysit feature (CLI and MCP tool plate_pr_babysit) monitors PRs for unresolved third-party agent feedback but does not detect or handle situations where the PR's feature branch falls behind or conflicts with the base branch.

This breaks the babysitting loop on active repositories where the base branch moves frequently, requiring manual intervention to update branches before the babysitter can continue addressing review feedback.

Research Questions

  1. How can we detect when a PR branch is out of sync with its base branch?
  2. What is the appropriate default action for handling out-of-sync branches?
  3. How should configurability be exposed to support different strategies?
  4. What are the implementation constraints given existing architecture?

Detection Approach

GitHub PR Merge State

GitHub's GraphQL API provides mergeStateStatus on the PullRequest type with these relevant values:

Decision: Use mergeStateStatus as the primary detection signal. Consider BEHIND, DIRTY, and CONFLICTING as "out of sync" states requiring intervention.

Implementation Location

The detection logic belongs in the babysit core (pr_babysit.py) alongside review thread detection, since both are PR health checks performed during babysitting.

Decision: Create a _detect_base_branch_out_of_sync() helper function and extend the existing GraphQL query to fetch mergeStateStatus, baseRefName, and headRefName.

Default Action: Copilot Merge-Request Trigger

Options Considered

  1. Manual notification only: Report the state but take no action

    • Pro: Safe, no automation risk
    • Con: Requires human intervention, breaks autopilot goal
  2. Local automated rebase: Use worktree isolation to rebase locally and push

    • Pro: Fully automated, no human interaction
    • Con: Complex, potential for merge conflicts requiring human resolution, risky for CI stability
  3. Copilot merge-request trigger: Post a comment triggering GitHub Copilot's native branch update assistance

    • Pro: Leverages native GitHub/Copilot flow, auditable, reversible
    • Con: Requires Copilot to be enabled on the repository

Decision: Default to Copilot merge-request trigger (option 3) for consistency with existing babysit pattern where we post a @copilot trigger comment for actionable work.

Trigger Comment Format

Following the existing _BABYSIT_MARKER pattern, introduce _MERGE_TRIGGER_MARKER:

<!-- plate-pr-merge-trigger -->
@copilot This PR branch (`feature-branch`) is out of sync with the base branch (`main`).
Merge state: `BEHIND`

Please update this branch to resolve the merge conflict or bring it up to date with the base branch.

This matches GitHub's UI flow where users can click to request Copilot assistance with branch updates.

Deduplication

Use marker-based deduplication (similar to _has_existing_babysit_comment) to avoid posting duplicate merge triggers on subsequent babysit cycles.

Configurability

Strategy Options

Expose a branch_update_strategy parameter with three values:

  1. copilot-request (default): Post Copilot merge-request trigger comment
  2. local-rebase: Local worktree rebase (stub for future implementation)
  3. none: Detect and report only, take no action

Configuration Surface

Default: copilot-request (safe, leverages native GitHub capabilities)

Validation

Validate strategy value against the set ["copilot-request", "local-rebase", "none"] and raise ValueError for invalid values.

For local-rebase, raise NotImplementedError with a clear message until the feature is implemented.

Implementation Constraints

TDD Approach Required

Per AGENTS.md, feature work must follow TDD:

  1. Write failing tests first
  2. Implement minimal code to pass tests
  3. Refactor as needed

Backward Compatibility

The changes must not break existing babysit usage:

Data Classes

Extend BabysitReport with:

Architecture Decisions

Function Responsibilities

Error Handling

Acceptance Testing

Unit Tests

  1. Detection logic:

    • test_detect_base_branch_out_of_sync_behind()
    • test_detect_base_branch_out_of_sync_conflicting()
    • test_detect_base_branch_out_of_sync_dirty()
    • test_detect_base_branch_out_of_sync_clean()
  2. Integration:

    • test_babysit_pr_detects_out_of_sync_and_posts_copilot_trigger()
    • test_babysit_pr_respects_branch_update_strategy_none()

Manual Verification

After implementation:

  1. Test CLI: gh plate pr babysit <number> --act --branch-update-strategy copilot-request
  2. Test MCP: Invoke plate_pr_babysit with branch_update_strategy: "copilot-request"
  3. Verify trigger comment format and deduplication
  4. Check JSON output includes new fields

Documentation Impact

Files to Update

  1. AGENTS.md: Document new capability in §Third-Party Agent Feedback section
  2. CLI help: Already included via add_argument() help text
  3. MCP schema: Already included in tool description
  4. .agentic/releases/: Add per-feature change file describing implementation and verification

Implementation Summary

Implemented: 2026-05-30

Core Changes

Test Results

All 207 tests pass, including:

Default Behavior

When --act is specified and a PR is detected as out of sync:

  1. Default strategy is copilot-request
  2. Posts a @copilot trigger comment with merge context
  3. Deduplicates to avoid multiple triggers
  4. Returns merge state in BabysitReport

Configuration

# Default: copilot-request
gh plate pr babysit 123 --act

# Explicit strategy
gh plate pr babysit 123 --act --branch-update-strategy copilot-request

# Detect only, no action
gh plate pr babysit 123 --act --branch-update-strategy none

# Future: local-rebase (currently NotImplementedError)
gh plate pr babysit 123 --act --branch-update-strategy local-rebase

MCP Usage

{
  "name": "plate_pr_babysit",
  "arguments": {
    "pr_number": 123,
    "act": true,
    "branch_update_strategy": "copilot-request"
  }
}

Conclusion

The implementation successfully addresses the issue by:

  1. Detecting out-of-sync base branches via mergeStateStatus
  2. Defaulting to safe Copilot merge-request triggers
  3. Providing configurability via branch_update_strategy
  4. Following TDD approach with comprehensive test coverage
  5. Maintaining backward compatibility
  6. Supporting both CLI and MCP surfaces

The solution is conservative (leverages native GitHub capabilities), auditable (posts visible trigger comments), and reversible (comments can be deleted, strategy can be changed to none).

References