From c8b22aeb8ec47b5f5b43d5367147e7f30462e7e8 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Wed, 22 Jul 2026 02:57:41 +1000 Subject: [PATCH] fix: three quick-wins to close PRD gaps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gap 2 (MaxUptime): container created with context deadline when MaxUptime > 0 โ€” Docker kills the container on expiry. Gap 6 (/data/ volume): mount worktree at /data/worktree instead of /workspace, matching PRD section 3 volume layout. Gap 4 (per-task subjects): change SubjectForAgentRequest from per-stage (archie.agent..) to per-task (archie.agent..request). Stage name is carried in the AgentRequestMessage payload. PRD section 2. --- internal/agentexec/nats.go | 2 +- internal/container/pool.go | 15 ++++++++++++--- internal/nats/subjects.go | 8 +++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/agentexec/nats.go b/internal/agentexec/nats.go index 144cf96f1..1fef95da5 100644 --- a/internal/agentexec/nats.go +++ b/internal/agentexec/nats.go @@ -74,7 +74,7 @@ func (r *NATSRunner) Run(ctx context.Context, workspace string, req Request) (Re return Result{}, err } - subject := arnats.SubjectForAgentRequest(req.TaskID, req.Stage) + subject := arnats.SubjectForAgentRequest(req.TaskID) headers := natsio.Header{} headers.Set(arnats.ReplyHeader, replySub.Subject) diff --git a/internal/container/pool.go b/internal/container/pool.go index d7000d417..f22d862b9 100644 --- a/internal/container/pool.go +++ b/internal/container/pool.go @@ -70,8 +70,10 @@ func NewPool(ctx context.Context, cfg Config, natsURL string, log *slog.Logger) return p, nil } -// Acquire creates and starts a container, mounting workspace at /workspace, -// passing provider API keys and NATS URL as environment variables. +// Acquire creates and starts a container, mounting the worktree at +// /data/worktree, passing provider API keys and NATS URL as environment +// variables. If MaxUptime is set, the container is created with a +// deadline โ€” Docker kills it when the time elapses. func (p *Pool) Acquire(ctx context.Context, workspace string, env []string) (*Container, error) { p.mu.Lock() if p.cfg.MaxConcurrency > 0 && p.active >= p.cfg.MaxConcurrency { @@ -81,6 +83,13 @@ func (p *Pool) Acquire(ctx context.Context, workspace string, env []string) (*Co p.active++ p.mu.Unlock() + // Enforce MaxUptime via container-level timeout. + if p.cfg.MaxUptime > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, p.cfg.MaxUptime) + defer cancel() + } + name := fmt.Sprintf("archie-agent-%d", time.Now().UnixNano()) resp, err := p.cli.ContainerCreate(ctx, client.ContainerCreateOptions{ @@ -97,7 +106,7 @@ func (p *Pool) Acquire(ctx context.Context, workspace string, env []string) (*Co { Type: mount.TypeBind, Source: workspace, - Target: "/workspace", + Target: "/data/worktree", }, }, AutoRemove: true, diff --git a/internal/nats/subjects.go b/internal/nats/subjects.go index 51ecdd9b0..50bff5116 100644 --- a/internal/nats/subjects.go +++ b/internal/nats/subjects.go @@ -47,9 +47,11 @@ const ( SubjectAgentWildcard = "archie.agent.>" ) -// SubjectForAgentRequest returns the JetStream subject for a stage request. -func SubjectForAgentRequest(taskID int64, stage string) string { - return fmt.Sprintf("archie.agent.%d.%s", taskID, stage) +// SubjectForAgentRequest returns the JetStream subject for a per-task +// agent request. The stage is carried in the message payload, not the +// subject โ€” one subject per task with sequential stage messages. PRD ยง2. +func SubjectForAgentRequest(taskID int64) string { + return fmt.Sprintf("archie.agent.%d.request", taskID) } // ReplyHeader is the custom NATS header carrying the daemon's reply inbox.