Skip to content

fix(proof): bind receipt replanning to current head - #837

Merged
EffortlessSteven merged 25 commits into
mainfrom
codex/issue804-proof-replan
Aug 5, 2026
Merged

EffortlessSteven merged 25 commits into
mainfrom
codex/issue804-proof-replan

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Bind receipt-driven proof replanning and terminalization to the exact reviewed head.

The current broker already replans after focused receipts and shares equivalent request evidence. Before this repair, receipt reuse was keyed by task/request identity alone, so a receipt from an earlier PR head could incorrectly satisfy current-head work or prevent its execution.

Scope

  • require current-head receipts for initial, seeded, and follow-up portfolio reuse;
  • require current-head receipts before the unreceipted-work broker starts;
  • require current-head receipts when terminalizing final proof requests and writing artifacts;
  • add stale-head regression tests for portfolio selection and terminalization.

No new proof command family, GitHub posting, gate-authority change, threshold change, suppression, or unrelated compiler work is included.

Proof

  • focused broker/planner/main regressions: pass;
  • cargo test --locked --bin ub-review -- --test-threads=4: 806 passed;
  • cargo test --workspace --all-targets --locked: pass (806 binary, 52 integration with 1 ignored, 4 docs, 3 shared-context, 21 xtask);
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass;
  • cargo doc --workspace --no-deps --locked: pass;
  • cargo xtask policy-check: pass, with the pre-existing overdue review-date warning;
  • artifact verifier self-test: pass;
  • git diff --check: pass.

The hosted exact-head gate and RIPR remain required before merge.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes
    • Proof requests now validate and match receipts only against the current diff head, preventing stale receipts from satisfying or terminalizing active requests.
    • Proof portfolio selection and seeded execution now ignore out-of-date receipt evidence.
    • Focused test/build planning now preserves approved Cargo passthrough arguments and merges candidates strictly by task ID.
    • Expanded coverage for current-head matching, stale-receipt rejection, terminalization behavior, and focused-task command handling.

Walkthrough

Proof receipt validation now scopes terminalization, portfolio selection, seeded requests, and receipt checks to the current diff head. Focused proof planning records budget status for all candidates. v2 normalization preserves Cargo passthrough arguments.

Changes

Proof receipt handling

Layer / File(s) Summary
Head-aware request terminalization
src/proof/planner.rs
terminalize_proof_requests matches receipts by request ID and case-insensitive head.
Head-aware portfolio and seeded selection
src/proof/broker.rs
Portfolio selection and unreceipted-task checks exclude receipts from other heads. Candidate merging uses task IDs.
Focused candidate planning
src/proof/tasks.rs
Focused test and build plans retain candidates and mark budget-selected plans as planned or deferred_by_budget. Cargo passthrough arguments remain unchanged.
Diff-head integration and validation
src/main.rs, src/proof/planner.rs, src/proof/broker.rs
Callers pass the current head. Tests cover stale-head rejection, current-head acceptance, candidate identity, and budget behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Diff
  participant ProofBroker
  participant ProofPlanner
  participant Receipts
  Diff->>ProofBroker: provide current diff.head
  ProofBroker->>Receipts: filter receipts by head
  ProofBroker->>ProofPlanner: pass current-head portfolio evidence
  ProofPlanner->>Receipts: terminalize requests by ID and head
  Receipts-->>ProofPlanner: current-head receipt status
Loading

Possibly related issues

  • EffortlessMetrics/ripr-swarm issue 2334 — Covers current-head receipt filtering and replay validation.

Possibly related PRs

Suggested labels: enhancement

Poem

