refactor(agentexec): remove legacy execution paths

Autonomous workflows now have exactly one production boundary: a task-scoped archie-agent receives a full-task core-NATS request and runs the worker-local stage loop. The legacy [agent] section remains decode-only for migration; it no longer selects runtime behavior.
This commit is contained in:
sam committed 2026-08-24 14:56:57 +10:00
1 parent cc6b093820
commit 5d00ec7b0c
65 files changed
+454 -2678

No files matched your search

-4
View File
@@ -15,8 +15,6 @@ import (
"github.com/samcharles93/archie-core/internal/app/agentworker"
)
const consumerName = "archie-agent"
type workerRunner func(context.Context, agentworker.Settings, *slog.Logger) error
func main() {
@@ -31,7 +29,6 @@ func runCommand(args []string, getenv func(string) string, stderr io.Writer, run
flags := flag.NewFlagSet("archie-agent", flag.ContinueOnError)
flags.SetOutput(stderr)
natsURLFlag := flags.String("nats-url", "", "NATS server URL (defaults to NATS_URL)")
consumer := flags.String("consumer", consumerName, "JetStream consumer name")
if err := flags.Parse(args); err != nil {
if errors.Is(err, flag.ErrHelp) {
return 0
@@ -53,7 +50,6 @@ func runCommand(args []string, getenv func(string) string, stderr io.Writer, run
if err := runWorker(ctx, agentworker.Settings{
NATSURL: natsURL,
NATSToken: natsToken,
Consumer: *consumer,
}, log); err != nil {
return 1
}
+3 -2
View File
@@ -21,6 +21,7 @@ func TestRunCommandPreservesCLIExitSemantics(t *testing.T) {
}{
{name: "help", args: []string{"-h"}},
{name: "flag parse error", args: []string{"-unknown"}, wantCode: 2},
{name: "removed consumer flag", args: []string{"-consumer", "legacy"}, wantCode: 2},
{name: "missing NATS URL", wantCode: 1},
{
name: "worker failure",
@@ -88,8 +89,8 @@ func TestRunCommandMapsWorkerOutcomeToExitStatus(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var stderr bytes.Buffer
code := runCommand([]string{"-nats-url", "nats://flag", "-consumer", "custom"}, func(string) string { return "token" }, &stderr, func(_ context.Context, settings agentworker.Settings, _ *slog.Logger) error {
if settings.NATSURL != "nats://flag" || settings.NATSToken != "token" || settings.Consumer != "custom" {
code := runCommand([]string{"-nats-url", "nats://flag"}, func(string) string { return "token" }, &stderr, func(_ context.Context, settings agentworker.Settings, _ *slog.Logger) error {
if settings.NATSURL != "nats://flag" || settings.NATSToken != "token" {
t.Fatalf("settings = %#v", settings)
}
return test.workerErr
+4 -78
View File
@@ -31,7 +31,6 @@ import (
"github.com/samcharles93/archie-core/internal/domain/curator"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/domain/workflow/skillbuild"
"github.com/samcharles93/archie-core/internal/domain/workflow/wfeval"
"github.com/samcharles93/archie-core/internal/domain/workintake"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/forge"
@@ -107,8 +106,7 @@ type boot struct {
containerPool *container.Pool
storeBackend storage.Backend
providers map[string]agentexec.Provider
llm *runtime.Runtime
llm *runtime.Runtime
toolReg *tools.Registry
chatModels gateway.ModelManager
@@ -120,8 +118,6 @@ type boot struct {
webRouter *gateway.Router
startGateways []func()
agentRunner agentexec.Runner
registry workflow.Registry
capabilityHost *plugin.Host
trees *worktree.Manager
worktreeGrants *worktreerpc.Grants
@@ -401,7 +397,7 @@ func (b *boot) connectNATS(ctx context.Context) error {
natsClient, err := nats.Connect(ctx, nats.Config{
URL: url,
Token: natsToken,
Subjects: []string{workintake.SubjectTaskWildcard, agentexec.SubjectAgentWildcard},
Subjects: []string{workintake.SubjectTaskWildcard},
FilterSubject: workintake.SubjectTaskWildcard,
}, log)
if err != nil {
@@ -439,7 +435,6 @@ func (b *boot) setupLLMAndChat(ctx context.Context) {
// Created before gateways so the LLMResponder can be wired into the
// Telegram router for non-command message processing.
providers := executionProviders(cfg)
b.providers = providers
b.llm = agentexec.NewRuntime(providers)
b.toolReg = tools.NewRegistry()
chatModels := newChatModelManager(cfg.Models, cfg.Chat.Models, b.catalogModels)
@@ -582,39 +577,6 @@ func (b *boot) setupGateways(ctx context.Context, cfgPath, overlayPath string) b
return true
}
func (b *boot) buildAgentRunner() error {
cfg, log := b.cfg, b.log
if b.llm == nil {
return nil
}
switch cfg.Agent.Mode {
case "subprocess":
b.agentRunner = &agentexec.SubprocessRunner{
Command: cfg.Agent.Command,
Environ: os.Environ(),
AdditionalEnv: cfg.Agent.Env,
Diagnostics: os.Stderr,
Providers: b.providers,
}
case "inprocess":
inproc := agentexec.NewInProcessRunner(b.llm, log, b.toolReg)
inproc.Limits = toolLimits(cfg)
b.agentRunner = inproc
case "nats":
if b.natsClient == nil {
log.Error("agent.mode is nats but nats is unavailable (nats.mode is off)")
return fmt.Errorf("agent.mode is nats but nats is unavailable (nats.mode is off)")
}
b.agentRunner = &agentexec.NATSRunner{
Bus: b.natsClient,
Providers: b.providers,
MCPServers: cfg.Tools.MCPServers,
Log: log,
}
}
return nil
}
// loadWorkflows builds the workflow registry from the skill catalog.
// Plugin-defined workflows override built-ins of the same name;
// built-ins fill gaps.
@@ -629,9 +591,8 @@ func (b *boot) loadWorkflows(ctx context.Context) error {
log.Error("skill registry build failed", "err", err)
return err
}
b.registry = workflowCatalog.Registry
log.Info("workflow registry built", "workflows", len(b.registry))
b.web.Workflows = workflow.DefinitionsWithOrigins(b.registry, workflowCatalog.Origins)
log.Info("workflow registry built", "workflows", len(workflowCatalog.Registry))
b.web.Workflows = workflow.DefinitionsWithOrigins(workflowCatalog.Registry, workflowCatalog.Origins)
if l := cfg.Web.Listen; l != "" && l != "off" {
b.web.Token = webTokenFor(l, cfg.DBPath, log)
go func() {
@@ -707,29 +668,6 @@ func (b *boot) buildTreesAndIdentities(ctx context.Context) error {
log.Error("identity construction failed", "identity", idCfg.Name, "err", err)
return err
}
idProviders := agentexec.ProvidersFromConfig(idCfg.Providers)
idRuntime := agentexec.NewRuntime(idProviders)
if idRuntime != nil {
switch cfg.Agent.Mode {
case "subprocess":
runner.Agent = &agentexec.SubprocessRunner{
Command: cfg.Agent.Command,
Environ: os.Environ(),
AdditionalEnv: cfg.Agent.Env,
Diagnostics: os.Stderr,
Providers: idProviders,
}
case "inprocess":
idRunner := agentexec.NewInProcessRunner(idRuntime, log.With("identity", idCfg.Name), b.toolReg)
idRunner.Limits = toolLimits(cfg)
runner.Agent = idRunner
case "nats":
runner.Agent = &agentexec.NATSRunner{
Bus: b.natsClient, Providers: idProviders,
MCPServers: cfg.Tools.MCPServers, Log: log.With("identity", idCfg.Name),
}
}
}
b.identityRunners = append(b.identityRunners, runner)
log.Info("identity configured", "identity", idCfg.Name, "bot_user", idCfg.BotUser, "repos", len(idCfg.Repos))
}
@@ -1007,12 +945,9 @@ func (b *boot) buildDaemon() {
Bus: b.bus,
Forge: b.forgeClient,
Trees: b.trees,
Agent: b.agentRunner,
Workflows: b.registry,
CapabilityHost: b.capabilityHost,
Storage: b.storeBackend,
Log: log,
CustomStages: wfeval.Discover,
Tasks: b.natsClient,
WorktreeGrants: b.worktreeGrants,
ContainerPool: b.containerPool,
@@ -1329,15 +1264,6 @@ func (b *boot) setupBackends(ctx context.Context) error {
return err
}
// buildAgentAndWorkflows builds the agent runner and the workflow
// registry it executes.
func (b *boot) buildAgentAndWorkflows(ctx context.Context) error {
if err := b.buildAgentRunner(); err != nil {
return err
}
return b.loadWorkflows(ctx)
}
// shutdownCuratorRuntime returns a cleanup that stops the curator
// runtime. The stop path derives its own timeout budget from Background
// rather than the boot context, which is already cancelled by the time
+3 -3
View File
@@ -360,7 +360,7 @@ func run() int {
return 1
}
if err := b.buildAgentAndWorkflows(ctx); err != nil {
if err := b.loadWorkflows(ctx); err != nil {
return 1
}
if err := b.loadPlugins(); err != nil {
@@ -704,8 +704,8 @@ func subscribeSystemLogs(nc *natsio.Conn, taskLogs *logging.TaskRegistry, log *s
// in-process and invisible to the daemon; this is the other half of the
// bridge, landing them on bus so persistAndBroadcastEvents -- the single
// choke point that inserts into the SQLite events table and fans out over
// SSE -- treats them exactly like an in-process daemon-run workflow's own
// events. Mirrors subscribeSystemLogs's demux-by-taskID shape.
// SSE -- treats them exactly like every other daemon-observed event. Mirrors
// subscribeSystemLogs's demux-by-taskID shape.
func subscribeAgentEvents(nc *natsio.Conn, bus *events.Bus, log *slog.Logger) (unsubscribe func(), err error) {
sub, err := nc.Subscribe(agentexec.SubjectEventsWildcard, func(msg *natsio.Msg) {
taskID, ok := agentexec.TaskIDFromEventsSubject(msg.Subject)
+3
View File
@@ -158,6 +158,9 @@ var reloadableFields = map[string]bool{
// per-task half of this list is pinned mechanically; this webui-only
// entry is pinned by TestChangedNonReloadableFields.
"MaxRetries": true,
// [agent] is a decode-only compatibility shim; changes have no runtime
// consumer and therefore require neither reload nor restart.
"LegacyAgent": true,
}
// reloadableSubFields are sub-fields of structs that are otherwise
+7 -6
View File
@@ -31,7 +31,7 @@ func minimalConfigTOML(botUser string) string {
}
func invalidConfigTOML() string {
return "bot_user = \"widget\"\nagent = { mode = \"bogus-mode\" }\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"
return "bot_user = \"widget\"\ndispatch = { trigger = \"bogus-trigger\" }\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"
}
func TestReloadAppliesAndPublishes(t *testing.T) {
@@ -212,11 +212,12 @@ func TestChangedNonReloadableFields(t *testing.T) {
t.Fatalf("reloadable-only: got %v, want []", got)
}
// A non-reloadable change is named (Agent builds the startup runner).
nonReloadable := base
nonReloadable.Agent = config.Agent{Mode: "subprocess"}
if got := changedNonReloadableFields(base, nonReloadable); len(got) != 1 || got[0] != "Agent" {
t.Fatalf("Agent change: got %v, want [Agent]", got)
// The removed [agent] section remains decode-only for old files. Changing
// it has no running consumer and must not claim a restart will apply it.
legacyOnly := base
legacyOnly.LegacyAgent = config.LegacyAgent{Mode: "subprocess"}
if got := changedNonReloadableFields(base, legacyOnly); len(got) != 0 {
t.Fatalf("legacy agent change: got %v, want []", got)
}
// Containers sub-field granularity: Image change warns, MaxConcurrency