Skip to content

Conversation

@taco-paco
Copy link
Contributor

@taco-paco taco-paco commented Nov 17, 2025

feat: parallelize task cleanup
feat: add metrics for task preparation & alt preparation

Summary by CodeRabbit

  • Performance Improvements

    • Increased execution timeout, parallelized task preparation, and moved cleanup to background tasks for improved responsiveness.
  • Monitoring & Observability

    • Added metrics for intent scheduling and task/ALT preparation timings.
    • Improved logging to include more detailed debug representations.
  • Refactor

    • Task labeling/interfaces updated to support metrics and the new preparation flow.
  • Tests

    • Added short waits in integration tests to stabilize asynchronous assertions.

feat: add metrics for task preparation & alt preparation
@github-actions
Copy link

github-actions bot commented Nov 17, 2025

Manual Deploy Available

You can trigger a manual deploy of this PR branch to testnet:

Deploy to Testnet 🚀

Alternative: Comment /deploy on this PR to trigger deployment directly.

⚠️ Note: Manual deploy requires authorization. Only authorized users can trigger deployments.

Comment updated automatically when the PR is synchronized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Walkthrough

Adds committor intent metrics and timing instrumentation, requires Clone for transaction preparators, moves cleanup to a spawned background task, implements LabelValue for task types and updates BaseTask to require it, parallelizes delivery preparation, and increases execution timing threshold and debug logging.

Changes

