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

  • Refactor

    • Execution workflow now parallelizes preparation steps for improved efficiency
    • Background cleanup operations introduced to optimize performance
  • Chores

    • Execution time threshold increased from 2.0 to 5.0 seconds
    • Enhanced observability metrics for task and intent tracking

✏️ Tip: You can customize this high-level summary in your review settings.

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

Walkthrough

This pull request updates the committor service with performance metrics and architectural improvements. It increases the execution time threshold to 5.0 seconds, changes debug logging, and adds Clone trait bounds to the TransactionPreparator generic parameter. Background cleanup task spawning replaces synchronous cleanup in execution flows. The BaseTask trait now requires LabelValue for metric labeling. New LabelValue implementations are added for ArgsTask and BufferTask. Task preparation and ALT preparation are wrapped with performance timing instrumentation, and initialization with parallelized reallocation patterns are introduced. New Committor metrics including counters and histograms for intent tracking and preparation timing are registered.

Possibly related PRs

  • #607: Modifies execution_metrics in intent_execution_engine.rs to update timing behavior and logging patterns in the same function
  • #624: Adds and updates committor-related metrics in magicblock-metrics with histograms and timing helpers used by the main changes
  • #640: Introduces undelegation error handling and cleanup-producing logic that directly intersects with the intent_executor cleanup task spawning added in this PR

Suggested reviewers

  • thlorenz
  • bmuddha
  • GabrielePicco

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.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

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

📒 Files selected for processing (4)
  • 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-metrics/src/metrics/mod.rs (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-21T10:22:07.520Z
Learnt from: taco-paco
Repo: magicblock-labs/magicblock-validator PR: 661
File: magicblock-committor-service/src/intent_executor/single_stage_executor.rs:20-28
Timestamp: 2025-11-21T10:22:07.520Z
Learning: In magicblock-committor-service's SingleStageExecutor and TwoStageExecutor (single_stage_executor.rs and two_stage_executor.rs), the fields transaction_strategy, junk, and patched_errors are intentionally public because these executors are designed to be used independently outside of the IntentExecutor scope, and callers need access to these execution reports for cleanup and error handling.

Applied to files:

  • magicblock-committor-service/src/intent_executor/two_stage_executor.rs
  • magicblock-committor-service/src/intent_executor/single_stage_executor.rs
  • magicblock-committor-service/src/intent_executor/mod.rs
  • magicblock-metrics/src/metrics/mod.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 (1)
magicblock-committor-service/src/intent_executor/mod.rs (1)
magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs (1)
  • spawn (98-103)
🔇 Additional comments (5)
magicblock-metrics/src/metrics/mod.rs (1)

252-254: Committor intent counters and preparation-time histograms are wired correctly and follow existing patterns.

  • COMMITTOR_INTENTS_COUNT plus inc_* wrappers are named/described consistently with the other committor metrics and registered in register().
  • The new preparation-time histograms (COMMITTOR_INTENT_TASK_PREPARATION_TIME, COMMITTOR_INTENT_ALT_PREPARATION_TIME) have clear help strings, plausible bucket ranges, and are exposed via observe_* helpers that match the existing LabelValue/HistogramTimer style in this module.
  • No issues spotted with label cardinality (task_type) or missed registrations.

Also applies to: 302-321, 354-361, 477-483, 516-528

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

24-28: Clone bound on T for TwoStageExecutor is consistent with the executor’s new usage.

Requiring T: TransactionPreparator + Clone here aligns with IntentExecutorImpl’s bounds and the background cleanup path that clones the preparator; no issues with the executor’s own logic.

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

25-29: T: TransactionPreparator + Clone on SingleStageExecutor matches the executor’s updated constraints.

This keeps the executor generic bounds in sync with IntentExecutorImpl and the new cleanup model, without changing SingleStage behavior.

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

103-107: New Clone bound on TransactionPreparator is aligned with the async cleanup design.

The additional T: TransactionPreparator + Clone constraints on IntentExecutorImpl and its IntentExecutor impl are necessary for spawn_cleanup_task to capture a preparator instance into a spawned future. As long as concrete preparators keep Clone cheap (e.g., via internal Arcs), this is a reasonable trade‑off.

Also applies to: 768-772


682-705: spawn_cleanup_task design is sound—trait bounds and Arc-backed cloning validate concurrent safety.

Verification confirms:

  • TransactionPreparator trait enforces Send + Sync + 'static at the trait level, so all implementations (including TransactionPreparatorImpl) are guaranteed thread-safe.
  • TransactionPreparatorImpl and DeliveryPreparator both derive Clone, backed by Arc-wrapped types (e.g., Arc<RwLock<...>> and Arc<Mutex<...>>), making clones cheap.
  • cleanup_for_strategy takes only &self (immutable), so concurrent calls are safe.
  • tokio::spawn enforces T: Future + Send + 'static at compile time; the async move block capturing owned Keypair and cloned TransactionPreparator will satisfy these bounds.

The parallelized cleanup pattern achieves the goal without blocking the main flow.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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

# Conflicts:
#	magicblock-metrics/src/metrics/mod.rs
Copy link
Collaborator

@GabrielePicco GabrielePicco left a comment

Choose a reason for hiding this comment

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

LGTM!

@taco-paco taco-paco merged commit 7eaaaf3 into master Nov 24, 2025
18 checks passed
@taco-paco taco-paco deleted the fix/committor/long-intents branch November 24, 2025 16: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.

3 participants