merge: lane B (forge-2 flagged, daemon-1, persistence-2)

This commit is contained in:
sam committed 2026-09-15 13:04:28 +10:00
commit ab2793e87f
2 files changed
+53 -48

No files matched your search

+6 -48
View File
@@ -124,8 +124,11 @@ type Daemon struct {
Trees *worktree.Manager
Bus *events.Bus
Log *slog.Logger
// Tasks is the optional message bus for task distribution. Nil means no
// bus is configured; the existing SQLite ClaimNext flow is used.
// Tasks is the NATS task distribution bus: the poller publishes
// discovered work over it and runViaAgent requests execution through it.
// NATS startup is mandatory (there is no broker-off execution mode), so
// production composition always sets it. Nil appears only in tests and
// is handled fail-closed at the publish/run sites.
Tasks TaskBus
WorktreeGrants WorktreeGrantIssuer
// StateStoreGrants issues per-task State Store credentials for container
@@ -381,8 +384,6 @@ func (d *Daemon) pollForIdentity(ctx context.Context, id *IdentityRunner) {
labels := strings.Join(is.Labels, ",")
if d.Tasks != nil {
d.pollNATS(ctx, id.Forge, cfg, repo, is, labels, id.Name)
} else {
d.pollSQLite(ctx, id.Forge, cfg, repo, is, labels, id.Name)
}
}
}
@@ -398,8 +399,6 @@ func (d *Daemon) maintainAndDrain(ctx context.Context) {
d.dispatchBindings(ctx)
if d.Tasks != nil {
d.drainNATS(ctx)
} else {
d.drainSQLite(ctx)
}
}
@@ -474,8 +473,6 @@ func (d *Daemon) Cycle(ctx context.Context) {
d.dispatchBindings(ctx)
if d.Tasks != nil {
d.drainNATS(ctx)
} else {
d.drainSQLite(ctx)
}
}
@@ -495,23 +492,6 @@ func (d *Daemon) cleanupExpiredStorage(ctx context.Context) {
}
}
// drainSQLite claims queued tasks from SQLite and dispatches them concurrently.
func (d *Daemon) drainSQLite(ctx context.Context) {
dispatcher := newTaskDispatcher(d.Cfg.Get().Containers.MaxConcurrency, d.allowConcurrentForTask)
for ctx.Err() == nil {
task, err := d.Store.ClaimNext(ctx)
if err != nil {
d.Log.Error("claim failed", "err", err)
break
}
if task == nil {
break
}
dispatcher.Submit(ctx, task, d.process)
}
dispatcher.Wait()
}
// bindingDispatchBatchLimit caps how many undispatched captures a single
// dispatchBindings pass will fetch from the store. The cap is defensive
// (the captures table is also pruned by retention/maxEvents) and bounds a
@@ -835,34 +815,11 @@ func (d *Daemon) poll(ctx context.Context) {
labels := strings.Join(is.Labels, ",")
if d.Tasks != nil {
d.pollNATS(ctx, d.Forge, d.Cfg.Get(), repo, is, labels, "")
} else {
d.pollSQLite(ctx, d.Forge, d.Cfg.Get(), repo, is, labels, "")
}
}
}
}
// pollSQLite enqueues discovered issues directly into SQLite (existing flow).
// fg is the forge client that discovered is -- d.Forge for the
// single-identity path, or an identity's own client from pollForIdentity.
// cfg is the dispatch config that owns this poll (root or identity-scoped).
// identity records which identity owns the resulting task; empty for
// single-identity deployments.
func (d *Daemon) pollSQLite(ctx context.Context, fg forge.Forge, cfg config.Config, repo config.Repo, is forge.Issue, labels, identity string) {
inserted, err := d.Store.EnqueueIssue(ctx,
repo.Owner, repo.Name, is.Number, is.Title, is.Body, labels, identity)
if err != nil {
d.Log.Error("enqueue failed", "repo", repo.FullName(), "issue", is.Number, "err", err)
return
}
if inserted {
d.acknowledge(ctx, fg, cfg, repo, is)
return
}
// Existing tasks are left untouched. Retry and approval are explicit
// operator actions in messaging or the Web UI, not forge-side label edits.
}
// pollNATS publishes discovered issues to NATS (new flow).
func (d *Daemon) pollNATS(ctx context.Context, fg forge.Forge, cfg config.Config, repo config.Repo, is forge.Issue, labels, identity string) {
// Read-only existence check prevents rediscovering an existing task.
@@ -1338,6 +1295,7 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
Repo: repo,
Cfg: d.configFor(task).ForTask(),
Providers: agentexec.ProvidersFromConfig(d.configFor(task).Providers),
MCPServers: d.configFor(task).Tools.MCPServers,
WorktreeGrant: grant,
KindWorkflows: d.KindWorkflows,
LabelWorkflows: d.LabelWorkflows,
+47
View File
@@ -734,6 +734,53 @@ func TestRunViaAgentSendsExpectedRequest(t *testing.T) {
}
}
// TestRunViaAgentSendsMCPServers is the daemon half of persistence-2: the
// configured daemon-wide MCP servers must be carried in the taskrun request
// so the archie-agent worker can construct transports and register their
// tools (task_execution.go startMCPProviders). A request missing them leaves
// the whole agent-side MCP tool path dead.
func TestRunViaAgentSendsMCPServers(t *testing.T) {
d, s, busClient := daemonWithNATS(t)
cfg := d.Cfg.Get()
cfg.Tools.MCPServers = []config.MCPServer{
{Name: "mcp-npm", Transport: "stdio", Command: "npx", Args: []string{"-y", "@modelcontextprotocol/server-filesystem"}},
}
d.Cfg.Set(cfg)
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 10, "t", "b", "", ""); err != nil {
t.Fatal(err)
}
task, err := s.ClaimNext(ctx)
if err != nil || task == nil {
t.Fatalf("claim: (%v, %v)", task, err)
}
received := make(chan taskrun.Request, 1)
sub, err := mustCoreConn(t, busClient).Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
var req taskrun.Request
_ = json.Unmarshal(msg.Data, &req)
received <- req
data, _ := json.Marshal(taskrun.Response{Status: workflow.StatusPROpen})
_ = msg.Respond(data)
})
if err != nil {
t.Fatalf("subscribe: %v", err)
}
t.Cleanup(func() { _ = sub.Unsubscribe() })
d.runViaAgent(ctx, task, config.Repo{Owner: "acme", Name: "widget", Base: "main"})
select {
case req := <-received:
if len(req.MCPServers) != 1 || req.MCPServers[0].Name != "mcp-npm" {
t.Fatalf("request MCPServers = %+v, want the configured mcp-npm server", req.MCPServers)
}
case <-time.After(time.Second):
t.Fatal("archied did not publish a taskrun request")
}
}
// TestRunViaAgentSendsRoutingBindings is the daemon half of
// workflow-engine-1: the kind/label -> workflow bindings the daemon loaded
// must be carried in the taskrun request, because workflow.Route runs in the