Cohort / File(s) Summary
Metrics Infrastructure
magicblock-metrics/src/metrics/mod.rs
Add COMMITTOR_INTENTS_COUNT counter and two histograms (COMMITTOR_INTENT_TASK_PREPARATION_TIME, COMMITTOR_INTENT_ALT_PREPARATION_TIME); register them and expose APIs to increment and observe timers.
Executor Generic Bounds
magicblock-committor-service/src/intent_executor/mod.rs, .../single_stage_executor.rs, .../two_stage_executor.rs
Strengthen T bounds from TransactionPreparator to TransactionPreparator + Clone in IntentExecutorImpl, SingleStageExecutor, and TwoStageExecutor impls.
Cleanup Refactor
magicblock-committor-service/src/intent_executor/mod.rs
Replace inline cleanup with a new private spawn_cleanup_task(&self, junk: Vec<TransactionStrategy>) that spawns a background task and clones preparator/authority for cleanup. Removed inline cleanup blocks and an old TODO comment.
Task Labeling (LabelValue)
magicblock-committor-service/src/tasks/mod.rs, .../args_task.rs, .../buffer_task.rs
Require LabelValue on BaseTask; implement LabelValue for ArgsTask (returns `"args_commit"
Execution Metrics / Logging
magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs
Increase execution time threshold from 2.0 to 5.0 seconds and change logging to print the Debug representation of results.
Delivery Preparation Instrumentation & Parallelism
magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs
Add timers around per-task and ALT preparation, run per-task prep and reallocations in parallel using spawned async tasks/try_join_all, and initialize buffer account before concurrent reallocations.
Integration Test Timing
test-integration/test-committor-service/tests/test_intent_executor.rs
Insert tokio::time::sleep(Duration::from_secs(1)).await delays after async operations in multiple tests to allow state propagation before assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Scheduler as Scheduler/Caller
    participant Executor as IntentExecutorImpl
    participant Preparator as DeliveryPreparator
    participant Cleanup as Spawned Cleanup Task

    Scheduler->>Executor: start single/two-stage execution
    Executor->>Preparator: prepare_for_delivery(tasks) (timed)
    alt per-task & ALT prep parallel
        Preparator->>Preparator: spawn per-task prep async (timed, labeled)
        Preparator->>Preparator: spawn ALT prep async (timed)
        Preparator-->>Preparator: await try_join_all for reallocs
    end
    Executor->>Cleanup: spawn_cleanup_task(junk)  note right of Cleanup "#DDDDFF": background task
    Scheduler-->>Executor: receive result (Debug logged, threshold 5s)
    Cleanup->>Cleanup: perform cleanup using cloned preparator & authority
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Inspect metric registration and label usage for correctness and naming collisions.
  • Verify concurrency/error handling around try_join_all and the new parallel prep paths in delivery_preparator.rs.
  • Confirm Clone bounds are acceptable for all callers and that spawned cleanup clones do not introduce resource/race issues.
  • Check tests with added sleeps for flakiness or timing assumptions.

Possibly related PRs

Suggested reviewers

  • thlorenz
  • GabrielePicco
  • bmuddha

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: parallelize task cleanup' accurately reflects a primary change (background cleanup via spawn_cleanup_task), but the PR also significantly adds metrics for task and ALT preparation, which is not conveyed in the title.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/committor/long-intents

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ded9c50 and 9f5c613.

📒 Files selected for processing (9)
  • magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs (2 hunks)
  • magicblock-committor-service/src/intent_executor/mod.rs (5 hunks)
  • magicblock-committor-service/src/intent_executor/single_stage_executor.rs (1 hunks)
  • magicblock-committor-service/src/intent_executor/two_stage_executor.rs (1 hunks)
  • magicblock-committor-service/src/tasks/args_task.rs (2 hunks)
  • magicblock-committor-service/src/tasks/buffer_task.rs (2 hunks)
  • magicblock-committor-service/src/tasks/mod.rs (2 hunks)
  • magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs (3 hunks)
  • magicblock-metrics/src/metrics/mod.rs (5 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-11-07T13:20:13.793Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: magicblock-processor/src/scheduler/coordinator.rs:227-238
Timestamp: 2025-11-07T13:20:13.793Z
Learning: In magicblock-processor's ExecutionCoordinator (scheduler/coordinator.rs), the `account_contention` HashMap intentionally does not call `shrink_to_fit()`. Maintaining slack capacity is beneficial for performance by avoiding frequent reallocations during high transaction throughput. As long as empty entries are removed from the map (which `clear_account_contention` does), the capacity overhead is acceptable.

Applied to files:

  • magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs
📚 Learning: 2025-10-14T09:56:14.047Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 564
File: test-integration/programs/flexi-counter/src/processor/call_handler.rs:122-125
Timestamp: 2025-10-14T09:56:14.047Z
Learning: The file test-integration/programs/flexi-counter/src/processor/call_handler.rs contains a test smart contract used for integration testing, not production code.

Applied to files:

  • magicblock-committor-service/src/tasks/args_task.rs
📚 Learning: 2025-11-07T13:09:52.253Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: test-kit/src/lib.rs:275-0
Timestamp: 2025-11-07T13:09:52.253Z
Learning: In test-kit, the transaction scheduler in ExecutionTestEnv is not expected to shut down during tests. Therefore, using `.unwrap()` in test helper methods like `schedule_transaction` is acceptable and will not cause issues in the test environment.

Applied to files:

  • magicblock-committor-service/src/intent_executor/mod.rs
🧬 Code graph analysis (5)
magicblock-committor-service/src/tasks/buffer_task.rs (3)
magicblock-committor-service/src/intent_executor/mod.rs (1)
  • value (74-82)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • value (171-178)
magicblock-committor-service/src/intent_executor/error.rs (1)
  • value (105-112)
magicblock-metrics/src/metrics/mod.rs (3)
magicblock-committor-service/src/tasks/args_task.rs (1)
  • task_type (147-154)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
  • task_type (123-127)
magicblock-committor-service/src/tasks/mod.rs (1)
  • task_type (90-90)
magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs (1)
magicblock-metrics/src/metrics/mod.rs (2)
  • observe_committor_intent_task_preparation_time (434-442)
  • observe_committor_intent_alt_preparation_time (444-446)
magicblock-committor-service/src/tasks/args_task.rs (3)
magicblock-committor-service/src/intent_executor/mod.rs (1)
  • value (74-82)
magicblock-committor-service/src/tasks/buffer_task.rs (1)
  • value (146-150)
magicblock-committor-service/src/intent_executor/error.rs (1)
  • value (105-112)
magicblock-committor-service/src/intent_executor/mod.rs (1)
magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs (1)
  • spawn (98-103)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build Project
  • GitHub Check: run_make_ci_test
  • GitHub Check: run_make_ci_lint
🔇 Additional comments (15)
magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs (2)

297-297: LGTM: Execution time threshold increased appropriately.

The threshold increase from 2.0s to 5.0s will reduce log noise while still flagging genuinely slow executions.


312-313: LGTM: Enhanced logging with Debug representation.

Using {:?} provides more detailed execution information compared to the previous success/error string conversion.

magicblock-committor-service/src/tasks/buffer_task.rs (1)

145-151: LGTM: Clean LabelValue implementation for metrics.

The implementation correctly labels buffer tasks for metric collection, consistent with the pattern used in ArgsTask and ExecutionOutput.

magicblock-committor-service/src/tasks/args_task.rs (1)

170-179: LGTM: Comprehensive LabelValue implementation for all task types.

The implementation provides distinct, well-named labels for each ArgsTaskType variant, enabling fine-grained metrics collection.

magicblock-committor-service/src/intent_executor/two_stage_executor.rs (1)

26-26: LGTM: Clone bound addition supports background cleanup.

The Clone requirement enables the new parallel cleanup pattern introduced in the executor module.

magicblock-committor-service/src/intent_executor/single_stage_executor.rs (1)

27-27: LGTM: Clone bound addition aligns with executor pattern.

Consistent with the Clone requirement in TwoStageExecutor, enabling background cleanup tasks.

magicblock-committor-service/src/tasks/mod.rs (1)

13-13: LGTM: LabelValue integration enables task-level metrics.

The trait bound addition to BaseTask provides a clean abstraction for metric labeling, with all implementors (ArgsTask, BufferTask) already providing implementations.

Also applies to: 54-54

magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs (3)

70-81: LGTM: Task preparation timing instrumentation added.

The metrics integration correctly measures per-task preparation time using the LabelValue trait for task-type labeling.


84-93: LGTM: ALT preparation timing instrumentation added.

The metrics correctly capture address lookup table preparation duration.


236-245: LGTM: Initialization parallelization improves performance.

The refactored logic correctly sequences initialization first, then parallelizes reallocation operations using try_join_all, improving buffer preparation throughput.

magicblock-committor-service/src/intent_executor/mod.rs (3)

105-105: LGTM: Clone bound supports asynchronous cleanup pattern.

The Clone requirement on TransactionPreparator enables the new background cleanup implementation.


740-740: LGTM: Clone bound in trait implementation.

Consistent with the updated type bounds in IntentExecutorImpl.


652-675: The review comment is incorrect—the code already has synchronization for this scenario.

The race condition mentioned in the code comment (lines 652-656) is intentionally handled via error handling that catches AccountAlreadyInitializedError and logs it as informational. When a buffer is already initialized, the task's preparation state is switched to Cleanup, which ensures the stale buffer is removed before the next operation.

This error-catch-and-cleanup pattern serves as the synchronization mechanism. The scenario is not a silent data corruption risk—it's an expected condition that the code explicitly handles.

Likely an incorrect or invalid review comment.

magicblock-metrics/src/metrics/mod.rs (2)

281-288: New committor metrics registration looks correct.

All newly added committor metrics are properly wired into the register! macro, so they’ll be exposed once register() is called. No issues here.


395-402: Helpers for COMMITTOR_INTENTS_COUNT are straightforward and consistent.

The increment helpers are thin, type-safe wrappers over the counter and match the style of the rest of the module. No issues.

# Conflicts:
#	test-integration/test-committor-service/tests/test_intent_executor.rs
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2019491 and 254652a.

📒 Files selected for processing (1)
  • test-integration/test-committor-service/tests/test_intent_executor.rs (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-07T13:09:52.253Z
Learnt from: bmuddha
Repo: magicblock-labs/magicblock-validator PR: 589
File: test-kit/src/lib.rs:275-0
Timestamp: 2025-11-07T13:09:52.253Z
Learning: In test-kit, the transaction scheduler in ExecutionTestEnv is not expected to shut down during tests. Therefore, using `.unwrap()` in test helper methods like `schedule_transaction` is acceptable and will not cause issues in the test environment.

Applied to files:

  • test-integration/test-committor-service/tests/test_intent_executor.rs
📚 Learning: 2025-10-14T09:56:14.047Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 564
File: test-integration/programs/flexi-counter/src/processor/call_handler.rs:122-125
Timestamp: 2025-10-14T09:56:14.047Z
Learning: The file test-integration/programs/flexi-counter/src/processor/call_handler.rs contains a test smart contract used for integration testing, not production code.

Applied to files:

  • test-integration/test-committor-service/tests/test_intent_executor.rs

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.

2 participants