Files
archie/docs/prds/embedded-nats.md
T
sam e832b8ef0c docs(prds): normalise statuses and remove writing dated to its own day
Three defects the first sweep left behind, each caught by a rule the guard
did not yet have.

Statuses. RULES.md gives three; the tree had 25 values, and the free-text ones
were carrying progress. "Implemented (wiring landed)" and "Ratified (rev. 2e).
Rev. 2e adds the OpenTaskByPR lookup. Rev. 2d revised section 10..." were both
changelogs living in the one field the other rules exempt. Every PRD now
declares Draft, Approved or Finalised and nothing else; five that declared
nothing now declare one. A revision number moves to **Revision:**, a pointer
to the authoritative document to **Authority:**, and what a past revision
changed to git. CLAUDE.md's citation of state-store-contract rev. 2e still
resolves.

Stale cross-references. "Supersedes the 2026-09-03 open question", "this
bullet previously said", "an earlier draft of this document claimed" all point
at text the reader cannot see, because it was replaced. A supersede marker
survives only when it names a file, a section or a symbol that can be found.

Temporal hedges. 100 uses of today, currently and right now across 31 files.
Each dates its sentence to the day it was written: "[notify] today is one
webhook URL, read in one place" stops being true the moment this design lands,
while still reading as the premise it rests on.

The header-field exemption was also too wide. "**Date:** 2026-09-03, Channel
resolved 2026-09-22" smuggled a dated status into the one line the rules did
not read; the exemption is now a Date holding only a date and a Status holding
only one of the three.
2026-09-22 00:38:35 +10:00

77 lines
3.7 KiB
Markdown

# Embedded NATS execution -- decision
**Status:** Finalised
**Date:** 2026-08-24
**Beads epic:** `archie-core-q15y`
This decision supersedes the position that embedded NATS was only a
distribution mechanism and could not be an agent-execution topology. That was
true only because the embedded listener was unauthenticated loopback. It left a
second production architecture in which `archied` ran autonomous workflows in
its own process, weakening the isolation boundary that managed task containers
exist to provide.
## One execution architecture, two broker deployments
Every autonomous repository workflow is handed over as one complete task via
NATS and runs in a task-scoped `archie-agent` container. `archied` remains a
native, long-lived orchestration and interactive-chat process; its operator
configured host filesystem access is unchanged. It owns task admission,
state, forge and worktree operations, container lifecycle, and the broker when
the embedded deployment is selected. It does not run an autonomous model loop.
NATS has two supported deployment shapes:
| mode | meaning |
| --- | --- |
| `embedded` | `archied` owns an in-process JetStream server (default). |
| `external` | `archied` and workers connect to the configured NATS URL. |
Both shapes have identical task semantics: one container and one full-task
request per workflow. Broker placement must not select a different executor.
The legacy `agent` section and `containers.enabled` key remain decode-only
migration inputs. `nats.mode = "off"`, per-stage NATS, in-process execution,
and subprocess execution are not production choices.
SQLite remains authoritative for task state. NATS is the sole autonomous work
handoff. SQLite recovery may identify work that needs republishing, but it must
not cause `archied` to call `workflow.Run` locally.
## Embedded reachability and authentication
An embedded listener uses a cryptographically random bearer token generated for
each daemon start. The token exists only in process memory and the environment
of managed worker containers; it is never written to config or logs.
For a native daemon with managed containers, startup resolves the Docker bridge
the workers will join. The listener binds only to that bridge's host gateway
address on a random port. Both the native daemon and workers use that same
reachable endpoint, and every client supplies the generated token. Binding a
Docker bridge address keeps the listener off ordinary LAN interfaces without
publishing a host port. A configured user bridge is respected; otherwise the
Docker default bridge is used. A network without a usable local IPv4 gateway is
a startup error for autonomous execution.
If Docker is unavailable, interactive chat may still start and embedded NATS
may remain loopback-only, but autonomous tasks park with an explicit container
capability failure. They never fall back to host execution.
## Ownership and lifecycle
- `internal/infrastructure/eventbus/nats` owns the authenticated embedded
server and exposes its runtime endpoint, not the server implementation.
- `internal/container` resolves the worker bridge and gateway and owns task
container lifecycle.
- `internal/app` composition selects embedded or external broker deployment,
freezes the connected runtime endpoint for worker environments, and wires the
full-task handoff.
- `cmd/archied` remains process input only as the domain migration reaches this
composition path.
The daemon starts the embedded server before its client, closes clients before
the server, and keeps JetStream data beneath the daemon data directory. NATS URL
and token are startup-built values: a reload cannot send new workers to a broker
different from the one the daemon is using.