Concurrent Execution¶
Run multiple Claude Code prompts in parallel with concurrency control.
ConcurrentExecutor
¶
Manages concurrent execution of Claude Code prompts on Fly.io machines.
Each prompt is dispatched to its own Fly machine. All machines run in parallel via asyncio, and cleanup is guaranteed for every machine regardless of individual success or failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The Fly app to run machines in. |
required |
token
|
str | None
|
Explicit Fly API token (falls back to |
None
|
max_concurrency
|
int | None
|
Maximum number of machines to run simultaneously.
Use |
None
|
wait_timeout
|
float
|
Max seconds to wait for each machine to exit. |
3600.0
|
Example::
executor = ConcurrentExecutor("my-fly-app")
requests = [
ExecutionRequest(config=MachineConfig(prompt="Fix bug in auth", ...)),
ExecutionRequest(config=MachineConfig(prompt="Add tests for API", ...)),
]
batch = await executor.run_batch(requests)
for result in batch.results:
print(result.tag, result.success)
Source code in flaude/executor.py
run_batch
async
¶
Execute multiple prompts concurrently, each on its own Fly machine.
All machines are launched in parallel (subject to max_concurrency). Each machine is guaranteed to be cleaned up regardless of individual success or failure. Results are returned in the same order as the input requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requests
|
Sequence[ExecutionRequest]
|
The execution requests to process. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
BatchResult
|
class: |
Source code in flaude/executor.py
run_one
async
¶
Convenience method to execute a single prompt.
Equivalent to calling :meth:run_batch with a single request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
MachineConfig
|
Machine configuration. |
required |
name
|
str | None
|
Optional machine name. |
None
|
tag
|
str
|
Optional tag for result correlation. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
ExecutionResult
|
class: |
Source code in flaude/executor.py
ExecutionRequest
dataclass
¶
A single prompt execution request to be dispatched to a Fly machine.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
MachineConfig
|
Machine configuration (includes prompt, repos, credentials). |
name |
str | None
|
Optional human-readable name for the machine. |
tag |
str
|
Optional user-defined tag for correlating results back to requests. |
ExecutionResult
dataclass
¶
Result of a single execution within a batch.
Attributes:
| Name | Type | Description |
|---|---|---|
tag |
str
|
The tag from the corresponding :class: |
run_result |
RunResult | None
|
The :class: |
error |
Exception | None
|
The exception if the execution failed before producing a result. |
BatchResult
dataclass
¶
Aggregated results from a concurrent batch execution.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
list[ExecutionResult]
|
Individual results in the same order as the input requests. |
total |
int
|
Total number of executions. |
succeeded |
int
|
Count of executions that completed with exit code 0. |
failed |
int
|
Count of executions that completed with non-zero exit or errored. |
all_succeeded
property
¶
True if every execution in the batch completed with exit code 0.