Temporal Workflows & Background Jobs
Relevant source files
The following files were used as context for generating this wiki page:
Speakeasy uses Temporal as its primary orchestrator for reliable, long-running background processes and asynchronous tasks. The system manages complex operations such as assistant runtimes, scheduled triggers, and data processing through a distributed worker architecture. Temporal ensures that background jobs are resilient to failures, provide full observability, and maintain consistency across the Speakeasy AI Control Plane.
Sources: README.md:65-67, CLAUDE.md:46-47, mise.toml:111-118
System Architecture
The background job system consists of a Temporal server and dedicated worker processes that execute workflows and activities. In local development, these services are managed by pitchfork, while production environments scale the server and worker independently.
Component Interaction
The Speakeasy server initiates workflows in response to API requests or internal events. The Temporal worker listens to specific task queues and executes the business logic defined in Go.
The diagram shows the flow from an API request to activity execution, including the process management layer used in local development.
Sources: mise.toml:132-136, CLAUDE.md:41-43, CLAUDE.md:68-71
Configuration & Environments
Temporal configuration is managed through environment variables in mise.toml. The system supports both local self-hosted Temporal instances and Temporal Cloud.
| Variable | Description | Default (Local) |
|---|---|---|
TEMPORAL_HOST | Host address for the Temporal server. | 127.0.0.1 |
TEMPORAL_PORT | Port for the Temporal server. | 17233 |
TEMPORAL_NAMESPACE | The logical isolation unit for workflows. | default |
TEMPORAL_TASK_QUEUE | The queue workers listen to for new tasks. | main |
TEMPORAL_ADDRESS | Combined host and port string. | 127.0.0.1:17233 |
Sources: mise.toml:111-122
Workflow Isolation
Each git worktree in Speakeasy can run its own full stack, including a unique Temporal namespace. This prevents task collisions between different feature branches during development. When a worktree is removed via wt remove, the associated Temporal namespace is torn down.
Sources: CONTRIBUTING.md:218-223
Key Background Operations
The background system handles several critical business domains:
Assistant Runtimes & Triggers
Temporal orchestrates the lifecycle of AI assistants, particularly for scheduled and event-based execution.
- Cron Triggers: Workflows handle periodic tasks scheduled by users.
- Slack Triggers: Background jobs process incoming Slack events delivered via webhooks.
- Warm Re-use: The system manages sandboxed processes (runtimes) with a default "Warm TTL" of 60 seconds.
Sources: client/dashboard/src/pages/assistants/onboarding/systemPrompt.ts:1-12, client/dashboard/src/pages/assistants/onboarding/systemPrompt.ts:47-50
Security & Audit Logging
Background jobs ensure that every mutation on a project or organization resource is recorded.
- Atomicity: Audit writes are executed within the same database transaction as the mutation.
- Cascading Deletes: Background processes emit per-row audit entries for affected child records during soft-deletes.
Sources: REVIEW.md:78-83
Local Development Workflow
To manage Temporal workers and workflows locally, use the following mise tasks:
- Start Services: Run
mise run startto spin up the worker and associated daemons. - Infrastructure Readiness: New worktrees wait for the infra (including Temporal) to be ready before starting daemons.
- Temporal CLI: The
temporalCLI is used to inspect workflow status, with the web UI typically available on port18233.
Sources: CLAUDE.md:68-71, mise.toml:234, CONTRIBUTING.md:225-230
Implementation Guidelines
When contributing to the background job system, follow these project-specific rules:
- Logic Placement: Implement workflows and activities inside
server/internal/background/. - Error Handling: Use the
oopspackage for error mapping andslogcontext-aware methods for logging within activities. - Observability: Background tasks must integrate with OpenTelemetry for traces and metrics.
- Audit Compliance: Every mutation must produce an audit entry; failure to log an audit event must result in an
oops.CodeUnexpectederror, failing the request.
Sources: CLAUDE.md:63-65, REVIEW.md:27-31, REVIEW.md:82-83, mise.toml:211-213
Summary
The Temporal-based background job system in Speakeasy provides the necessary reliability for AI assistant orchestration and enterprise-grade audit logging. By decoupling long-running tasks from the synchronous API path, Speakeasy maintains high availability and ensures that complex cross-system workflows are executed with consistent retry logic and full observability.