Skip to content

feat: Implement pending_corrections: heartbeat comment poll + finalize gate (item #269's proposal) - #756

Merged
getappz merged 1 commit into
masterfrom
task/270-implement-pending-corrections-heartbeat
Sep 17, 2026
Merged

getappz merged 1 commit into
masterfrom
task/270-implement-pending-corrections-heartbeat

Conversation

@getappz

@getappz getappz commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Summary

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.


Opened by claude-code on flared:51bb8de6c33b for item #270 via agentflare.

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

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 3 included reviews currently available. Your 47 included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: e5e595c8-dde8-464c-9116-183e9dae9ed0

📥 Commits

Reviewing files that changed from the base of the PR and between 01c2d60 and 2d803e0.

📒 Files selected for processing (3)
  • src/work_item_pipeline.rs
  • src/work_item_pipeline/sdd_loop_tests.rs
  • src/work_item_pipeline/tests.rs

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

@getappz
getappz merged commit 83d96e4 into master Sep 17, 2026
17 checks passed
@getappz
getappz deleted the task/270-implement-pending-corrections-heartbeat branch September 17, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant