fix: wire dead code — GracePeriod, task.json, plugin specs

GracePeriod now enforced in Release(): if > 0, container stays alive
for the configured duration after task completion before being killed,
per PRD section 1.

WriteTaskJSON now called from daemon.process() before container
Acquire, writing the task payload to <workspace>/task.json per
PRD section 3 /data/ layout.

PluginSpecs populated from TaskContext.SkillPlugins into the
Request sent to the agent. PluginSpec type added to protocol.go.
pluginSpecs() converts skill.Plugin → agentexec.PluginSpec for
transport. PRD section 5 Layer 1.
This commit is contained in:
sam committed 2026-07-22 03:31:27 +10:00
1 parent fab7a0ae6f
commit 4edad31b66
5 files changed
+75 -9

No files matched your search

+10
View File
@@ -77,6 +77,16 @@ type Request struct {
Protection Protection `json:"protection"`
Notes string `json:"notes,omitempty"`
CaptureTools []CaptureTool `json:"capture_tools,omitempty"`
// Plugins are bundled Yaegi plugins from the skill's plugins/
// directory. Each entry carries the name and source so the agent
// can register them as tools. PRD section 5 Layer 1.
Plugins []PluginSpec `json:"plugins,omitempty"`
}
// PluginSpec is a bundled Yaegi plugin passed from daemon to agent.
type PluginSpec struct {
Name string `json:"name"`
Src string `json:"src"`
}
// Validate rejects requests that this runner cannot safely interpret.
+10 -2
View File
@@ -168,18 +168,26 @@ func (p *Pool) Acquire(ctx context.Context, workspace string, env []string) (*Co
return &Container{ID: resp.ID}, nil
}
// Release stops and removes a container after a task completes.
// Release stops and removes a container after a task completes. If
// GracePeriod is configured, the container stays alive for that duration
// before being killed — the agent can handle follow-ups (gate re-runs,
// human replies) during this window. PRD section 1.
func (p *Pool) Release(c *Container) {
if c == nil {
return
}
// Honour the post-completion grace period.
if p.cfg.GracePeriod > 0 {
p.log.Info("container keeping alive for grace period", "id", c.ID[:12], "grace", p.cfg.GracePeriod)
time.Sleep(p.cfg.GracePeriod)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if _, err := p.cli.ContainerStop(ctx, c.ID, client.ContainerStopOptions{}); err != nil {
p.log.Warn("container stop failed", "id", c.ID[:12], "err", err)
}
// AutoRemove is set, but force-remove as a safety net.
p.cli.ContainerRemove(context.Background(), c.ID, client.ContainerRemoveOptions{Force: true})
p.mu.Lock()
+34 -6
View File
@@ -1,6 +1,9 @@
package container
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"time"
)
@@ -37,12 +40,37 @@ func TestContainerSupportsGracePeriod(t *testing.T) {
if cfg.MaxUptime == 0 {
t.Error("MaxUptime not set")
}
// Gap 2 assertion: Config needs GracePeriod alongside MaxUptime.
// MaxUptime = total container lifetime cap (creation → kill).
// GracePeriod = idle time after task completion before kill.
// Currently GracePeriod doesn't exist.
if cfg.MaxUptime > 0 {
// Placeholder: when GracePeriod is added, verify it exists.
// Gap 2 assertion: Release() must respect GracePeriod.
// Currently Release() calls ContainerStop immediately regardless of
// GracePeriod. When GracePeriod > 0, Release() must keep the
// container alive for the grace window before stopping it.
if cfg.GracePeriod > 0 {
// When GracePeriod is set, Release must not kill immediately.
// The container should stay alive for cfg.GracePeriod after
// the task completes, then be killed.
}
}
func TestWriteTaskJSONProducesValidFile(t *testing.T) {
dir := t.TempDir()
payload := TaskPayload{
ID: 42, Owner: "sam", Repo: "todo", Number: 170,
Title: "fix bug", Body: "body text",
Labels: []string{"bug"}, Workflow: "tdd",
}
if err := WriteTaskJSON(dir, payload); err != nil {
t.Fatal(err)
}
data, err := os.ReadFile(filepath.Join(dir, "task.json"))
if err != nil {
t.Fatal("task.json was not written:", err)
}
var decoded TaskPayload
if err := json.Unmarshal(data, &decoded); err != nil {
t.Fatal("task.json is not valid JSON:", err)
}
if decoded.ID != 42 || decoded.Workflow != "tdd" {
t.Errorf("decoded payload = %+v", decoded)
}
}
+7
View File
@@ -487,6 +487,13 @@ func (d *Daemon) process(ctx context.Context, task *store.Task) {
// Acquire a container for the task when Docker sandboxing is enabled.
if d.ContainerPool != nil {
workDir := d.Trees.Dir(task.Owner, task.Repo, task.IssueNumber)
// Write task.json — the container's boot-time brief.
_ = container.WriteTaskJSON(workDir, container.TaskPayload{
ID: task.ID, Owner: task.Owner, Repo: task.Repo,
Number: task.IssueNumber, Title: task.Title, Body: task.Body,
Labels: strings.Split(task.Labels, ","),
Workflow: task.Workflow, Branch: task.Branch, Plan: task.Plan,
})
ctr, err := d.ContainerPool.Acquire(ctx, workDir, d.containerEnv())
if err != nil {
d.Log.Error("container acquire failed", "err", err)
+14 -1
View File
@@ -120,7 +120,8 @@ func (a AgentStage) Stage() Stage {
Protection: protection,
Notes: tc.Task.Notes,
CaptureTools: captureTools,
}
Plugins: pluginSpecs(tc.SkillPlugins),
}
res, err := tc.Agent.Run(ctx, tc.Dir, req)
if err != nil && res.Version == 0 {
return fmt.Errorf("agent run: %w", err)
@@ -180,6 +181,18 @@ func GateFromRepo(repo config.Repo, budgets config.Budgets) agentexec.Gate {
return agentexec.Gate{Commands: cmds, MaxConsecutiveFailures: budgets.GateMaxFailures}
}
// pluginSpecs converts skill.Plugin to agentexec.PluginSpec for transport.
func pluginSpecs(plugins []skill.Plugin) []agentexec.PluginSpec {
if len(plugins) == 0 {
return nil
}
out := make([]agentexec.PluginSpec, len(plugins))
for i, p := range plugins {
out[i] = agentexec.PluginSpec{Name: p.Name, Src: p.Src}
}
return out
}
// missionWithSkill prepends the skill body (loaded from SKILL.md) to the
// stage's mission. When no skill is loaded, the mission is returned unchanged.
func missionWithSkill(tc *TaskContext, mission string) string {