Skip to content

fix(discovery): attach a PR to the item that owns its branch instead of minting a duplicate item - #852

Merged
getappz merged 2 commits into
masterfrom
task/337-pr-discovery-mints-a-duplicate-item-for
Oct 5, 2026
Merged

getappz merged 2 commits into
masterfrom
task/337-pr-discovery-mints-a-duplicate-item-for

Conversation

@getappz

@getappz getappz commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Stops PR discovery from minting a duplicate item for a PR whose branch a live item already owns, for item #337 . This is part 1 of that item; parts 2 and 3 are split out (see the end).

What happened (PR #849, items #330 and #334)

Item #330's agent opened its own PR with gh pr create on its task/330-… branch. That path never writes metadata.pr.number, so discover_untracked_prs, which decides "already tracked" by PR number only, treated the PR as untracked and created a second item (#334) for it. The supervisor then dispatched CI and review repairs against #334; those jobs died in about a second because task/330-… is already checked out in #330's worktree, #334 got needs-manual-dispatch, and that label gates both the CodeRabbit repair and the merge, so a green PR sat unmerged.

Change

src/worktree/discovery.rs:

  • item_owning_branch finds the item a PR's head branch belongs to: task/<seq> or task/<seq>-<slug> for an item in the project, or a branch already recorded in an item's metadata.pr.branch.
  • When there is one, attach_pr_to_item records {number, branch} as that item's PR if it has none yet (through the existing merge_item_metadata, which merges under a transaction), and discovery skips the PR: no second item, no claim comment.
  • A task/<seq>-… branch with no matching item still gets a tracking item, so another workstation's PRs are not swallowed.

Tests

  • discover_untracked_prs_attaches_a_pr_to_the_item_that_owns_its_branch failed first (metadata.pr.number was Null) and passes now.
  • a_task_branch_with_no_matching_item_still_gets_a_tracking_item pins the other direction.
  • 251 worktree and supervisor tests pass; clippy -D warnings and fmt are clean.

Not in this PR (follow-up item)

  1. A repair dispatch whose claim fails on a worktree collision is not a repair failure: it should not count toward the dispatch-failure cap or set needs-manual-dispatch, and should route to the branch's owning item.
  2. A green, approved PR skipped only because of needs-manual-dispatch should notify instead of silently counting as skipped.
    Those touch the supervisor's repair-dispatch and orphan-reconcile paths and deserve their own review.

Authored for item #337 via agentflare.

…of minting a duplicate item

An agent that opens its own PR on its item's task/<seq>-<slug> branch never
writes metadata.pr, so number-only tracking called the PR untracked and
created a second item, which the supervisor then dispatched repairs against
and which collided with the owner's worktree.

Agentflare-Agent: claude-code
Agentflare-Branch: task/337-pr-discovery-mints-a-duplicate-item-for
Agentflare-Item: 337
Agentflare-Session: 10553a88-a912-4153-97c7-8d172ee44d92
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 51 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: getappz/agentflare/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 021b397c-8fe7-4882-be56-ba5b22348a51
📥 Commits

Reviewing files that changed from the base of the PR and between 1dcdeaf and ff4df88.

📒 Files selected for processing (1)
  • src/worktree/discovery.rs
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@getappz
getappz merged commit e658657 into master Oct 5, 2026
16 checks passed
@getappz
getappz deleted the task/337-pr-discovery-mints-a-duplicate-item-for branch October 5, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant