Local / Production Placement Parityπ
This document describes the shared public contracts across local and production placements and the infrastructure adapters that may differ.
Related
| Doc | Role |
|---|---|
| index.md | Architecture & service map |
| worker-temporal.md | Worker PATH L vs PATH T operations |
| cli-architecture.md | contextunity local up |
| security-model.md | Token / Shield posture |
| testing-standards.md | How to prove parity |
| ADR-0015 | Trusted-local vs encrypted-external object boundary and authority split |
1. Principleπ
SAME: manifests, graph definitions, SDK method names, payload models,
tool bindings, error codes, feature-flag names,
Execution Trace/UDB/FaultSpool shapes
MAY DIFFER: process topology, storage engine, task engine, secret backend,
object-store adapter, embedder host, discovery, key backend/profileInvariant: Business workflows and agent graphs keep the same public contracts across local and production placement; only infrastructure adapters change.
Invariant: If external object offload is implemented, trusted-local and encrypted-external references remain distinct, and the external object store receives ciphertext only.
Forbidden
| Anti-pattern | Why |
|---|---|
| A separate local-only public client API with different methods | Agents and tests diverge |
| Silent no-op success on local (Huey βcompletedβ without side effects) | Local green, prod broken / reverse |
| Claiming completion from production Temporal registration alone | Local DX and CP local-parity fail |
| Different payload field names per backend | SDK/tool breakage |
| Unlabeled weak crypto presented as production-equivalent | Security footgun |
file://, MinIO and S3/R2 treated as interchangeable raw URIs | Erases the trust boundary and permits plaintext external writes |
2. Placement matrix (local vs production)π
| Plane | Shared contract | Local placement | Production placement | Proof style |
|---|---|---|---|---|
| Service API | gRPC + ContextUnit + ContextToken | In-process / loopback ports (create_local_*) | Multi-host service mesh | Same SDK tests against both |
| Brain storage | cells, blackboard, synapses, conversations, execution traces, and embedding jobs | SQLite + sqlite-vec where configured | Postgres + RLS + pgvector | Storage parity suites |
| Worker execution | Shared run_<job> + request/result models | PATH L: Huey dispatch or CLI one-shot; no Temporal process or durable schedules | PATH T: Temporal schedules + activities | Dual-runtime tests (see Β§3) |
| Router | Graphs, tools, conductor, memory injection | Same Router process; points at local Brain/Worker | Same contracts; remote endpoints | Inproc + integration |
| Shield | Token, project-key, secret, firewall, and typed trace-artifact RPC contracts | Same RPCs; secret backend is env or sqlite; trace-artifact protection needs SHIELD_MASTER_KEY | Same RPCs; secret backend support remains env or sqlite; no silent plaintext fallback | Verify permission, tenant, project binding, and missing-key failures |
| Trace-artifact archive | Brain owns a typed protected-artifact lifecycle; Worker's S3TraceArtifactArchive archives and restores opaque envelopes through a C0-selected S3-compatible profile | Uses the configured profile and Brain lifecycle RPCs | Uses the configured profile and Brain lifecycle RPCs | Verify ciphertext-only archive, identity binding, CAS receipts, and authorized reads |
| Generic external-object placement | ADR-0015 is design-only; it defines no general object reference, upload/download API, or placement caller | No generic object-offload implementation | No generic object-offload implementation | Do not infer generic storage parity from the separate trace-artifact archive |
| Vectors / embeddings | Cell embedding columns + job status enum | Configured Brain embedder; optional sqlite-vec | Configured Brain embedder (default image bundles pinned ONNX); PG vector | Status + vector_present, not metadata alone |
| Discovery | Service identity + tenant scope | In-process / optional Redis | Redis (or equiv) registry | Bootstrap same env keys |
| Execution/debug evidence | Brain Execution Trace; UDB FaultOccurrence; DLQ-0 fallback | Same trace contract; LocalFileDlqWriter JSONL for bounded unavailable UDB input | Direct UDB delivery plus bounded per-instance JSONL emergency spool; no HA/persistent-spool claim | Same IDs, bounds, redaction, replay semantics; optional Redis health state is non-authoritative |
| Technical telemetry | OTel instrumentation/export contract when enabled | Disabled or local Collector/backend | Deployment-approved OTLP backend/Collector | Export failure never invalidates Execution Trace or UDB |
| Fixtures | Phase fixture loader shapes | golden profile (small, committed) | parity / scale generated | Same keys; different volume |
| GPU / heavy jobs | Strongman/distill workflow payload | Dry-run / skip with explicit reason | Temporal + GPU isolation | Never silent success |
3. Worker dual-runtime (PATH L / PATH T)π
Worker is the most common place dual placement is mis-implemented. Target shape:
ββββββββββββββββββββββββββββββββββββββββββββββββ
β SHARED CORE β
β run_<job>(request, *, brain, dlq, β¦) β
β no temporalio, no huey imports β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββ
β
ββββββββββββββββ΄βββββββββββββββ
βΌ βΌ
PATH L PATH T
CLI one-shot @workflow / @activity
Huey start_workflow β run_* Temporal schedule / StartWorkflow
No Temporal server Temporal server required| Obligation | PATH L | PATH T |
|---|---|---|
| Run shared core | Required | Required |
| Durable schedule | Unsupported on PATH L; RegisterSchedules fails closed and operators can trigger supported jobs through the CLI | Temporal Schedule |
StartWorkflow | Must call run_* (no simulate-success) | Starts Temporal workflow |
| Retry / backoff | Huey/simple loops | Workflow-deterministic timers / retry policy |
| HA / multi-host | Single process | Temporal cluster |
| Proof | Tests without Temporal process | Compose/live Temporal when schedules claimed |
PATH L: Huey dispatches registered types to shared run_* (no simulate-success); durable schedule registration fails closed. PATH T compose: docker-compose.yml runs Temporal (+ UI) on the shared Postgres and a single worker service (gRPC + in-process Temporal pollers).
4. Service-by-service notesπ
4.1 Brainπ
| Concern | Shared | Local | Prod |
|---|---|---|---|
| Public API | UpsertCell, QueryCells, blackboard, synapses, embedding RPCs | Same method names | Same |
| Storage | Storage protocol / mixins | SqliteBrainStore | PostgresBrainStore + RLS |
| Tenant isolation | Token + app checks | App-layer isolation if no RLS | Postgres RLS + token |
| Embeddings | Job ledger + status | May skip vec backend β truthful skipped | Persist cells.embedding |
4.2 Routerπ
| Concern | Shared | Local | Prod |
|---|---|---|---|
| Graphs / tools / conductor | Manifest + compiler contracts | Same | Same |
| Brain/Worker clients | SDK | Localhost endpoints | Discovered / configured hosts |
| Auto-extract | Same policy modules | Background asyncio | Same; enqueue to Brain |
Router must not embed a second βlocal graph schemaβ.
4.3 Workerπ
See Β§3 and worker-temporal.md.
| Mode | Command | Runs Temporal poller? |
|---|---|---|
| gRPC / local | python -m contextunity.worker | No |
| Temporal | β¦ --temporal | Yes |
CLI one-shots (e.g. contextworker memory-synthesis) call shared runtime directly β preferred PATH L admin path.
4.4 Shieldπ
| Concern | Shared | Local | Prod |
|---|---|---|---|
| RPC surface | Current secret, project-key, session, policy, scan/statistics, and typed trace-artifact RPCs; see Shield service | Same current RPC surface | Same current RPC surface |
| Authority | Shield checks token scope, tenant, project, and node bindings on protected operations; trace-artifact encryption fails closed when its key is unavailable | Same checks; dev mode may omit the master key, in which case trace-artifact operations return a precondition error | Same checks; configured keys are required for trace-artifact protection |
| Secrets store | Factory supports env and sqlite; other configured backends fail as unimplemented | env / sqlite | env / sqlite; no Postgres or Vault implementation |
4.5 Forgeπ
| Concern | Shared | Local | Prod |
|---|---|---|---|
| Dashboard and operator CLI | Same operator behavior and authenticated Brain RPCs | Points at local Brain | Points at cluster Brain |
| Worker kicks | Same StartWorkflow / CLI semantics | Must work without Temporal if PATH L | Temporal when deployed |
Forge must show backend engine honestly (huey vs temporal), not imply Temporal-only.
4.6 CLI / LocalSupervisorπ
contextunity local up (see cli-architecture.md):
- Local Brain (SQLite), local Worker (Huey-oriented), Router, lightweight Shield
- Does not require Temporal for core DX
- Missing GPU/Borg/object features: explicit skip/label, not fake success
5. Config surface (same keys, different values)π
| Layer | Local typical | Production typical |
|---|---|---|
WORKER_ENGINE | huey | temporal (gRPC + in-process pollers in one Worker) |
TEMPORAL_HOST | unset / unused on PATH L | temporal:7233 or cluster |
| Brain DSN / mode | SQLite path | Postgres DSN + schema |
SHIELD_SECRET_BACKEND | env / sqlite | env / sqlite; postgres and vault fail as unimplemented |
| Embedder | local / mock in tests | production model endpoint |
| Generic external-object adapter | No current generic placement caller | No implementation |
| Trace-artifact archive | Separate Brain/Worker lifecycle, disabled unless its C0 profile is configured | Opaque protected envelopes use the configured S3-compatible profile |
| Feature flags | often off by default | staged enable |
Rule: request payloads must not override engine, DLQ path, Brain endpoint, or catalog roots (fail closed / config-owned).
6. How to prove parityπ
| Level | What | Example |
|---|---|---|
| Unit | Shared run_* with fakes | No Temporal/Huey imports in runtime module |
| Contract | Same SDK method against sqlite + postgres | Brain storage parity tests |
| PATH L | No Temporal process | CLI or Huey β real side effects |
| PATH T | Temporal present | Schedule or StartWorkflow β same side effects |
| Security | Same deny codes | Token/tenant fail closed both placements |
| Posture | Local weaker crypto labeled | Prod fail-closed if vault missing |
| External-object seam | No current implementation; ADR-0015 is a design boundary | Do not claim local/production offload parity until source contracts and a production caller exist |
Do not count as parity:
- Mock-only admin answers
- Huey status
completedwithout Brain writes - βWorkflow registeredβ without a consume path
7. Current implementation statusπ
Brain implements SQLite and PostgreSQL storage paths for contracts that define both adapters, including cells, conversations, Execution Trace, and CellEdge operations. Worker supports local Huey execution and Temporal-backed execution for registered workflows. Active service configuration determines which backend is available.
Shield currently implements env and sqlite secret backends. PostgreSQL and Vault secret storage are not implemented. Generic external-object placement remains design-only under ADR-0015; the Brain/Worker trace-artifact lifecycle is a separate implemented contract.
8. Checklist for new featuresπ
Before claiming local/prod support:
- One public contract (proto/SDK/CLI flags) documented
- Shared core path (handler or
run_*) has no engine-specific business forks - Local backend chosen and labeled if weaker
- Production backend chosen; fail-closed if missing in prodlike
- If external object offload is implemented, local and encrypted reference variants cannot be confused
- If external object offload is implemented, the backend receives ciphertext only and the reference contains no plaintext or key material
- If external object offload is implemented, Shield key authority, Worker I/O, and domain pointer authority are proven separately
- PATH L proof (if Worker) without Temporal
- PATH T proof (if schedules/HA claimed) with Temporal
- Same error codes and event types both sides
- No simulate-success stubs left on registered workflows
9. One-line summaryπ
Local and production use the same public contracts where both runtime adapters exist. Backend differences remain configuration-owned. Unsupported adapters and the design-only external object flow are not current capabilities.