Skip to content

fix(handoff): address PR #365 review findings - #366

Merged
getappz merged 1 commit into
task/236from
fix/pr365-review
Jul 29, 2026
Merged

fix(handoff): address PR #365 review findings#366
getappz merged 1 commit into
task/236from
fix/pr365-review

Conversation

@getappz

@getappz getappz commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes for the review findings on #365 (item #236 handoff hardening):

  • CI fmt: two cargo fmt --check failures (item.rs claim closure, types.rs schemars attribute) that were failing the fmt / CI Green checks on feat(handoff): verified continuation commit, structured payload, duplicate-item reuse, assignee freeze #365.
  • Alias canonicalization bug (crates/agentflare-backend/src/item.rs): agent_part() compared the raw owner id against the already-canonicalized assignee_agent. An alias owner like claude:1 didn't match the stored canonical claude-code, so the handoff's own assignee could get wrongly BlockedByAssignee on their own item. Now canonicalizes both sides.
  • Blocking git calls under the DB mutex (src/mcp_server/handoff.rs): verify_continuation_commit ran up to three git subprocess calls inside with_backend_db, which holds a shared mutex — the same pattern the codebase already avoids in item_claim (DB resolve under lock, then blocking work after). Restructured to resolve the target branch under the lock and run all git checks after releasing it.
  • last_commit validation gap (security/correctness): a leading - in oid would be parsed by git as an option rather than a rev, and plain cat-file -e accepts blobs/trees/tags, not just commits. Now rejects non-hex input up front and forces commit-type resolution via oid^{commit}.
  • Empty structured payload: completed/remaining are documented as required but weren't checked for emptiness, so "" satisfied the contract silently. Added the same trim().is_empty() guard used for the other required fields.
  • Docs: the /handoff prompt didn't mention completed/remaining as required fields, so agent-generated requests built from the prompt could fail to deserialize.

Also added two regression tests (owner-alias claim, and updated existing handoff tests to supply completed/remaining now that they're enforced as non-empty).

Test plan

  • cargo fmt --check — clean
  • cargo clippy --workspace --all-features -- -D warnings — clean
  • cargo test --workspace --all-features — all green (886 passed in the main crate, 60 in agentflare-backend, no failures workspace-wide)

…oad off the DB lock

- cargo fmt (item.rs claim closure, types.rs schemars doc attr)
- item::claim: canonicalize both sides of the assignee/owner comparison so
  an alias owner (claude:1) isn't wrongly BlockedByAssignee against its own
  canonical handoff assignee (claude-code)
- verify_continuation_commit: resolve the target branch under the backend
  DB lock, then run all git subprocess checks after releasing it, matching
  the existing item_claim split; validate oid is a plain hex id and force
  commit-type resolution (oid^{commit}) so a non-hex/flag-like value or a
  blob/tree/tag can't pass as a continuation commit
- handoff_impl: reject empty completed/remaining instead of silently
  accepting an empty structured payload
- mcp_prompts: document completed/remaining as required handoff fields
  so generated requests don't fail deserialization
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0584bd73-d167-4dd3-bd03-082d16f6bcf3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

@getappz
getappz merged commit f156c45 into task/236 Jul 29, 2026
12 checks passed
@getappz
getappz deleted the fix/pr365-review branch July 29, 2026 05:00
getappz added a commit that referenced this pull request Jul 29, 2026
…icate-item reuse, assignee freeze (#365)

* feat(handoff): verified continuation commit, structured payload, duplicate-item reuse, assignee freeze

Item #236 (handoff hardening, QuorumGit adoption):

- HandoffRequest gains last_commit: verified via `git cat-file -e` and,
  when the item's task/<seq> branch already exists, `git merge-base
  --is-ancestor` -- a fabricated or unreachable OID is rejected, not
  trusted.
- HandoffRequest gains required completed/remaining and optional
  blockers fields, stored in the asset's metadata.
- A handoff without item_id now reuses an existing open item assigned
  to the recipient (matched by name or thread_id) instead of blindly
  creating a duplicate; genuinely new work still auto-creates.
- agentflare_backend::item::claim gains a BlockedByAssignee outcome:
  a freshly handed-off, never-claimed item can only be claimed by its
  assignee until accepted, excluding completed/cancelled items.

Deferred: shim-side branch-push denial for open handoffs (spec's own
review already downgraded this to defense-in-depth, covered in large
part by #234's scope enforcement and the opencode branch-guard plugin).

* fix(handoff): fmt, canonicalize claim owner, validate commit oid/payload off the DB lock (#366)

- cargo fmt (item.rs claim closure, types.rs schemars doc attr)
- item::claim: canonicalize both sides of the assignee/owner comparison so
  an alias owner (claude:1) isn't wrongly BlockedByAssignee against its own
  canonical handoff assignee (claude-code)
- verify_continuation_commit: resolve the target branch under the backend
  DB lock, then run all git subprocess checks after releasing it, matching
  the existing item_claim split; validate oid is a plain hex id and force
  commit-type resolution (oid^{commit}) so a non-hex/flag-like value or a
  blob/tree/tag can't pass as a continuation commit
- handoff_impl: reject empty completed/remaining instead of silently
  accepting an empty structured payload
- mcp_prompts: document completed/remaining as required handoff fields
  so generated requests don't fail deserialization

* fix(test): stop with_temp_home_clears_the_override_env_var_after_returning from racing concurrent with_temp_home callers

The assertion read AGENTFLARE_HOME_OVERRIDE outside GLOBAL_STATE_LOCK,
the lock that guards every set/remove of it. A concurrent thread's own
correctly-scoped with_temp_home call could be transiently holding the
var set at the exact moment this test read it, flaking the check on a
var this test was never entitled to observe in the first place. Fix:
acquire the same lock before reading.
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