Skip to content

feat(mcp): knowledge fact import + session snapshot in flare_handoff - #269

Merged
getappz merged 3 commits into
masterfrom
fix/handoff-facts-import
Jul 19, 2026
Merged

getappz merged 3 commits into
masterfrom
fix/handoff-facts-import

Conversation

@getappz

@getappz getappz commented Jul 19, 2026 •

Copy link
Copy Markdown
Owner

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:

  • Fact import: iterates facts before backend work, calls handle_remember for each, titles prefixed [sender]. Best-effort — logs and continues on error, never fails the handoff.
  • Session snapshot: embeds the 5 snapshot fields into the asset's meta JSON so the recipient gets context from the attachment without extra round-trips.

Review fix

HandoffRequest.facts's #[schemars(description = ...)] was copy-pasted from the unrelated memory tool's action-enum text ("Single consolidated tool with action field (compact|context|curate|...)") — would've leaked a nonsensical description into the MCP tool schema shown to callers. Replaced with an accurate description and added the topic_key? sub-field the code reads but the old text omitted.

Verification

  • cargo build — clean
  • cargo fmt --check — clean
  • cargo clippy -D warnings — clean (only pre-existing unrelated claude_settings dead_code)
  • cargo test --workspace --lib --bins — all green, incl. 16 handoff tests
    • workspace doctests hit a pre-existing, unrelated stale-cache E0460 in skill-registry; not touched by this change

Closes item #220.

Summary by CodeRabbit

  • New Features
    • Handoffs can now carry session context (summary, findings, decisions, files touched, and evidence) and include it directly in handoff metadata.
    • Handoffs can also accept a set of provided facts to import into the recipient’s memory for smoother continuity.
  • Reliability
    • Fact/memory-import failures are handled best-effort and no longer interrupt or fail the handoff.

Recovers work that was stashed instead of landed (item #218/#220 review).
Fixes a copy-pasted schema description on HandoffRequest.facts.
@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: af9bb447-c09b-45db-af1c-e10d47d96a43

📥 Commits

Reviewing files that changed from the base of the PR and between 82d3a09 and 581b89f.

📒 Files selected for processing (2)
  • src/mcp_server.rs
  • src/mcp_server/types.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/mcp_server/types.rs
  • src/mcp_server.rs

📝 Walkthrough

Walkthrough

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

Changes

Handoff session context enrichment

Layer / File(s) Summary
Handoff request contract
src/mcp_server/types.rs, src/mcp_server.rs
HandoffRequest accepts optional facts and session snapshot fields, and the tool description documents their use.
Fact import during handoff
src/mcp_server/handoff.rs
Supplied facts are mapped to RememberInput values and written to recipient memory without failing the handoff when a write errors.
Session snapshot attachment metadata
src/mcp_server/handoff.rs
Provided summary, findings, decisions, files-touched, and evidence fields are conditionally added to attachment metadata.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and matches the fact import and session snapshot changes.
Description check ✅ Passed The description covers the summary, review fix, and verification results, with only the reviewer-notes section not fully formalized.
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 fix/handoff-facts-import

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

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5003210 and 1703171.

📒 Files selected for processing (3)
  • src/mcp_server.rs
  • src/mcp_server/handoff.rs
  • src/mcp_server/types.rs

Comment thread src/mcp_server.rs Outdated
Comment thread src/mcp_server/handoff.rs Outdated
Comment thread src/mcp_server/handoff.rs Outdated
@getappz
getappz merged commit f536b96 into master Jul 19, 2026
17 checks passed
@getappz
getappz deleted the fix/handoff-facts-import branch July 19, 2026 19:18
getappz pushed a commit that referenced this pull request Sep 17, 2026
…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
getappz added a commit that referenced this pull request Sep 17, 2026
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>
getappz pushed a commit that referenced this pull request Sep 17, 2026
…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
getappz pushed a commit that referenced this pull request Sep 17, 2026
…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
getappz pushed a commit that referenced this pull request Sep 17, 2026
…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
getappz added a commit that referenced this pull request Sep 17, 2026
…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>
getappz added a commit that referenced this pull request Sep 17, 2026
…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>
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