ContextWorker and Dual-Runtime Executionπ
ContextWorker owns durable background workflows, heavy compute jobs, isolated code execution, evaluation gates, and derived audit runs. Its gRPC service, execution engines, job implementations, and runtime registry live under services/worker/src/contextunity/worker/.
Inherited kernel, five actors, and PATH L / PATH T parityπ
ContextWorker exposes one closed workflow registry and engine-neutral run_* business bodies shared across two execution adapters (PATH L local HueyEngine and PATH T production TemporalEngine) over durable WorkflowRunRecord state (W-001):
| Actor | Role | Target C0 flag (worker.yml) |
|---|---|---|
WorkerRunner | Trusted platform workflows (memory_synthesis, embedding_enrichment, tenant lifecycle orchestration, and ADR-0016 durable RouterGraphDagWorkflow orchestration calling bounded Router GraphRuns) | worker.runner.enabled |
WorkerStrongman | Resource-budgeted (CPU/RAM/GPU/timeout) heavy batch jobs with cooperative cancellation and ADR-0015 encrypted external outputs (W-101) | worker.strongman.enabled |
WorkerSandman | Isolated ephemeral Linux sandbox execution (ExecuteCode) gated by Shield Constitution (S-202) and SandboxExecutionIntent (S-101) with zero host-process fallback (W-102) | worker.sandman.enabled (sandman.provider: none default) |
WorkerTestMan | Deterministic, calibrated-oracle, and hybrid evaluation suites producing immutable TestRunRecord and EvaluationSummary bundles (W-201) | worker.testman.enabled |
WorkerAuditor | Scoped compliance and Memory Linter check execution emitting only Shield-signed derived findings to _audit without policy or mutation authority (W-201/B-201) | worker.auditor.enabled |
- INV-WORKER-SERVICE-ISOLATION:
WorkerServiceowns mechanical durability, retries, budgets, and engine-neutral workflow dispatch (prepare_registered_workflow,HueyEngine,TemporalEngine) without importing peer service implementations (enforced byARCH-WORKER-ISOLATION), selecting LLM prompts/tools, holding long-lived Shield keys (ADR-0015), or mutating Brain domain pointers directly.
Key symbols and inputs/outputsπ
flowchart LR
Callers["CLI / Router Callers"] --> Service["WorkerService (gRPC)"]
Service --> Huey["HueyEngine (PATH L local)"]
Service --> Temporal["TemporalEngine (PATH T durable)"]
Huey --> Prepare["prepare_registered_workflow (validate & resolve)"]
Temporal --> Prepare
Huey --> Jobs["jobs/* (run_prepared_workflow / activities)"]
Temporal --> Jobs
Service -. "RegisterSchedules" .-> Temporal
Jobs --> Peers["Brain / Router / Shield gRPC Clients"]| Symbol | Role | Inputs / Outputs |
|---|---|---|
WorkerService | Worker gRPC servicer | Authenticated workflow/schedule RPCs -> dispatched engine status & results |
WorkerConfig | Typed C0 Worker configuration | YAML + env vars -> validated WorkerConfig (validate_memory_runtime_gates fails closed) |
prepare_registered_workflow | Engine-neutral workflow resolver | (workflow_type, workflow_args, tenant_id) -> RegisteredWorkflowInvocation shared by Huey and Temporal |
HueyEngine | Local PATH L task engine | start_workflow(...) -> executes shared run_* business bodies locally |
TemporalEngine | Production PATH T durable engine | start_workflow(...) / register_schedules(...) -> Temporal workflows and schedules |
Execution pathsπ
| Path | Entry | Purpose |
|---|---|---|
| Worker gRPC | contextworker serve | RPC service; starts configured Temporal pollers when WORKER_ENGINE=temporal |
| Temporal worker | contextworker temporal | Run discovered workflow modules directly |
| local Huey | WORKER_ENGINE=huey | Lightweight local jobs; not a durable Temporal substitute |
| one-shot synthesis | contextworker memory-synthesis | Admin-triggered bounded synthesis batch |
| one-shot enrichment | contextworker embedding-enrichment | PATH-L embedding sweep without Temporal |
Workflow and activity implementations are under jobs/, with registration and dispatch in jobs/workflow_dispatch.py and the Worker registry. There are no workflows/ or activities/ top-level packages. The contextunity.worker.schedules module provides a separate Temporal schedule CLI.
Configuration and gatesπ
WorkerConfig is parsed without mesh I/O; resolve_runtime_endpoints resolves Brain once at service startup. Key environment inputs are WORKER_ENGINE, WORKER_TENANTS, WORKER_MODULES, TEMPORAL_HOST, TEMPORAL_NAMESPACE, the WORKER_MEMORY_SYNTHESIS_* family, and the WORKER_EMBEDDING_* family.
Memory Synthesis is fail-closed:
- embedding enrichment must be enabled;
WORKER_TENANTSmust be non-empty;- at least one project tenant is required;
- reserved tenants are rejected;
- batch, age, backoff, retry, concurrency, and DLQ paths are bounded by config.
The local DLQ paths must remain below .contextunity/dlq/. A DLQ envelope is failure evidence, not a successful workflow result.
Schedulingπ
Temporal schedules are registered through the authenticated Worker RPC and manifest/runtime integration. RegisterSchedules deliberately rejects the Huey engine. Run python -m contextunity.worker.schedules list to list schedule IDs; the same module provides pause, unpause, and delete subcommands with a schedule ID. Use Temporal's operator tooling to trigger schedules.
Invariant: PATH L does not report durable Temporal schedule registration as successful; schedule registration fails closed unless the Temporal engine owns the request.
Developmentπ
contextworker serve
contextworker temporal --modules <module>
uv run pytest services/worker/testsChanges require workflow/activity registration tests, tenant reject paths, retry/idempotency behavior, and tests for both enabled and disabled gates.