Skip to content

chore: item done leaves an item stuck In Progress when its PR was merged externally before finalize ran (seen on #283 / PR #910) - #953

Merged
getappz merged 3 commits into
masterfrom
task/373-item-done-leaves-an-item-stuck-in-progre
Oct 22, 2026
Merged

getappz merged 3 commits into
masterfrom
task/373-item-done-leaves-an-item-stuck-in-progre

Conversation

@getappz

@getappz getappz commented Oct 22, 2026

Copy link
Copy Markdown
Owner

A human (or another instance's finalize) merged an item's PR while its job was still running, and the head branch went with it. done then tried to push a branch that no longer existed, and the item was left wedged in started with its PR record stripped — a state nothing could recover from, because the sweep's self-heal reads the PR number out of that same record (item #283 / PR #910, item #173 / PR #666).

done now asks GitHub whether the PR it tracked has already merged, and when it has, completes the item instead of pushing.

Two conditions keep it honest:

  • it keys on metadata.pr, and redispatch clears that (crates/agentflare-backend/src/item/claim.rs) — so an item handed back for more work carries no PR reference and can never be completed by someone else's merge;
  • the merge has to have covered the branch. A branch tip that moved on after the merge holds work the PR never carried, and that work is not completed away.

The PR record survives the completion: it is what lets the review sweep find the PR again.

Also adds AgentflareMcp::github_client_override — a GitHub-client test seam in the same shape as the repo-root and backend-db overrides — so a code path that has to ask GitHub about a PR can be driven end to end against a mock server instead of only at the helper level. (item_check_merge's merge path had no such seam, which is why its behaviour was only ever unit-tested one layer down.)

Test plan

mbx test --bin agentflare            # 2763 passed, 0 failed (1 known load flake, passes in isolation), 10 ignored
mbx clippy --all-targets             # no warnings in the touched files
cargo fmt --all -- --check           # clean
sh scripts/loc-gate.sh               # OK

Notes for reviewers

Risk areas

  • item_done is the most-used path in the codebase. The new branch fires only when the item records a PR and GitHub reports that PR merged and the branch tip is exactly the PR's head — three conditions, all of which must hold.
  • The check costs one GitHub read per done call on an item that has a PR. It runs before the push, so a merged PR short-circuits the push entirely.
  • metadata.pr is deliberately not cleared on this path: the sweep needs it to find the PR again.

Edge cases covered by tests

  • a merged PR completes the item, keeps metadata.pr.number, releases the claim, and removes the worktree;
  • the branch tip that moved on past the merged commit is not covered, so that work is not completed away;
  • a branch that is gone counts as covered (nothing local is left to deliver);
  • no PR head sha means not covered — the claim cannot be backed;
  • an open PR is not a merge.

Backwards compatibility

  • No behaviour change for an item with no PR, an open PR, or a PR whose merge did not cover the branch.
  • No new dependencies; no schema change.

Opened by opencode on i-flare-51bb8de6c33b (flared:51bb8de6c33b) for item #373 via agentflare.

A human (or another instance's finalize) merged an item's PR while its
job was still running, and the head branch went with it. `done` then
tried to push a branch that no longer existed, and the item was left
wedged in "started" with its PR record stripped -- a state nothing could
recover from, because the sweep's self-heal reads the PR number out of
that same record (item #283 / PR #910, item #173 / PR #666).

`done` now asks GitHub whether the PR it tracked has already merged, and
when it has, completes the item instead of pushing. Two conditions keep
it honest:

- it keys on `metadata.pr`, and `redispatch` clears that -- so an item
  handed back for more work carries no PR reference and can never be
  completed by someone else's merge;
- the merge has to have covered the branch. A branch tip that moved on
  after the merge holds work the PR never carried, and that work is not
  completed away.

The PR record survives the completion: it is what lets the review sweep
find the PR again.

Also adds `AgentflareMcp::github_client_override`, a GitHub-client test
seam in the same shape as the repo-root and backend-db overrides, so a
code path that has to ask GitHub about a PR can be driven end to end
against a mock server instead of only at the helper level.

Agentflare-Agent: opencode
Agentflare-Branch: task/373-item-done-leaves-an-item-stuck-in-progre
Agentflare-Item: 373
@coderabbitai

coderabbitai Bot commented Oct 22, 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 6 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 7e08ca7 and 58d3bfa.

📒 Files selected for processing: 7
  • src/mcp_server.rs
  • src/mcp_server/item.rs
  • src/mcp_server/item_merged_pr.rs
  • src/mcp_server/tests/item_merged_pr_tests.rs
  • src/mcp_server/tests/mod.rs
  • src/worktree/mod.rs
  • src/worktree/mod_tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@getappz
getappz marked this pull request as ready for review October 22, 2026 08:06
…-progre

Agentflare-Agent: opencode
Agentflare-Branch: HEAD
@getappz
getappz merged commit 6179f98 into master Oct 22, 2026
16 checks passed
@getappz
getappz deleted the task/373-item-done-leaves-an-item-stuck-in-progre branch October 22, 2026 12:32
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