A rabbit checks each proof head,
Old receipts leave the thread.
New candidates wait in line,
Budget marks their status fine.
Cargo arguments stay aligned.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes binding proof receipt reuse and replanning to the current reviewed head.
Description check ✅ Passed The description explains the change, scope, verification results, CI requirements, and remaining merge conditions.
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 codex/issue804-proof-replan

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.41003% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/proof/broker.rs 99.26% 2 Missing ⚠️
src/main.rs 96.42% 1 Missing ⚠️
src/proof/tasks.rs 99.67% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot added the enhancement New feature or request label Aug 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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/proof/broker.rs`:
- Around line 1000-1023: Update has_unreceipted_proof_request_tasks to call
current_head_receipts once, bind the resulting collection, and pass it by
slice/reference to both unreceipted_focused_test_tasks and
unreceipted_focused_build_tasks instead of recomputing and cloning the same
receipts.

In `@src/proof/planner.rs`:
- Around line 1690-1728: Extend
terminalization_does_not_use_receipt_from_another_head with a stale-only
scenario before the final call that moves request and receipt: invoke
terminalize_proof_requests using only the previous-head receipt, then assert the
request status is deferred rather than satisfied. Preserve the existing
assertions for the current-head receipt case.
🪄 Autofix

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0f6bf3c1-7590-4056-94b6-c3bdaf5f51eb

📥 Commits

Reviewing files that changed from the base of the PR and between 1510d29 and 147fa3c.

📒 Files selected for processing (3)
  • src/main.rs
  • src/proof/broker.rs
  • src/proof/planner.rs

Comment thread src/proof/broker.rs Resolved
Comment thread src/proof/planner.rs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/proof/tasks.rs (1)

720-723: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Compare the command specifications.

These assertions only confirm that both tasks have command specifications. The task identity does not contain Cargo passthrough arguments. The test can pass if one path removes -- --nocapture.

Compare the head.argv and base_plus_tests.argv values from both command specifications.

Proposed test assertion
-        assert_eq!(
-            from_v1[0].command_specs.is_some(),
-            from_v2[0].command_specs.is_some()
-        );
+        assert_eq!(
+            from_v1[0].command_specs.as_ref().map(|specs| {
+                (&specs.head.argv, &specs.base_plus_tests.argv)
+            }),
+            from_v2[0].command_specs.as_ref().map(|specs| {
+                (&specs.head.argv, &specs.base_plus_tests.argv)
+            }),
+            "v1 and v2 command specifications must preserve Cargo passthrough arguments"
+        );
🤖 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/proof/tasks.rs` around lines 720 - 723, Strengthen the task comparison
assertion by comparing the actual command arguments rather than only
command_specs presence: when command specifications exist, compare both
head.argv and base_plus_tests.argv between from_v1[0] and from_v2[0]. Preserve
the existing option-presence check while ensuring Cargo passthrough arguments
such as --nocapture cannot be omitted unnoticed.
♻️ Duplicate comments (1)
src/proof/planner.rs (1)

1725-1734: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add stale-only behavior assertions.

Both tests include a current-head receipt. That receipt makes the final result successful. Add a stale-only invocation before the mixed-receipt invocation.

  • src/proof/planner.rs#L1725-L1734: terminalize with only receipt and assert deferred.
  • src/proof/broker.rs#L1504-L1518: select with only stale_receipt and assert the task remains selected instead of answered.
🤖 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/proof/planner.rs` around lines 1725 - 1734, Add stale-only assertions
before the existing mixed-receipt checks: in src/proof/planner.rs lines
1725-1734, invoke terminalization with only receipt and assert the result is
deferred; in src/proof/broker.rs lines 1504-1518, invoke selection with only
stale_receipt and assert the task remains selected rather than answered.
Preserve the existing mixed current-head receipt assertions afterward.
🤖 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/proof/planner.rs`:
- Around line 1725-1734: The new unit tests are located in child-module tests
blocks instead of the designated root test module. Move the head-aware
terminalization assertions from src/proof/planner.rs lines 1725-1734, the
head-aware portfolio assertions from src/proof/broker.rs lines 1504-1518, and
the current-head filtering, candidate-merging, and seeded-request tests from
src/proof/broker.rs lines 1574-1695 into the mod tests block at the bottom of
src/main.rs, preserving their coverage and required imports or helpers.

---

Outside diff comments:
In `@src/proof/tasks.rs`:
- Around line 720-723: Strengthen the task comparison assertion by comparing the
actual command arguments rather than only command_specs presence: when command
specifications exist, compare both head.argv and base_plus_tests.argv between
from_v1[0] and from_v2[0]. Preserve the existing option-presence check while
ensuring Cargo passthrough arguments such as --nocapture cannot be omitted
unnoticed.

