fix: three quick-wins to close PRD gaps

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.<id>.<stage>) to per-task (archie.agent.<id>.request).
Stage name is carried in the AgentRequestMessage payload. PRD section 2.
This commit is contained in:
sam committed 2026-07-22 02:57:41 +10:00
1 parent fc33e519a5
commit c8b22aeb8e
3 files changed
+18 -7

No files matched your search

+1 -1
View File
@@ -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)
+12 -3
View File
@@ -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,
+5 -3
View File
@@ -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.