feat(deployment): default to managed NATS workers
Autonomous workflows now always hand a complete task to a scoped archie-agent container. Embedded NATS is the default and external NATS changes only broker placement; legacy agent and containers.enabled inputs decode for migration but cannot select an execution path. The daemon flushes task-event subscriptions before a worker can publish, and runtime updates snapshot and restore the configured worker image.
This commit is contained in:
1 parent
5d00ec7b0c
commit
972fb5b8e1
38 files changed
+497
-232
No files matched your search
@@ -354,13 +354,9 @@ func (b *boot) setupObservability() {
|
||||
// connectNATS opens the NATS client. External mode dials cfg.NATS.URL;
|
||||
// embedded mode starts an in-process nats-server and dials it, so single-
|
||||
// process deployments get task distribution and reaction delivery without a
|
||||
// separate server. Off mode returns nil and the SQLite ClaimNext flow runs.
|
||||
// separate server. Broker deployment never changes the worker executor.
|
||||
func (b *boot) connectNATS(ctx context.Context) error {
|
||||
cfg, log := b.cfg, b.log
|
||||
if cfg.NATS.Mode == config.NATSModeOff {
|
||||
return nil
|
||||
}
|
||||
|
||||
url := cfg.NATS.URL
|
||||
var natsToken string
|
||||
if cfg.NATS.Mode == config.NATSModeExternal {
|
||||
@@ -412,13 +408,10 @@ func (b *boot) connectNATS(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// setupContainers builds the optional container pool. Container setup
|
||||
// degrades rather than aborting, for the same reason resolveForge does:
|
||||
// containers are one capability among many, and refusing to start denies
|
||||
// the operator chat, the dashboard and every other subsystem over a
|
||||
// feature they may not be exercising right now. Under a systemd unit
|
||||
// with Restart=on-failure it also turns a recoverable problem into a
|
||||
// crash loop with the real error scrolling past unread.
|
||||
// setupContainers builds the managed autonomous-worker pool. Failure degrades
|
||||
// rather than aborting because the native interactive agent and dashboard do
|
||||
// not require Docker; repository tasks park instead of falling back to a host
|
||||
// model loop.
|
||||
func (b *boot) setupContainers(ctx context.Context) func() {
|
||||
containerPool, storeBackend, closeDocker := startContainers(ctx, b.cfg, b.log)
|
||||
b.containerPool = containerPool
|
||||
@@ -1251,8 +1244,8 @@ func (b *boot) startServices(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// setupBackends wires the optional runtime backends: the NATS client
|
||||
// and the container pool.
|
||||
// setupBackends wires the autonomous-workflow backends. Container setup may
|
||||
// degrade, but NATS startup must succeed because there is no other task handoff.
|
||||
func (b *boot) setupBackends(ctx context.Context) error {
|
||||
closeContainers := b.setupContainers(ctx)
|
||||
err := b.connectNATS(ctx)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Autonomous execution has one production composition: managed task
|
||||
// containers over embedded or external NATS. These old switches must not
|
||||
// quietly restore a host or no-broker path in the composition root.
|
||||
func TestCompositionContainsNoAutonomousExecutionOptOut(t *testing.T) {
|
||||
for _, file := range []string{"bootstrap.go", "main.go"} {
|
||||
source, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, forbidden := range []string{"NATSModeOff", "Containers.Enabled"} {
|
||||
if strings.Contains(string(source), forbidden) {
|
||||
t.Errorf("%s contains removed autonomous execution switch %q", file, forbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -723,6 +723,12 @@ func subscribeAgentEvents(nc *natsio.Conn, bus *events.Bus, log *slog.Logger) (u
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := nc.Flush(); err != nil {
|
||||
if cleanupErr := sub.Unsubscribe(); cleanupErr != nil {
|
||||
log.Warn("task event subscription cleanup failed after flush failure", "err", cleanupErr)
|
||||
}
|
||||
return nil, fmt.Errorf("flush task event subscription: %w", err)
|
||||
}
|
||||
return func() {
|
||||
if err := sub.Unsubscribe(); err != nil {
|
||||
log.Warn("task event unsubscribe failed", "err", err)
|
||||
@@ -948,28 +954,22 @@ func memoryProvider(workDir string, log *slog.Logger) (*builtin.Provider, string
|
||||
return fb, fallback
|
||||
}
|
||||
|
||||
// startContainers brings up the container pool and storage backend, returning
|
||||
// nils when containers are disabled or unavailable.
|
||||
// startContainers brings up the mandatory autonomous-worker pool and storage
|
||||
// backend, returning a degraded nil pool when Docker is unavailable.
|
||||
//
|
||||
// Failure here degrades rather than aborting, for the same reason resolveForge
|
||||
// does: containers are one capability among many, and refusing to start denies
|
||||
// the operator chat, the dashboard and every other subsystem over a feature
|
||||
// they may not be exercising. Under Restart=on-failure it also turns a
|
||||
// recoverable problem into a crash loop with the real error scrolling past.
|
||||
// Failure here degrades rather than aborting: the native interactive agent and
|
||||
// dashboard remain useful without Docker, while autonomous tasks park because
|
||||
// there is deliberately no host execution fallback.
|
||||
func startContainers(
|
||||
ctx context.Context,
|
||||
cfg config.Config,
|
||||
log *slog.Logger,
|
||||
) (*container.Pool, storage.Backend, func()) {
|
||||
noop := func() {}
|
||||
if !cfg.Containers.Enabled {
|
||||
return nil, nil, noop
|
||||
}
|
||||
|
||||
// Single Docker client shared between pool and storage backend.
|
||||
dockerCli, err := client.New(client.FromEnv)
|
||||
if err != nil {
|
||||
log.Error("containers disabled: docker client unavailable", "err", err)
|
||||
log.Error("autonomous workflows unavailable: docker client unavailable", "err", err)
|
||||
return nil, nil, noop
|
||||
}
|
||||
closeDocker := func() {
|
||||
@@ -991,7 +991,7 @@ func startContainers(
|
||||
// A missing image is recoverable by hand. The daemon sends no registry
|
||||
// credentials on pull (internal/container/pool.go), so a private
|
||||
// registry always needs the operator's CLI to fetch it first.
|
||||
log.Error("containers disabled: pool unavailable", "err", err,
|
||||
log.Error("autonomous workflows unavailable: container pool unavailable", "err", err,
|
||||
"hint", "run `docker compose pull agent` (or `build agent`) so the image is present locally")
|
||||
return nil, storage.NewDockerBackend(dockerCli), closeDocker
|
||||
}
|
||||
|
||||
@@ -1205,3 +1205,13 @@ func TestSubscribeAgentEventsDropsUnparseableMessages(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubscribeAgentEventsFlushesBeforeReturning(t *testing.T) {
|
||||
source, err := os.ReadFile("main.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(source), "flush task event subscription") {
|
||||
t.Fatal("subscribeAgentEvents does not flush its NATS subscription before returning")
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ var reloadableFields = map[string]bool{
|
||||
|
||||
// reloadableSubFields are sub-fields of structs that are otherwise
|
||||
// startup-built. VolumeTTL is re-read per cycle in cleanupExpiredStorage;
|
||||
// everything else in Containers (Image, Enabled, MaxConcurrency,
|
||||
// everything else in Containers (Image, MaxConcurrency,
|
||||
// MaxUptime, PullPolicy, Network) is frozen in the startup-built
|
||||
// container pool -- the dispatchers re-read MaxConcurrency but the pool
|
||||
// captures it at construction (container/pool.go:94,163), so a change
|
||||
@@ -174,7 +174,7 @@ var reloadableFields = map[string]bool{
|
||||
// forge client itself is startup-built, so Type/Token/TokenEnv stay
|
||||
// requires-restart.
|
||||
var reloadableSubFields = map[string]map[string]bool{
|
||||
"Containers": {"VolumeTTL": true},
|
||||
"Containers": {"LegacyEnabled": true, "VolumeTTL": true},
|
||||
"Forge": {"Host": true},
|
||||
}
|
||||
|
||||
|
||||
@@ -219,6 +219,11 @@ func TestChangedNonReloadableFields(t *testing.T) {
|
||||
if got := changedNonReloadableFields(base, legacyOnly); len(got) != 0 {
|
||||
t.Fatalf("legacy agent change: got %v, want []", got)
|
||||
}
|
||||
legacyContainers := base
|
||||
legacyContainers.Containers.LegacyEnabled = true
|
||||
if got := changedNonReloadableFields(base, legacyContainers); len(got) != 0 {
|
||||
t.Fatalf("legacy containers.enabled change: got %v, want []", got)
|
||||
}
|
||||
|
||||
// Containers sub-field granularity: Image change warns, MaxConcurrency
|
||||
// and VolumeTTL changes do not.
|
||||
|
||||
Reference in new issue
Block a user