Skip to content

fix(dispatcher): clear dispatch labels on cancel, make discovery state-aware - #661

Merged
getappz merged 2 commits into
masterfrom
task/225-item-cancel-doesn-t-clear-ready-for-work
Sep 11, 2026
Merged

getappz merged 2 commits into
masterfrom
task/225-item-cancel-doesn-t-clear-ready-for-work

Conversation

@getappz

@getappz getappz commented Sep 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • `item_cancel` never cleared `ready-for-work`/`dispatched`/`needs-manual-dispatch`, and `run_discovery_tick`'s `list_by_label` query joined purely on label with no state filter — a cancelled item that still carried `ready-for-work` (the normal case for a cancel shortly after handoff, before any orphan/failure cycle would've swapped the label) kept getting redispatched indefinitely.
  • `item_cancel` now best-effort clears the dispatch-lifecycle labels, mirroring what `redispatch` already does in reverse.
  • `list_by_label` is now state-aware like its sibling `list_by_assignee_agent`, excluding completed/cancelled items at the SQL level (defense-in-depth even if a label is left on a non-active item for some other reason).

Fixes item #225. A deeper related bug (`claim()` not checking item state, so a stale queued retry job can still reopen a cancelled item) is filed separately as item #226 — bigger design question, not bundled here.

Test plan

  • `cargo check` clean
  • `cargo test -p agentflare-backend -p agentflare cancel` — 8/8 pass, including new `item_cancel_clears_dispatch_lifecycle_labels`
  • `cargo test -p agentflare-backend list_by_label` — 2/2 pass, including new `list_by_label_excludes_completed_and_cancelled_items`

Summary by CodeRabbit

  • Bug Fixes

    • Cancelled and completed items no longer appear as dispatch candidates when filtered by label.
    • Cancelling an item now removes dispatch-related labels, preventing it from remaining eligible for work.
    • Active items sharing labels with cancelled items continue to appear correctly.
  • Tests

    • Added coverage for label-based filtering and cleanup of dispatch labels when items are cancelled.

…e-aware

item_cancel never cleared ready-for-work/dispatched/needs-manual-dispatch,
and run_discovery_tick's list_by_label query joined purely on label with
no state filter. A cancelled item that still carried ready-for-work (the
normal case for a cancel shortly after handoff, before any orphan/failure
cycle would've swapped the label) kept getting redispatched indefinitely.

- item_cancel now best-effort clears the dispatch-lifecycle labels,
  mirroring what redispatch already does in reverse.
- list_by_label is now state-aware like its sibling list_by_assignee_agent,
  excluding completed/cancelled items at the SQL level.

Adds regression tests for both; the new list_by_label test lives in a new
tests_labels.rs to respect the frozen LOC limit on item/tests.rs, same
split pattern as the existing tests_relations.rs.

Agentflare-Agent: claude-code
Agentflare-Branch: task/225-item-cancel-doesn-t-clear-ready-for-work
Agentflare-Item: 225
Agentflare-Session: b80abe7f-226d-4884-95a6-2aca737f1aa8
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: e3246310-c09b-4eff-9755-034cfa3ec0e9

📥 Commits

Reviewing files that changed from the base of the PR and between e623403 and 944a641.

📒 Files selected for processing (5)
  • crates/agentflare-backend/src/item/crud.rs
  • crates/agentflare-backend/src/item/tests.rs
  • crates/agentflare-backend/src/item/tests_labels.rs
  • src/mcp_server/item.rs
  • src/mcp_server/tests/item_tests.rs

Included review availability: 3 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


📝 Walkthrough

Walkthrough

The change prevents cancelled and completed items from remaining dispatch candidates. Label-based listing filters inactive states, and cancellation best-effort removes dispatch lifecycle labels. Regression tests cover both behaviors.

Changes

Dispatch lifecycle handling

Layer / File(s) Summary
Filter inactive labeled items
crates/agentflare-backend/src/item/crud.rs, crates/agentflare-backend/src/item/tests.rs, crates/agentflare-backend/src/item/tests_labels.rs
list_by_label now excludes items in completed or cancelled state groups. Regression coverage verifies that active items remain when they share a label with a cancelled item.
Clear labels during cancellation
src/mcp_server/item.rs, src/mcp_server/tests/item_tests.rs
item_cancel best-effort removes ready-for-work, dispatched, and needs-manual labels. Tests verify removal of the ready-for-work and dispatched labels.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to a07cc

Cancelled and completed items are filtered from dispatch candidates, and cancellation clears the relevant lifecycle labels. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the cancellation and discovery fixes, the reason for the changes, the regression tests, and the excluded follow-up issue. It does not include the optional Notes for re…
Title check ✅ Passed The title clearly identifies both primary changes: clearing dispatch labels on cancellation and making discovery state-aware. It is concise and directly related to the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/225-item-cancel-doesn-t-clear-ready-for-work

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

@getappz

getappz commented Sep 11, 2026

Copy link
Copy Markdown
Owner Author

Tracking this PR for automated review (flared:51bb8de6c33b).

@getappz
getappz merged commit 8554100 into master Sep 11, 2026
2 of 15 checks passed
@getappz
getappz deleted the task/225-item-cancel-doesn-t-clear-ready-for-work branch September 11, 2026 12:20
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