---

Duplicate comments:
In `@src/proof/planner.rs`:
- Around line 1725-1734: Add stale-only assertions before the existing
mixed-receipt checks: in src/proof/planner.rs lines 1725-1734, invoke
terminalization with only receipt and assert the result is deferred; in
src/proof/broker.rs lines 1504-1518, invoke selection with only stale_receipt
and assert the task remains selected rather than answered. Preserve the existing
mixed current-head receipt assertions afterward.
🪄 Autofix

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 23da2af7-7069-4b1c-9c50-13c752ca9889

📥 Commits

Reviewing files that changed from the base of the PR and between 147fa3c and b9b0d75.

📒 Files selected for processing (4)
  • src/main.rs
  • src/proof/broker.rs
  • src/proof/planner.rs
  • src/proof/tasks.rs

Comment thread src/proof/planner.rs
Comment on lines +1725 to +1734
assert!(receipt_matches_request_on_head(
&current_receipt,
"request-current-head",
"current-head",
));
assert!(!receipt_matches_request_on_head(
&receipt,
"request-current-head",
"current-head",
));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Move the new unit tests to src/main.rs.

These assertions are in child-module mod tests blocks. Move unit-test coverage to the mod tests block at the bottom of src/main.rs.

  • src/proof/planner.rs#L1725-L1734: move the head-aware terminalization test assertions to src/main.rs.
  • src/proof/broker.rs#L1504-L1518: move the head-aware portfolio test assertions to src/main.rs.
  • src/proof/broker.rs#L1574-L1695: move the current-head filtering, candidate-merging, and seeded-request unit tests to src/main.rs.

As per coding guidelines, “Integration tests live in tests/cli.rs; unit tests in the mod tests at the bottom of src/main.rs.”

📍 Affects 2 files
  • src/proof/planner.rs#L1725-L1734 (this comment)
  • src/proof/broker.rs#L1504-L1518
  • src/proof/broker.rs#L1574-L1695
🤖 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/proof/planner.rs` around lines 1725 - 1734, The new unit tests are
located in child-module tests blocks instead of the designated root test module.
Move the head-aware terminalization assertions from src/proof/planner.rs lines
1725-1734, the head-aware portfolio assertions from src/proof/broker.rs lines
1504-1518, and the current-head filtering, candidate-merging, and seeded-request
tests from src/proof/broker.rs lines 1574-1695 into the mod tests block at the
bottom of src/main.rs, preserving their coverage and required imports or
helpers.

Source: Coding guidelines

@EffortlessSteven
EffortlessSteven merged commit 7b112d9 into main Aug 5, 2026
3 of 4 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/proof/tasks.rs (1)

760-797: 📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Move the added unit tests to src/main.rs.

The added tests are unit tests. Put them in the mod tests at the bottom of src/main.rs, as required by the repository test layout.

As per coding guidelines, “Integration tests live in tests/cli.rs; unit tests in the mod tests at the bottom of src/main.rs.”

Also applies to: 800-1075

🤖 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/proof/tasks.rs` around lines 760 - 797, Move the newly added unit tests
out of `src/proof/tasks.rs` and into the `mod tests` block at the bottom of
`src/main.rs`, following the repository’s test layout. Keep the existing
assertions and coverage unchanged, and preserve the helper symbols they exercise
such as `focused_test_candidates_from_requests`,
`focused_test_candidates_from_v2`, and `v2_focused_test_request` by relocating
the test code rather than rewriting it.

Source: Coding guidelines

♻️ Duplicate comments (1)
src/proof/planner.rs (1)

1735-1749: 📐 Maintainability & Code Quality | 🟠 Major

Keep the new head-scoped regression tests in the root test module.

Move the containing tests and their new assertions to src/main.rs:

  • src/proof/planner.rs#L1735-L1749: move terminalization_does_not_use_receipt_from_another_head.
  • src/proof/broker.rs#L1520-L1530: move portfolio_does_not_reuse_receipt_from_another_head.

