Home/Docs/Core Services/ContextWorker

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):

ActorRoleTarget C0 flag (worker.yml)
WorkerRunnerTrusted platform workflows (memory_synthesis, embedding_enrichment, tenant lifecycle orchestration, and ADR-0016 durable RouterGraphDagWorkflow orchestration calling bounded Router GraphRuns)worker.runner.enabled
WorkerStrongmanResource-budgeted (CPU/RAM/GPU/timeout) heavy batch jobs with cooperative cancellation and ADR-0015 encrypted external outputs (W-101)worker.strongman.enabled
WorkerSandmanIsolated 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)
WorkerTestManDeterministic, calibrated-oracle, and hybrid evaluation suites producing immutable TestRunRecord and EvaluationSummary bundles (W-201)worker.testman.enabled
WorkerAuditorScoped 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
Important
  • INV-WORKER-SERVICE-ISOLATION: WorkerService owns mechanical durability, retries, budgets, and engine-neutral workflow dispatch (prepare_registered_workflow, HueyEngine, TemporalEngine) without importing peer service implementations (enforced by ARCH-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"]
SymbolRoleInputs / Outputs
WorkerServiceWorker gRPC servicerAuthenticated workflow/schedule RPCs -> dispatched engine status & results
WorkerConfigTyped C0 Worker configurationYAML + env vars -> validated WorkerConfig (validate_memory_runtime_gates fails closed)
prepare_registered_workflowEngine-neutral workflow resolver(workflow_type, workflow_args, tenant_id) -> RegisteredWorkflowInvocation shared by Huey and Temporal
HueyEngineLocal PATH L task enginestart_workflow(...) -> executes shared run_* business bodies locally
TemporalEngineProduction PATH T durable enginestart_workflow(...) / register_schedules(...) -> Temporal workflows and schedules

Execution pathsπŸ”—

PathEntryPurpose
Worker gRPCcontextworker serveRPC service; starts configured Temporal pollers when WORKER_ENGINE=temporal
Temporal workercontextworker temporalRun discovered workflow modules directly
local HueyWORKER_ENGINE=hueyLightweight local jobs; not a durable Temporal substitute
one-shot synthesiscontextworker memory-synthesisAdmin-triggered bounded synthesis batch
one-shot enrichmentcontextworker embedding-enrichmentPATH-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_TENANTS must 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.

Important

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/tests

Changes require workflow/activity registration tests, tenant reject paths, retry/idempotency behavior, and tests for both enabled and disabled gates.