feat: parallel rule execution with Tokio semaphore#34
Open
evg4b wants to merge 1 commit into
Open
Conversation
Rules are now split into two execution modes based on what they do:
- **Sync** (default): branch-name-*, commit-message-*, suppress-files,
suppress-string — run sequentially in a dedicated thread, one after another.
- **Async**: exec, shell, write-file, copy-files, delete-files — each gets
its own OS thread and runs concurrently with the other async rules.
Both groups start simultaneously so sync validation and heavy file/process
operations overlap in time, minimising total hook latency.
Concurrency of async rules is bounded by a `tokio::sync::Semaphore` (default
limit: 10). Scoped OS threads acquire permits via `Handle::block_on` which
is safe to call from non-tokio threads and does not require the caller to be
inside a tokio task.
Implementation details:
- Add `ExecutionMode::{Sync,Async}` enum and a `Rule::execution_mode()`
trait method (defaults to `Sync`) in `fisherman_core/src/rules/rule.rs`.
- Five dynamic rule types override `execution_mode()` to return `Async`.
- `HandleCommand::exec` now has three phases: (1) sequential preparation
(extend context, evaluate `when` conditions), (2) parallel execution via
`std::thread::scope` + tokio semaphore, (3) report in declaration order.
- All new behaviour is covered by unit tests in `handle.rs` and `rule.rs`.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
ExecutionMode::{Sync, Async}enum and aRule::execution_mode()trait method (default:Sync) so each rule type declares how it should be scheduledAsync:exec,shell,write-file,copy-files,delete-files; all validation rules remainSyncHandleCommand::execto run both groups in parallel usingstd::thread::scope+tokio::sync::Semaphore(max 10 concurrent async rules viaHandle::block_on)Execution model
Test plan
rules::rule::tests::sync_rules_default_to_sync_mode— all 8 validation rules returnSyncrules::rule::tests::async_rules_return_async_mode— all 5 dynamic rules returnAsynchandle::tests::test_sync_rule_{success,failure}— existing sync behaviour unchangedhandle::tests::test_async_rule_{success,failure}— async rules propagate results correctlyhandle::tests::test_mixed_rules_*— sync failure and async failure both surfacehandle::tests::test_more_async_rules_than_concurrency_limit— 20 async rules with limit of 10 complete without deadlockhandle::tests::test_result_order_preserved— results always returned in declaration ordercargo test -p fisherman_core)cargo clippy --all-targets -- -D warningsclean🤖 Generated with Claude Code