Skip to content

feat(handoff): auto-label brand-new items ready-for-work - #406

Merged
getappz merged 4 commits into
masterfrom
task/32
Aug 8, 2026
Merged

getappz merged 4 commits into
masterfrom
task/32

Conversation

@getappz

@getappz getappz commented Aug 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Depends on #401 — targeted at that branch so this diff only shows item #32's incremental work; retarget to master once #401 merges (independent of #402, can merge in either order after #401).

Today mcp__flare__handoff (src/mcp_server/handoff.rs) assigns assignee_agent on the item it creates/updates but never touches labels — a human has to separately add the ready-for-work label for the daemon's discovery loop (run_discovery_tick in src/supervisor.rs) to notice and auto-dispatch it. Handoff is effectively manual today.

  • Only the brand-new-item creation path (item_id not given) gets auto-labeled — not replies to an existing item_id, which may already be claimed, in progress, or done and shouldn't be silently re-queued for dispatch.
  • Applies to every recipient, not just confirmed-autonomous agents — the daemon's existing discovery-tick gate (resolve_confirmed_agent) already safely no-ops and relabels to needs-manual-dispatch with an explanatory comment for a human/non-autonomous recipient, so that check isn't duplicated here.
  • Best-effort: looks up the ready-for-work label by name in the project; skips silently if the project doesn't have it, rather than creating one out of nowhere for a project that hasn't opted into autonomous dispatch.
  • READY_LABEL (src/supervisor.rs) is now pub(crate) so handoff.rs reuses it as the single source of truth instead of duplicating the label name as a second string literal that could drift.

Also includes (merged in from #401's branch, same fix needed here since this branch runs the same test suite): the coaching::rule Windows CI flake fix (tempfile::tempdir() instead of a process-local counter that collides across cargo nextest's per-test-process model).

Test plan

  • cargo build -p agentflare -p agentflare-jobs — clean
  • cargo test -p agentflare -p agentflare-jobs --lib --bins — 1139 passed (3 new: label added when the project has ready-for-work, skipped silently when it doesn't, not added on a reply to an existing item)
  • cargo fmt --all -- --check / cargo clippy --all-targets — clean

Summary by CodeRabbit

  • New Features
    • Newly created handoff items are automatically marked as ready for work when the existing label is available.
  • Bug Fixes
    • Handoff creation continues successfully when the label is unavailable.
    • Existing handoff items are no longer incorrectly labeled.
  • Tests
    • Added coverage for label application, missing-label handling, and reused items.

shiva added 2 commits August 8, 2026 13:40
A freshly created handoff item is real, undone work -- the supervisor's
discovery loop (run_discovery_tick) only notices items already labeled
ready-for-work, so until now a human had to add that label by hand for
autonomous dispatch to ever pick up a handed-off item.

Only the brand-new-item path is labeled, not replies to an existing
item_id -- those may already be claimed, in progress, or done, and
silently re-queuing them for dispatch would be wrong. Applies to every
recipient, not just confirmed-autonomous agents: the discovery loop's
own resolve_confirmed_agent gate already handles a non-autonomous
recipient safely (relabels to needs-manual-dispatch with an
explanatory comment), so that check isn't duplicated here. Best-effort:
looks up the ready-for-work label by name in the project and skips
silently if the project doesn't have it, rather than creating one out
of nowhere for a project that hasn't opted into autonomous dispatch.

READY_LABEL (src/supervisor.rs) is now pub(crate) so handoff.rs can
reuse it as the single source of truth instead of duplicating the
label name as a second string literal that could drift.
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The handoff workflow now applies the existing project ready-for-work label to newly created items. It does not create missing labels or relabel reused items. Tests cover all three cases.

Changes

Handoff labeling

Layer / File(s) Summary
Shared ready-for-work label contract
src/supervisor.rs
READY_LABEL is crate-visible and documents its shared use by supervisor discovery and handoff creation.
New item labeling and validation
src/mcp_server/handoff.rs
New items receive the existing label when available. Missing labels do not block creation, and reused items remain unchanged. Tests cover these behaviors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes automatic ready-for-work labeling for newly created handoff items.
Description check ✅ Passed The description explains the change, scope, edge cases, dependencies, and test results, but omits the optional Notes for reviewers section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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/32

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

Base automatically changed from task/20 to master August 8, 2026 08:52
@getappz
getappz enabled auto-merge August 8, 2026 08:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/mcp_server/handoff.rs (1)

139-160: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Propagate label lookup failures.

Line 141 converts every backend error into an empty label list. A transient or persistent query failure then creates an unlabeled handoff item and prevents supervisor discovery.

Return the backend error. Only an empty successful result should skip the label.

Proposed fix
 let ready_label_id =
     agentflare_backend::label::list_by_project(conn, &project.id)
-        .ok()
+        .map_err(map_backend_err)?
         .and_then(|labels| {
             labels
                 .into_iter()
                 .find(|l| l.name == crate::supervisor::READY_LABEL)
         })
         .map(|l| l.id);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp_server/handoff.rs` around lines 139 - 160, The ready-label lookup in
the handoff creation flow must propagate errors from label::list_by_project
instead of converting them to an empty result. Update the chain around
ready_label_id so successful empty results still omit the label, while backend
failures are returned from the enclosing function before creating the item.
🧹 Nitpick comments (1)
src/mcp_server/handoff.rs (1)

451-482: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test the reusable-item branch without item_id.

This test sets item_id, so it only tests the update branch at Lines 75-82. It does not test the reusable branch at Lines 91-111.

Create the second handoff without item_id. Assert that it returns the first item ID and that the cleared label remains absent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp_server/handoff.rs` around lines 451 - 482, Update the test
a_reply_to_an_existing_item_is_not_labeled_ready_for_work to omit item_id from
the second HandoffRequest, exercising the reusable-item branch. Capture the
returned item ID, assert it matches the first item ID, and retain the assertion
that the cleared ready-for-work label remains absent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/mcp_server/handoff.rs`:
- Around line 139-160: The ready-label lookup in the handoff creation flow must
propagate errors from label::list_by_project instead of converting them to an
empty result. Update the chain around ready_label_id so successful empty results
still omit the label, while backend failures are returned from the enclosing
function before creating the item.

---

Nitpick comments:
In `@src/mcp_server/handoff.rs`:
- Around line 451-482: Update the test
a_reply_to_an_existing_item_is_not_labeled_ready_for_work to omit item_id from
the second HandoffRequest, exercising the reusable-item branch. Capture the
returned item ID, assert it matches the first item ID, and retain the assertion
that the cleared ready-for-work label remains absent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e7b55b81-f92e-4d2f-95e5-b4cefe07793f

📥 Commits

Reviewing files that changed from the base of the PR and between c5649bd and f90a775.

📒 Files selected for processing (2)
  • src/mcp_server/handoff.rs
  • src/supervisor.rs

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