Skip to content

fix(handoff): item_id re-labeling permanently blocked by stale-but-undone claims - #446

Merged
getappz merged 3 commits into
masterfrom
task/82
Aug 11, 2026
Merged

fix(handoff): item_id re-labeling permanently blocked by stale-but-undone claims#446
getappz merged 3 commits into
masterfrom
task/82

Conversation

@getappz

@getappz getappz commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Summary

Root causes confirmed (via code reading + live DB inspection, not guessing):

  1. Case 1 (real bug, fixed)handoff(item_id=X)'s "safe to re-label" check in src/mcp_server/handoff.rs used claim::current_owner, which deliberately includes stale-but-undone claims (its own doc comment says so — it exists for lock-cleanup tooling). A claim row only ever leaves status='claimed' via claim::done, which only fires on the normal in_review→completed promotion. Any item whose work was interrupted or manually rescued outside that flow kept a permanently claimed row, so current_owner never returned None again — silently vetoing ready-for-work re-labeling on every future handoff to that item, forever, with zero error. Fixed by swapping in a TTL-aware liveness check (has_active_claim_by_other), the same primitive quota::decide tier 4 and the GitHub bridge already use elsewhere.

  2. Case 2 hypothesis — refuted. Read list_by_label, run_discovery_tick, and quota::decide::decide end to end: nothing anywhere gates on completed_at. Direct DB inspection showed item [ponytail#532] Persona wording: lazy = less work for same result #66's actual blocker was that it simply had no ready-for-work label (only a leftover dispatched label) — its claim was already correctly marked done. Confirmed by re-adding the label: the (unmodified, already-running) daemon picked it up and enqueued a job within one tick.

  3. Real but separate bug found: item::update_state's "started" branch never clears a stale completed_at, so a reopened item can show completed_at < started_at forever — this is what produced [ponytail#532] Persona wording: lazy = less work for same result #66's specific stale timestamp, and corrupts standup/health velocity bucketing (which keys off completed_at). I wrote and tested the fix, but could not commit it: crates/agentflare-backend/src/item.rs is already at 2139 lines against the repo's 2000-line frozen-file LOC gate on master — pre-existing debt unrelated to this task. Landing it would require first splitting the file, which is out of scope here. Confirmed this fix isn't needed to unblock [ponytail#532] Persona wording: lazy = less work for same result #66.

  4. Visibility: threaded Decision::reason through EffectiveAction::Wait and added per-item logging plus a waiting count in the daemon summary line, so a labeled item stuck for many ticks is now visible in the log instead of indistinguishable from "no eligible items."

Committed (cc8e3ad): the handoff fix, the visibility improvement, and regression tests (an_explicit_item_id_handoff_labels_an_item_with_only_a_stale_claim, plus an assertion on the cooldown test). All 40+44 relevant tests pass.

Item #66: manually re-labeled ready-for-work (data-only fix) and confirmed dispatched — job CeUJQf7EUe4eTCXQFqsff is queued, waiting on a free work_max_concurrency slot (ironically, the very thing item #66 itself is about).

Left for a human: the update_state completed_at fix is written and tested but not committed, blocked by the pre-existing LOC gate on item.rs — worth a follow-up decision (split the file vs. adjust the gate) before it can land.

… on any item with an abandoned claim

The item_id branch's "safe to relabel" check used claim::current_owner,
which deliberately includes stale-but-undone claims (its own doc comment:
"so stale locks can be cleaned up"). A claim row only ever leaves
status='claimed' via claim::done, which only runs on the normal
in_review -> completed promotion. Any item whose work was interrupted or
manually rescued outside that flow (crash, human takeover) kept a
permanently "claimed" row, so current_owner never went None again --
silently vetoing ready-for-work re-labeling on every future handoff to
that item, with no error surfaced anywhere.

Swapped in a TTL-aware liveness check (the same primitive quota::decide's
tier 4 and the GitHub bridge's own claim-liveness check already use), so
an expired claim is correctly treated as no claim -- matching what "safe
to re-queue" actually means.

Also thread Decision::reason through EffectiveAction::Wait and log each
waiting/cooling-down ready-for-work item per tick, plus a `waiting` count
in the daemon's summary line, so a labeled item sitting idle for many
ticks is visible in the log instead of looking identical to "no eligible
items exist" -- exactly what made this bug take an hour of manual
item-diffing to notice.

A related stale-completed_at issue (item::update_state's "started" branch
never clearing a prior completed_at) was root-caused too but is not
included here: crates/agentflare-backend/src/item.rs is already past the
repo's 2000-line frozen-file LOC gate on master (pre-existing, unrelated
to this change), so any edit to it is currently unlandable without first
splitting the file. Confirmed that fix is not required to unblock item
#66 -- its sole blocker was a missing ready-for-work label, fixed as a
data-only change (no code path reads completed_at for dispatch
eligibility at all).

Agentflare-Agent: claude-code
Agentflare-Branch: task/82
Agentflare-Item: 82
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 40 minutes

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).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9ac51da2-ee27-4061-8391-59dddd129840

📥 Commits

Reviewing files that changed from the base of the PR and between 65f0788 and 5e5e452.

📒 Files selected for processing (4)
  • src/dashboard/server.rs
  • src/mcp_server/handoff.rs
  • src/quota/decide.rs
  • src/supervisor.rs

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

@getappz getappz changed the title investigate: discovery tick silently skips correctly-labeled ready-for-work items — stale completed_at and missing-label-after-handoff both observed fix(handoff): item_id re-labeling permanently blocked by stale-but-undone claims Aug 11, 2026
shiva and others added 2 commits August 11, 2026 14:29
Agentflare-Agent: claude-code
Agentflare-Branch: task/82
Agentflare-Item: 82
@getappz
getappz merged commit 60042f7 into master Aug 11, 2026
16 checks passed
@getappz
getappz deleted the task/82 branch August 11, 2026 09:16
getappz pushed a commit that referenced this pull request Aug 11, 2026
Reconciles per-project folder_path dispatch (item #63) with item #82's
waiting/Wait(reason) tracking and cooling-down/wait logging, which
landed to master independently (#446) while this branch was open.
Both behaviors kept: dispatch_item still threads folder_path, and
both the cooldown and Wait branches now log + increment waiting.

All 19 supervisor:: tests pass, fmt clean, clippy clean (CI flags).

Agentflare-Agent: claude-code
Agentflare-Branch: task/63
Agentflare-Item: 63
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