Background Runs
BindAI v0.1 provides a REST API for submitting automation runs for background execution. Background runs allow a client to submit work without keeping the original HTTP request open until the automation completes. The API provides two endpoints:AutomationWorker backed by a thread pool. Run state and history use in-memory stores by default, so they should not be treated as durable across process restarts.
Background Run Architecture
The v0.1 architecture is:Authentication
Background-run endpoints are protected by the BindAI API authentication layer. Clients must provide an API key using theAuthorization header:
BINDAI_API_KEY environment variable:
401 Unauthorized. If BINDAI_API_KEY is not configured on the server, the authentication dependency raises a server-side configuration error instead.
See the Authentication page for details.
Submit a Background Run
A new background run is submitted with:automation_id identifies an automation definition already configured in the BindAI API application.
The input field is optional and can contain application-specific data. The current API stores the supplied input on the resulting AutomationRun.
Important: The current worker does not automatically pass this input into AutomationDefinition.run(). The stored run input and the automation’s execution input are separate concerns in v0.1.
Example Request
Using cURL:AutomationWorker.
Submission Response
A successful submission returns HTTP202 Accepted.
The response includes information about the created run. For example:
pending.
The returned id is the run identifier used to query the run later.
What HTTP 202 Accepted Means
Background execution uses HTTP202 Accepted because the request submits work for execution rather than waiting for the automation to finish.
The request lifecycle is:
202 Accepted response does not mean the automation completed successfully. It means the request was accepted for background execution.
Get Run Status
A submitted run can be inspected with:404 Not Found.
Run Response
A run response contains fields corresponding to theAutomationRun model:
status rather than assume a particular state immediately after submission.
Run Lifecycle
TheAutomationWorker creates an AutomationRun before scheduling its background execution.
The run lifecycle is conceptually:
created_at— when the run was created.started_at— when execution started.completed_at— when execution reached a completed or failed state.
null. Timestamps are represented as UTC-aware datetimes in the run model and serialized in the API response.
The current status values include pending, running, completed, and failed.
Polling
A client can poll the run endpoint until execution reaches a terminal state:Python Client Example
A Python application can submit a background run using therequests library:
JavaScript Example
A JavaScript application can submit a run usingfetch:
Run Input
The submission request supports an optionalinput value:
AutomationRun. Its meaning is application-specific.
An important v0.1 detail is that the current AutomationWorker invokes the automation definition using:
input field should be understood as stored run data, not as an argument automatically passed to the automation definition.
Applications that require input-driven execution must explicitly connect their input data to the automation’s execution logic.
Automation Definition
Theautomation_id identifies an automation definition configured in the BindAI application.
Conceptually:
Definition Version
Background runs include the automation definition version. For example:Run State
Run state includes execution metadata such as:started_at, completed_at, output, or error populated.
Successful Runs
A completed run can contain an output value:Failed Runs
A failed run can contain an error description:Run Not Found
If a requested run does not exist in the available worker state or history, the API returns HTTP404 Not Found.
For example:
failed.
Because the default stores are in memory, a previously known run may no longer be available after the application process restarts.
Background Worker
The v0.1 API uses anAutomationWorker for background execution.
The worker uses an in-process ThreadPoolExecutor, with a default of four worker threads.
Its responsibilities include:
- Creating
AutomationRuninstances. - Saving run state.
- Submitting background work.
- Updating the run lifecycle state.
- Recording completed or failed runs in history.
Worker Submission
The worker exposes two related background-submission operations. The simple form returns aFuture:
future.result() waits for that future to finish. It should not be used in the HTTP request path if the intention is to return immediately without waiting for execution.
The lower-level form returns both the run and the future:
submit_with_run() saves the newly created AutomationRun before background execution proceeds. This lets the API obtain the run information without waiting for the automation to finish.
Note: In the current worker implementation, input is stored on the run; it is not passed as an argument to AutomationDefinition.run().
Synchronous Worker Execution
AutomationWorker also supports synchronous execution:
AutomationDefinition.run().
The REST background-run endpoint uses background submission rather than synchronous execution.
Process-Local Execution
The most important v0.1 limitation is that the worker runs inside the application process:In-Memory State and History
The default run state store and run history are in-memory implementations. They support storing and retrieving run information while the process is running, but their contents do not survive a process restart. The current implementation therefore does not provide durable run-state storage by default. The worker’s state-store and history interfaces allow alternative implementations, but durable persistence depends on configuring and implementing a suitable backend. It should not be assumed to exist in a default v0.1 deployment.No Distributed Queue
The v0.1 background-run implementation does not provide a distributed message queue. For example:Horizontal Scaling
Running multiple API instances does not automatically create one shared background execution system. For example:Durable Execution
The v0.1 worker should not be considered a durable distributed job system. A distributed architecture might look like:Background Runs vs Streaming
Background runs and streaming serve different purposes. Background runs:Background Runs vs Synchronous Execution
Synchronous execution keeps the request open while execution completes:Background Runs and Automation Scheduling
Background runs are different from scheduled automation. A background run is explicitly submitted through the API:Background Runs and Observability
BindAI’s event system can emit runtime events during execution. Depending on the execution path, relevant events can include:- Agent events.
- Workflow events.
- Node events.
- Model events.
- Tool events.
- Memory events.
EventRecorder for recording events emitted through an execution context’s event bus.
This can support debugging, execution inspection, and custom logging. Additional metrics or tracing integrations require separate implementation.
The event recorder is not a distributed background-run state store. Event recording and run-state persistence are separate concerns:
Error Handling
Background execution can fail for reasons similar to other BindAI executions, including:- Model provider errors.
- Tool errors.
- Workflow errors.
- Connection failures.
- External-service failures.
- Invalid automation configuration.
- Application errors.
status and error fields rather than assume that a successfully submitted run will always complete successfully.
Retries
The currentAutomationWorker does not automatically retry failed runs.
Retry behavior configured elsewhere in an automation or workflow should be treated separately from the worker’s basic execution lifecycle.
Clients should not blindly resubmit failed background runs, especially when external side effects are involved.
For example:
Idempotency
Background operations should be designed with idempotency in mind. This is especially important when an automation performs:- API writes.
- Notifications or emails.
- Database updates.
- Deployment operations.
- Ticket creation.
- External workflow changes.
Security
Background runs can execute automations that use tools and connections to external services. Protect the run endpoints accordingly. Recommended practices include:- Use strong API keys.
- Use HTTPS outside trusted local development environments.
- Protect external credentials.
- Limit connection permissions.
- Validate automation inputs.
- Avoid exposing secrets through run input or output.
- Avoid logging sensitive run data.
- Restrict access to state-changing automations.
Input and Output Data
Run input and output can contain application data.AutomationDefinition.run().
Production Considerations
Before using background runs in production, consider:- Process lifetime and deployment restarts.
- Container restarts.
- Worker capacity and execution duration.
- External-service reliability.
- Retry behavior and idempotency.
- Monitoring and alerting.
- Run-state persistence.
- Failure recovery.
- Access control for automation execution.
Docker
Background runs execute inside the BindAI API process in the v0.1 deployment model. Conceptually:Docker Compose
Docker Compose can run the BindAI API locally:API Health vs Run Health
The/health endpoint indicates basic API service availability:
Testing
The API package tests can be run with:- Run submission.
- Run lookup.
- Authentication.
- Missing runs.
- Successful execution.
- Failed execution.
- Worker submission.
- Synchronous worker execution.
- Run-state transitions.
- History recording.
Current v0.1 Scope
The current background-run implementation provides:- Background run submission through the REST API.
- Run identifiers.
- Run status lookup.
- Run input storage.
- Run output and error fields.
- Creation, start, and completion timestamps.
- In-process automation workers.
- Thread-pool background execution.
- API-key authentication.
- In-memory state and history implementations.
Current Limitations
The default v0.1 background-run system does not provide:- A distributed message queue.
- Durable distributed workers.
- Cross-instance worker coordination.
- Kubernetes-native job execution.
- Built-in worker autoscaling.
- Managed cloud workers.
- Guaranteed execution after process failure.
- Durable run-state storage by default.
- Automatic worker retries.
- Dead-letter queues.
- Automatic propagation of the submitted
inputintoAutomationDefinition.run().
Future Distributed Execution
A future BindAI architecture could introduce a persistent queue:Recommended Usage
For v0.1, background runs are appropriate when:- Work can execute inside the API process.
- Interruptions during process restarts are acceptable.
- A lightweight background execution model is sufficient.
- Coordinated workers across multiple instances are not required.
- The application can tolerate the default persistence limitations.
Example End-to-End Flow
A complete background-run flow looks like this:Summary
BindAI v0.1 provides background automation execution through:AutomationWorker backed by a thread pool. It stores run state and history in memory by default and does not automatically retry failed runs.
The API’s input value is stored on the run. The current worker does not automatically pass it as an argument to AutomationDefinition.run().
The most important deployment limitation is that execution is process-local:
