Skip to content

refactor(committor): track cleanup resources separately - #1848

Open
snawaz wants to merge 2 commits into
refactor/committor-unify-recoveryfrom
refactor/committor-cleanup-resources
Open

snawaz wants to merge 2 commits into
refactor/committor-unify-recoveryfrom
refactor/committor-cleanup-resources

Conversation

@snawaz

@snawaz snawaz commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Cleanup keeps resource identities instead of whole transaction strategies, so finished tasks and their account data can be dropped. Recovery helpers no longer build dummy strategies; commit_stage_task becomes buffer_task.

Closes #1842.

Impact

TableMania records each acquired reservation, including partial failures and cancellation. Cleanup releases repeated reservations separately and closes each buffer once after success. Failed executions keep buffers available for retry.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between b4f9c04 and 89595b7.

Files selected for processing: 19
  • committor/src/intent_engine/intent_execution_engine.rs
  • committor/src/intent_executor/cleanup_handle.rs
  • committor/src/intent_executor/executor.rs
  • committor/src/intent_executor/executor/tests.rs
  • committor/src/intent_executor/mod.rs
  • committor/src/intent_executor/strategy_executor/recovery.rs
  • committor/src/intent_executor/strategy_executor/transaction.rs
  • committor/src/intent_executor/strategy_executor/transaction/tests.rs
  • committor/src/intent_executor/strategy_executor/utils.rs
  • committor/src/intent_executor/test_utils.rs
  • committor/src/tasks/buffer_task.rs
  • committor/src/tasks/commit_delivery.rs
  • committor/src/tasks/commit_finalize_task.rs
  • committor/src/tasks/mod.rs
  • committor/src/tasks/task_strategist.rs
  • committor/src/transaction_preparator/cleanup_resources.rs
  • committor/src/transaction_preparator/delivery_preparator.rs
  • committor/src/transaction_preparator/mod.rs
  • table-mania/src/manager.rs

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 41a7b4f and b4f9c04.

Files selected for processing: 14
  • committor/src/intent_engine/intent_execution_engine.rs
  • committor/src/intent_executor/executor.rs
  • committor/src/intent_executor/executor/tests.rs
  • committor/src/intent_executor/strategy_executor/recovery.rs
  • committor/src/intent_executor/strategy_executor/transaction.rs
  • committor/src/intent_executor/strategy_executor/transaction/tests.rs
  • committor/src/intent_executor/strategy_executor/utils.rs
  • committor/src/intent_executor/test_utils.rs
  • committor/src/tasks/buffer_task.rs
  • committor/src/tasks/commit_delivery.rs
  • committor/src/tasks/commit_finalize_task.rs
  • committor/src/tasks/task_strategist.rs
  • committor/src/transaction_preparator/delivery_preparator.rs
  • committor/src/transaction_preparator/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The change replaces transaction strategies retained for cleanup with per-attempt cleanup records. Preparation records buffer tasks, ALT reservations, and uniqueness nonces. Recovery and execution no longer return cleanup-only strategies. The cleanup handle releases recorded resources.

Changes: Cleanup resource lifecycle

Layer / File(s) Summary
Track ALT reservations
committor/src/transaction_preparator/cleanup_resources.rs, table-mania/src/manager.rs
CleanupResources stores reserved ALT keys. Reservation paths record keys reserved during table reuse, creation, extension, and reconciliation.
Capture resources during preparation
committor/src/tasks/*, committor/src/transaction_preparator/*, committor/src/intent_executor/test_utils.rs, committor/src/intent_engine/intent_execution_engine.rs
Preparation records buffer cleanup tasks, uniqueness nonces, and ALT reservations. Buffer delivery variants no longer include a preparation flag.
Update recovery and execution cleanup flow
committor/src/intent_executor/strategy_executor/*, committor/src/tasks/task_strategist.rs
Recovery and strategy helpers update strategies or schedule callbacks without returning cleanup-only strategies. The executor registers cleanup records before preparation.
Release recorded resources
committor/src/intent_executor/*, committor/src/transaction_preparator/*
The report stores cleanup records for preparation attempts. The cleanup handle deduplicates buffer identities and calls the preparator, which releases ALT reservations and conditionally closes buffers.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant TransactionExecutor
  participant TransactionPreparator
  participant IntentExecutionReport
  participant CleanupHandle
  TransactionExecutor->>IntentExecutionReport: register CleanupResources
  TransactionExecutor->>TransactionPreparator: prepare with CleanupResources
  TransactionPreparator->>IntentExecutionReport: record resources acquired during preparation
  IntentExecutionReport->>CleanupHandle: pass cleanup records
  CleanupHandle->>TransactionPreparator: cleanup_resources
Loading

Possibly related issues

  • magicblock-labs/magicblock-validator#1839 — The changes track ALT reservations and release them during cleanup while making buffer closure conditional.

Possibly related PRs

Suggested labels: techdebt

Suggested reviewers: bmuddha, bzawisto

Merge Risk: Minimal · previous review b4f9c

No actionable issue was established in the cleanup-resource change; it is ready to merge after normal checks.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 32.81% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 64 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check Inconclusive Issue #1842 objectives are mostly implemented. CleanupResources (committor/src/transaction_preparator/cleanup_resources.rs) holds buffer tasks, ALT reservations, and the uniqueness nonce per prepara… Provide the following to decide this objective:
1. Confirm whether the intended rule still requires closing only buffers that completed preparation. The base prepared gate is the current rule. If the author intends to close partial writes…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: tracking cleanup resources separately from transaction strategies.
Description check Passed The description is directly related to the changes. It explains separate cleanup resources, reservation tracking, recovery changes, buffer handling, and retry behavior.
Out of Scope Changes check Passed The changed files support #1842. The production changes cover the cleanup record type, cleanup handle, delivery and transaction preparators, recovery and utility helpers, TableMania reservation trac…
Full details: Out of Scope Changes check

Explanation

The changed files support #1842. The production changes cover the cleanup record type, cleanup handle, delivery and transaction preparators, recovery and utility helpers, TableMania reservation tracking, the commit_stage_task to buffer_task rename, and the removal of reset_commit_id and dummy_revaluate_alts. The test changes adapt cleanup and reservation assertions to the compact records. No unrelated functional change was found. The buffer-closure behavior question is handled under the linked-issue assessment, not as out-of-scope work.

Full details: Linked Issues check

Explanation

Issue #1842 objectives are mostly implemented. CleanupResources (committor/src/transaction_preparator/cleanup_resources.rs) holds buffer tasks, ALT reservations, and the uniqueness nonce per preparation attempt. IntentExecutionReport keeps a cleanup vector, and dispose/junk are removed. prepare_for_delivery records resources before preparation. CleanupHandle (committor/src/intent_executor/cleanup_handle.rs) deduplicates buffers by (pubkey, commit_id) and keeps every ALT reservation, so buffers close once and reservations release separately. commit_stage_task is renamed to buffer_task. Recovery no longer returns dummy strategies. Reservation tracking in TableMania::reserve_pubkeys records keys per attempt.

One acceptance criterion is not established. The base CleanupTask::from_commit_finalize (commit_stage_task.rs) closed only deliveries with prepared: true. The head version (buffer_task.rs) closes every StateInBuffer and DiffInBuffer task. Cleanup records are taken before preparation runs, so a failed or partially written attempt can add buffers that were never initialized. These buffers stay in report.cleanup and are closed on a later successful attempt with close_buffers = true. The issue requires retaining the existing buffer-closure rules. The PR description says buffer closure follows the current success/failure rules. This change alters the success-path rule. The code and tests do not show whether closing an uninitialized buffer fails, and no test in the reviewed evidence covers success after a failed preparation attempt.

Resolution

Provide the following to decide this objective:

  1. Confirm whether the intended rule still requires closing only buffers that completed preparation. The base prepared gate is the current rule. If the author intends to close partial writes and failed-attempt buffers on success, state that change against the issue text.
  2. Confirm the behavior of the buffer close instruction on a buffer PDA that was never initialized. State whether it returns an error that affects the intent result.
  3. Point to a test that runs a failed preparation attempt followed by a successful retry, and asserts which buffers are closed.
Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@snawaz
snawaz marked this pull request as ready for review October 26, 2026 16:49
@snawaz
snawaz force-pushed the refactor/committor-cleanup-resources branch 2 times, most recently from cf236e6 to c9f4e1e Compare October 26, 2026 18:40
@snawaz
snawaz force-pushed the refactor/committor-cleanup-resources branch from c9f4e1e to dfd29ac Compare October 26, 2026 18:45
@snawaz
snawaz force-pushed the refactor/committor-cleanup-resources branch 2 times, most recently from 47f5d6a to b4f9c04 Compare October 26, 2026 20:18
@snawaz
snawaz force-pushed the refactor/committor-cleanup-resources branch from b4f9c04 to 0e487cb Compare October 28, 2026 10:17
Replace retained transaction strategies with compact cleanup records for
each preparation attempt. Records contain buffer identities, acquired ALT
reservations, and the uniqueness nonce used by that attempt. Keep them in
the execution report before entering cancellable preparation futures.

Release executable tasks and their account payloads after use. Recovery
helpers now update remaining work without cloning tasks or returning dummy
strategies for cleanup. Rename commit_stage_task to buffer_task to reflect
its buffer preparation and closure role.

Record ALT acquisitions inside TableMania as they occur, including partial
failure and cancellation. Separate attempts retain separate reservations
even when their keys match, so cleanup cannot under-release repeated
reservations or release a key that an attempt never acquired.

Close each recorded buffer at most once after successful intent execution,
using its recorded nonce. Failed execution still releases ALT reservations
without closing buffers that another attempt could reuse. Cleanup no longer
rescans executable tasks to recover resource identities.

Adapt the existing lifecycle, nonce-recovery, and cleanup tests. Extend the
recovery regression to exercise real TableMania reference counts across
repeated reservations, partial failure, and cancellation while preserving
another intent's reservation. Check buffer closure and nonce association
through the cleanup handle.

Validation: make fmt; make ci-fmt; cargo check for the committor and TableMania
packages with --tests; the recovery_preserves_progress_and_resources test;
cargo clippy --workspace --all-targets -- -D warnings; cargo test --workspace
(nextest is unavailable locally); git diff --check.

Closes #1842.
Remove the buffer prepared flags now that cleanup records retain resource identities before preparation begins. Delete PreparationTask::done, its mutable-reference lifetime, and the commit-ID reset wrapper; recovery can update the commit ID directly.

Make preparation borrow transaction strategies and tasks immutably while continuing to record cleanup resources separately. Reuse the validated v1 message after delivery preparation instead of assembling it a second time. Remove the redundant explicit drop before the runner replaces its current strategy or returns.

Adapt the existing mocks and buffer fixtures to immutable preparation. Preserve real reservation-count, partial-failure, cancellation, buffer-deduplication, and callback recovery coverage.

Validation: cargo fmt --check; cargo check -p magicblock-committor-service --tests; the focused recovery_preserves_progress_and_resources test; cargo clippy --workspace --all-targets -- -D warnings; cargo test --workspace (527 passed, none failed or ignored); git diff --check.
@snawaz
snawaz force-pushed the refactor/committor-cleanup-resources branch from 0e487cb to 89595b7 Compare October 31, 2026 21:17
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.

Track committor cleanup resources separately from transaction strategies

1 participant