As per coding guidelines, “Integration tests live in tests/cli.rs; unit tests in the mod tests at the bottom of src/main.rs.”

🤖 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/proof/planner.rs` around lines 1735 - 1749, The head-scoped regression
test terminalization_does_not_use_receipt_from_another_head, including its new
assertions, should be moved from src/proof/planner.rs#L1735-L1749 into the mod
tests section of src/main.rs. Also move
portfolio_does_not_reuse_receipt_from_another_head from
src/proof/broker.rs#L1520-L1530 into the same root test module, preserving both
tests’ behavior and assertions.

Source: Coding guidelines

🤖 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/proof/tasks.rs`:
- Around line 132-145: Update the planning flow around
focused_test_tasks_from_diff so budget-rejected candidates do not prevent later
candidates from being evaluated. Continue scanning candidate_tasks after a
rejection, and ensure later candidates that satisfy the remaining caps are added
to plans with the appropriate candidate_plan_status instead of being marked
deferred_by_budget solely because an earlier candidate failed.

---

Outside diff comments:
In `@src/proof/tasks.rs`:
- Around line 760-797: Move the newly added unit tests out of
`src/proof/tasks.rs` and into the `mod tests` block at the bottom of
`src/main.rs`, following the repository’s test layout. Keep the existing
assertions and coverage unchanged, and preserve the helper symbols they exercise
such as `focused_test_candidates_from_requests`,
`focused_test_candidates_from_v2`, and `v2_focused_test_request` by relocating
the test code rather than rewriting it.

---

Duplicate comments:
In `@src/proof/planner.rs`:
- Around line 1735-1749: The head-scoped regression test
terminalization_does_not_use_receipt_from_another_head, including its new
assertions, should be moved from src/proof/planner.rs#L1735-L1749 into the mod
tests section of src/main.rs. Also move
portfolio_does_not_reuse_receipt_from_another_head from
src/proof/broker.rs#L1520-L1530 into the same root test module, preserving both
tests’ behavior and assertions.
🪄 Autofix

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 618006be-8e1d-4a71-ab03-a9a7ae2001e9

📥 Commits

Reviewing files that changed from the base of the PR and between b9b0d75 and c34df47.

📒 Files selected for processing (3)
  • src/proof/broker.rs
  • src/proof/planner.rs
  • src/proof/tasks.rs

Comment thread src/proof/tasks.rs
Comment on lines +132 to +145
let planned_ids = focused_test_tasks_from_diff(diff, proof_requests, budget)
.into_iter()
.map(|task| task.id)
.collect::<BTreeSet<_>>();
let candidate_tasks = focused_test_candidates_from_diff(diff, proof_requests);
let mut plans = Vec::with_capacity(candidate_tasks.len());
for task in candidate_tasks {
let status = candidate_plan_status(planned_ids.contains(&task.id));
plans.extend(std::iter::once(focused_proof_plan_for_task(
task,
budget,
status,
"candidate recorded for portfolio accounting; execution is budget-gated".to_owned(),
)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Continue after a candidate exceeds a budget cap.

focused_test_tasks_from_diff stops at its first rejected candidate. This function then marks every later candidate as deferred_by_budget.

With one selected file, a candidate for a second file can fail max_focused_test_files, while a later candidate for the selected file can still fit all caps. Keep scanning after a rejection so the later candidate can be planned.

Proposed fix
         if !focused_proof_budget_allows_next(
             tasks.len(),
             &files,
             &task.file,
             estimated_seconds,
             task_timeout_sec,
             task.mode.command_count(),
             budget,
         ) {
-            return tasks;
+            continue;
         }
🤖 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/proof/tasks.rs` around lines 132 - 145, Update the planning flow around
focused_test_tasks_from_diff so budget-rejected candidates do not prevent later
candidates from being evaluated. Continue scanning candidate_tasks after a
rejection, and ensure later candidates that satisfy the remaining caps are added
to plans with the appropriate candidate_plan_status instead of being marked
deferred_by_budget solely because an earlier candidate failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant