Repository navigation
feat(mcp): knowledge fact import + session snapshot in flare_handoff - #269
Conversation
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe MCP handoff request now accepts optional facts and session snapshot fields. Facts are imported into recipient memory on a best-effort basis, while snapshot fields are stored in attachment metadata and documented in the tool description. ChangesHandoff session context enrichment
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant handoff_impl
participant handle_remember
participant Attachment
Caller->>handoff_impl: HandoffRequest with facts and snapshot fields
handoff_impl->>handle_remember: RememberInput for each fact
handle_remember-->>handoff_impl: Memory write result
handoff_impl->>Attachment: Store session snapshot in meta
handoff_impl-->>Caller: Handoff outcome
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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.
Inline comments:
In `@src/mcp_server.rs`:
- Line 412: Update the public handoff description assigned to the tool around
the facts payload to document the optional topic_key field alongside title,
content, and type. Keep the existing description and behavior unchanged while
making the advertised facts contract match the request schema and handler.
In `@src/mcp_server/handoff.rs`:
- Around line 46-79: Move the knowledge-fact import block around the visible
handoff success path so it runs only after with_backend_db successfully resolves
the item and creates the asset. Preserve the existing best-effort
handle_remember behavior and error logging, while ensuring any backend or
storage failure returns before facts are persisted.
- Around line 62-72: Update the handoff memory flow around RememberInput so
imported facts are associated with the handoff recipient by passing the
appropriate recipient-specific session, project, scope, or agent context through
the memory API. Ensure the recipient value is propagated into the memory layer
rather than leaving all context fields unset; alternatively, revise the handoff
contract and documentation to explicitly define these facts as shared memory.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d38aa94f-1df9-473e-b3e1-619bcc49b2fa
📒 Files selected for processing (3)
src/mcp_server.rssrc/mcp_server/handoff.rssrc/mcp_server/types.rs
…anism (item #269) Root-caused why a comment/handoff correction posted after an agent claims an item is never read before that agent opens/merges its PR: tasks are synthesized once from the item description at dispatch, every role prompt is built only from that frozen task plus prior review findings, and finalize calls item_done with no check of the item's live comment history. Reproduced live on items #265/#266 (PR #753 shipped mise which -t after a comment said to use mise env --json instead). Proposes piggybacking a comment/handoff poll on the existing claim heartbeat loop, feeding pending corrections into the next role prompt and gating finalize's item_done call the same way hold_reason already does. Doc only, no code changes. Agentflare-Agent: claude-code Agentflare-Branch: task/269-dispatched-agents-miss-mid-flight-item-c Agentflare-Item: 269 Agentflare-Session: 4466a268-502d-45d2-b372-46b85b9f800b
Implemented the mechanism from `docs/superpowers/plans/2026-09-17-mid-flight-item-correction-detection.md` (item #269) in `src/work_item_pipeline.rs`: 1. **`WorkItemData::pending_corrections: Vec<String>`** and **`last_seen_comment_at: i64`** — new persisted fields (both `#[serde(default)]` for backward-compat deserialization of older runs). 2. **Heartbeat-tick poll** (`poll_pending_corrections`) — piggybacks on the existing 300s heartbeat in `run_or_resume_with_sender`'s outer loop. Lists item comments via `comment_impl(action="list")`, keeps ones newer than the cursor and not authored by the run's own `owner` identity, and writes them via `StateStore::update` (the same load-mutate-write-under-lock primitive the engine itself uses), so it races safely against an in-flight step — worst case a write is lost to a step's completion overwrite and gets re-detected on the next tick (an explicitly accepted tradeoff in the plan doc). 3. **Per-task-turn consumption** in `build_sdd_loop_step` — prepends any pending corrections to the next role prompt as a labeled note, then clears them. 4. **Finalize gate** in `build_finalize_step` — if a correction is still pending right before `item_done`, it's treated like `hold_reason`: release the claim, post an on-hold comment quoting the correction, skip `item_done`/PR-open. Seeded `last_seen_comment_at` to run-start time on fresh dispatch (resumed runs keep their persisted cursor). **Tests added** (4 new, all passing): prompt-prepend + clear behavior, no-op when nothing pending, finalize hold-gate (verifies `pr_url` stays `None` and the hold comment quotes the correction), and `poll_pending_corrections`'s author/cursor filtering against a real SQLite-backed engine + comment DB. **Verification**: `cargo build` clean; `cargo test -p agentflare --bin agentflare work_item_pipeline` → 104 passed, 0 failed, 2 pre-existing ignores (unrelated); `cargo clippy --tests` clean (zero warnings touching `work_item_pipeline`); `rustfmt --edition 2024` applied to all changed files (plain `cargo fmt -- <paths>` misdetects edition when given explicit file args — pre-existing repo quirk, not a regression). **Concerns**: The plan's two "open questions" (handoff-onto-claimed-item not surfacing through this channel, and whether a correction should force-reopen an already-approved judge decision) are explicitly left as follow-ups in the doc and are out of scope here — not implemented. Agentflare-Branch: task/270-implement-pending-corrections-heartbeat Agentflare-Item: 270 Co-authored-by: shiva <shiva@gosysinfo.tech>
…anism (item #269) Root-caused why a comment/handoff correction posted after an agent claims an item is never read before that agent opens/merges its PR: tasks are synthesized once from the item description at dispatch, every role prompt is built only from that frozen task plus prior review findings, and finalize calls item_done with no check of the item's live comment history. Reproduced live on items #265/#266 (PR #753 shipped mise which -t after a comment said to use mise env --json instead). Proposes piggybacking a comment/handoff poll on the existing claim heartbeat loop, feeding pending corrections into the next role prompt and gating finalize's item_done call the same way hold_reason already does. Doc only, no code changes. Agentflare-Agent: claude-code Agentflare-Branch: task/269-dispatched-agents-miss-mid-flight-item-c Agentflare-Item: 269 Agentflare-Session: 4466a268-502d-45d2-b372-46b85b9f800b
…anism (item #269) Root-caused why a comment/handoff correction posted after an agent claims an item is never read before that agent opens/merges its PR: tasks are synthesized once from the item description at dispatch, every role prompt is built only from that frozen task plus prior review findings, and finalize calls item_done with no check of the item's live comment history. Reproduced live on items #265/#266 (PR #753 shipped mise which -t after a comment said to use mise env --json instead). Proposes piggybacking a comment/handoff poll on the existing claim heartbeat loop, feeding pending corrections into the next role prompt and gating finalize's item_done call the same way hold_reason already does. Doc only, no code changes. Agentflare-Agent: claude-code Agentflare-Branch: task/269-dispatched-agents-miss-mid-flight-item-c Agentflare-Item: 269 Agentflare-Session: 4466a268-502d-45d2-b372-46b85b9f800b
…anism (item #269) Root-caused why a comment/handoff correction posted after an agent claims an item is never read before that agent opens/merges its PR: tasks are synthesized once from the item description at dispatch, every role prompt is built only from that frozen task plus prior review findings, and finalize calls item_done with no check of the item's live comment history. Reproduced live on items #265/#266 (PR #753 shipped mise which -t after a comment said to use mise env --json instead). Proposes piggybacking a comment/handoff poll on the existing claim heartbeat loop, feeding pending corrections into the next role prompt and gating finalize's item_done call the same way hold_reason already does. Doc only, no code changes. Agentflare-Agent: claude-code Agentflare-Branch: task/269-dispatched-agents-miss-mid-flight-item-c Agentflare-Item: 269 Agentflare-Session: 4466a268-502d-45d2-b372-46b85b9f800b
…anism (item #269) (#754) Root-caused why a comment/handoff correction posted after an agent claims an item is never read before that agent opens/merges its PR: tasks are synthesized once from the item description at dispatch, every role prompt is built only from that frozen task plus prior review findings, and finalize calls item_done with no check of the item's live comment history. Reproduced live on items #265/#266 (PR #753 shipped mise which -t after a comment said to use mise env --json instead). Proposes piggybacking a comment/handoff poll on the existing claim heartbeat loop, feeding pending corrections into the next role prompt and gating finalize's item_done call the same way hold_reason already does. Doc only, no code changes. Agentflare-Agent: claude-code Agentflare-Branch: task/269-dispatched-agents-miss-mid-flight-item-c Agentflare-Item: 269 Agentflare-Session: 4466a268-502d-45d2-b372-46b85b9f800b Co-authored-by: shiva <shiva@gosysinfo.tech>
…ings elsewhere in the crate). The fix is complete. (#766) **What I did:** In `src/supervisor/notify.rs`, added a `summarize_reason()` helper that `notify_human_gate` now applies to the `reason` before building the Telegram message: it takes the last non-blank line of the (possibly multi-line/raw-blob) reason and caps it at 240 chars. This is the single choke point all 9 `notify_human_gate` call sites funnel through, so it fixes the item #269-style case (`cli/work_auth_expiry.rs`'s `handle_auth_expired`, which embeds the full dispatch-failure message — potentially containing `agent_launch::diagnostic_suffix`'s multi-KB raw stdout/stderr/sandbox-log tail) without touching the full-detail text that still goes to item comments/logs elsewhere. **Tests:** Added 3 unit tests for `summarize_reason` (short reason passthrough, last-line extraction from a multi-line/JSON-shaped blob, and overlong-line capping). Ran `cargo build --bin agentflare` (clean), `cargo test --bin agentflare supervisor::` (94 passed, including the 3 new ones), and `cargo clippy --bin agentflare` (no new warnings). **Concerns:** None blocking. One judgment call: I fixed this centrally in `notify_human_gate` rather than at each call site, since it's the one place all reasons converge and it doesn't affect the full-detail text already written to item comments/logs. Agentflare-Branch: task/275-human-gate-notifications-dump-raw-stdout Agentflare-Item: 275 Co-authored-by: shiva <shiva@gosysinfo.tech>
Recovers work from item #218 that never landed anywhere reachable — it was sitting uncommitted in a stash from a prior session (correctly kept off master, but never given a branch). Reviewed per item #220, one bug fixed.
Changes
HandoffRequest(types.rs) gains 6 optional fields:facts,summary,findings,decisions,files_touched,evidence.handoff.rs:factsbefore backend work, callshandle_rememberfor each, titles prefixed[sender]. Best-effort — logs and continues on error, never fails the handoff.metaJSON so the recipient gets context from the attachment without extra round-trips.Review fix
HandoffRequest.facts's#[schemars(description = ...)]was copy-pasted from the unrelatedmemorytool's action-enum text ("Single consolidated tool withactionfield (compact|context|curate|...)") — would've leaked a nonsensical description into the MCP tool schema shown to callers. Replaced with an accurate description and added thetopic_key?sub-field the code reads but the old text omitted.Verification
cargo build— cleancargo fmt --check— cleancargo clippy -D warnings— clean (only pre-existing unrelatedclaude_settingsdead_code)cargo test --workspace --lib --bins— all green, incl. 16 handoff testsE0460inskill-registry; not touched by this changeCloses item #220.
Summary by CodeRabbit