Repository navigation
Conversation
…the done-arm race item::claim_done released the claim lease and moved the item to completed in one transaction; push_and_open_pr then ran after that transaction committed, outside the backend DB lock. In the window between release and the push/PR finishing, another agent could claim() the same now-completed item, silently reassigning item.assignee_agent mid-flight. Split into item::mark_completed (state transition only, verifies the caller still holds the claim, does not touch the ledger) plus a deferred claim::done call in the done MCP arm that only runs after push_and_open_pr has been attempted. The lease stays held for the entire publish window, so a concurrent claim() correctly returns Held instead of Acquired. Added ClaimLedger::is_owner (ownership check without mutating the claim) to support the split. New/updated backend tests cover: a concurrent claim is rejected while the lease is still held post- mark_completed, and mark_completed no-ops for a non-owning caller.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds claim ownership checks, replaces ChangesCompletion and claim lease flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Sequence Diagram(s)sequenceDiagram
participant MCP_item_tool
participant mark_completed
participant push_and_open_pr
participant claim_done
MCP_item_tool->>mark_completed: Mark item completed
mark_completed-->>MCP_item_tool: Completion result
MCP_item_tool->>push_and_open_pr: Push changes and open PR
push_and_open_pr-->>MCP_item_tool: PR result
MCP_item_tool->>claim_done: Release claim lease
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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.rs (1)
2635-2675: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winKeep the claim lease alive through publish, and surface release failures.
push_and_open_prcan run long enough for the claim to expire beforeclaim::doneruns.claim::done(...)is discarded; log or handlefalse/errors so an owner mismatch or DB failure doesn't disappear.🤖 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.rs` around lines 2635 - 2675, The completion flow around push_and_open_pr must refresh or otherwise keep the claim lease alive throughout publishing, then surface any claim::done failure instead of discarding it. Update the done-claim release block to handle both false results and database errors with appropriate logging or propagation, preserving the existing owner and timestamp semantics.
🤖 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.rs`:
- Around line 2635-2675: The completion flow around push_and_open_pr must
refresh or otherwise keep the claim lease alive throughout publishing, then
surface any claim::done failure instead of discarding it. Update the done-claim
release block to handle both false results and database errors with appropriate
logging or propagation, preserving the existing owner and timestamp semantics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a24fd575-3ea4-4abd-a393-c12d27c940b0
📒 Files selected for processing (4)
crates/agentflare-backend/src/claim.rscrates/agentflare-backend/src/item.rscrates/agentflare-db-kit/src/claim.rssrc/mcp_server.rs
Addresses CodeRabbit on PR #183: - push_and_open_pr can run long enough that a short custom AGENTFLARE_BACKEND_CLAIM_TTL_SECS could let the lease go stale mid-publish. Refresh the heartbeat right before the publish step starts, immediately after mark_completed succeeds. - The final claim::done release call discarded its result entirely. Now logs (eprintln, matching this file's other soft-fails) on an owner mismatch, a DB error, or a with_backend_db lock failure, instead of silently swallowing it.
* feat(mcp): consolidate 6 tools into action-dispatch pattern - Merge skill/search+load, gateway/search+execute, claim/5-actions, review/5-actions, artifact/6-actions, memory/6-actions into one consolidated #[tool(...)] method each with action dispatch - Reconcile with #182 (fetch target branch before branching) and #183 (deferred claim release, mark_completed split) * fix(mcp): finish artifact/skill/gateway test migration, fix consolidation regressions CI was red: ~35 test call sites in mcp_server.rs still called the old per-action methods (artifact_publish/get/list/delete/diff/search, skill_search/load, gateway_search/execute) that this consolidation removed. Migrated them all to the unified action-dispatch tools. Also fixes real bugs the consolidation introduced along the way: - artifact()'s get/diff/search arms called store methods with a signature they no longer have (get takes no version, diff's to is a required u32, and there's no store.search at all) — restored the pre-consolidation logic (get_version fallback, latest-version resolution, inline list+filter+snippet search). - review()'s "consensus" arm called crate::review::consensus with the wrong arguments entirely (a Connection/ids instead of findings+changed-lines); now loads findings and computes the diff/changed-lines first, matching "record"'s already-correct pattern. Also dropped record's dead base/head locals that shadowed the actual req.base/req.head usage. - memory()'s "curate" arm passed the outer "curate" action into CurateInput.action, so update/delete/pin/unpin could never be reached; added a dedicated curate_action field. - mark_completed's ownership check and completion write weren't in the same transaction, leaving a window for a concurrent release+claim by a different owner to complete the item out from under its new owner. Also ran cargo fmt across the branch (had never been formatted). * fix(fmt): collapse tool() signature onto one line per rustfmt
…ut false positives (#183) cursor-agent was dispatched with its default text output format, same as the pre-#489 Claude Code behavior: run_captured's idle-timeout (default 300s) writes nothing to stdout until the run finishes, so any real, longer cursor-agent task gets killed as a false-positive hang. build_extra_args now also passes --output-format stream-json for Agent::Cursor (without the Claude-Code-only --verbose/--max-turns/ --max-cost-usd flags, unconfirmed for cursor-agent), and clean_agent_reply parses cursor-agent's stream-json transcript the same way as Claude Code's. New test lives in its own file (cli/work/cursor_dispatch_tests.rs) since src/cli/work.rs is frozen at the LOC gate's limit. Agentflare-Agent: claude-code Agentflare-Branch: task/183-fix-cursor-agent-stream-json-idle-timeout Agentflare-Item: 183
…ut false positives (#183) (#594) cursor-agent was dispatched with its default text output format, same as the pre-#489 Claude Code behavior: run_captured's idle-timeout (default 300s) writes nothing to stdout until the run finishes, so any real, longer cursor-agent task gets killed as a false-positive hang. build_extra_args now also passes --output-format stream-json for Agent::Cursor (without the Claude-Code-only --verbose/--max-turns/ --max-cost-usd flags, unconfirmed for cursor-agent), and clean_agent_reply parses cursor-agent's stream-json transcript the same way as Claude Code's. New test lives in its own file (cli/work/cursor_dispatch_tests.rs) since src/cli/work.rs is frozen at the LOC gate's limit. Agentflare-Agent: claude-code Agentflare-Branch: task/183-fix-cursor-agent-stream-json-idle-timeout Agentflare-Item: 183 Co-authored-by: shiva <shiva@gosysinfo.tech>
Fixes item #37 (flagged by CodeRabbit reviewing PR #179): item::claim_done released the claim lease and moved the item to completed in one transaction; push_and_open_pr then ran after that transaction committed, outside the backend DB lock. In the window between release and the push/PR finishing, another agent could claim() the same now-completed item, silently reassigning item.assignee_agent mid-flight.
Fix
Split item::claim_done into item::mark_completed (state transition only — verifies the caller still holds the claim, does not touch the ledger) plus a deferred claim::done call in the done MCP arm that only runs after push_and_open_pr has been attempted (success or soft-fail, it never blocks). The lease stays held for the entire publish window, so a concurrent claim() correctly returns Held instead of Acquired.
Added ClaimLedger::is_owner (checks current ownership without mutating the claim row) to support the split.
Tests
432/432 tests pass, clippy clean (-D warnings -A unsafe_code -A clippy::pedantic), fmt clean.
Summary by CodeRabbit