fix(agentexec): clip tool detail on a rune boundary, stop resuming without a session, keep captures when the ready marker fails, log with context
deploy / plan (push) Failing after 1s
deploy / gate (push) Skipped
deploy / archied-image (push) Skipped
deploy / agent-image (push) Skipped
deploy / dist-zip (push) Skipped

This commit is contained in:
sam committed 2026-11-09 01:41:46 +11:00
1 parent 1ef576ca7b
commit b15858adc9
5 files changed
+27 -11

No files matched your search

+7 -3
View File
@@ -10,6 +10,7 @@ import (
"io"
"os"
"sync"
"sync/atomic"
"github.com/modelcontextprotocol/go-sdk/mcp"
@@ -142,12 +143,15 @@ func ServeCaptureFiles(ctx context.Context, specPath, capturesPath string, t mcp
}
defer sink.Close()
server := mcp.NewServer(&mcp.Implementation{Name: "archie", Version: "1"}, nil)
var ready atomic.Bool
server.AddReceivingMiddleware(func(next mcp.MethodHandler) mcp.MethodHandler {
return func(ctx context.Context, method string, req mcp.Request) (mcp.Result, error) {
result, err := next(ctx, method, req)
if err == nil && (method == "tools/list" || method == "tools/call") {
if err := os.WriteFile(capturesPath+".ready", nil, 0o600); err != nil {
return nil, fmt.Errorf("record MCP initialization: %w", err)
if err == nil && (method == "tools/list" || method == "tools/call") && !ready.Load() {
// A call is already recorded by now, so a failed marker must not
// turn it into a tool error; the runner reports the missing marker.
if os.WriteFile(capturesPath+".ready", nil, 0o600) == nil {
ready.Store(true)
}
}
return result, err
+9 -3
View File
@@ -144,7 +144,11 @@ func (r *HarnessRunner) run(ctx context.Context, workspace string, req agentrun.
if res.Iterations >= maxIterations {
return park(res, StopGate, gateOutput), nil
}
verb, prompt = resumeVerb(req.Harness, session), "The quality gate failed. Fix the cause, then stop.\n\n"+gateOutput
verb = resumeVerb(req.Harness, session)
if len(verb) == 0 {
return park(res, StopGate, gateOutput), nil
}
prompt = "The quality gate failed. Fix the cause, then stop.\n\n" + gateOutput
}
}
@@ -230,7 +234,9 @@ func harnessArgv(h *agentrun.HarnessSpec, verb []string, prompt, session, mcpCon
}
// resumeVerb continues the session the last invocation reported, falling
// back to the most recent session when the CLI reported none.
// back to the most recent session when the CLI reported none. It returns nil
// when neither is possible: resuming with an empty session ID would start a
// broken command.
func resumeVerb(h *agentrun.HarnessSpec, sessionID string) []string {
if len(h.Resume) > 0 && sessionID != "" {
return slices.Clone(h.Resume)
@@ -238,7 +244,7 @@ func resumeVerb(h *agentrun.HarnessSpec, sessionID string) []string {
if len(h.Continue) > 0 {
return slices.Clone(h.Continue)
}
return slices.Clone(h.Resume)
return nil
}
// invoke runs one harness invocation in its own process group, feeding
+6 -1
View File
@@ -7,6 +7,7 @@ import (
"path/filepath"
"slices"
"strings"
"unicode/utf8"
"github.com/google/jsonschema-go/jsonschema"
@@ -23,7 +24,11 @@ func ClipToolCallDetail(s string) string {
if len(s) <= toolCallDetailBytes {
return s
}
return s[:toolCallDetailBytes] + "…"
cut := toolCallDetailBytes
for cut > 0 && !utf8.RuneStart(s[cut]) {
cut--
}
return s[:cut] + "…"
}
func ProjectScopedRules(workspace, extra string) string {
+4 -3
View File
@@ -1,6 +1,7 @@
package agentexec
import (
"context"
"encoding/json"
"log/slog"
@@ -14,16 +15,16 @@ type EventPublisher interface {
// ForwardTaskEvents publishes every event from sub to SubjectForEvents(taskID)
// until sub closes. Failures are logged.
func ForwardTaskEvents(sub *events.Sub, pub EventPublisher, taskID int64, log *slog.Logger) {
func ForwardTaskEvents(ctx context.Context, sub *events.Sub, pub EventPublisher, taskID int64, log *slog.Logger) {
subject := SubjectForEvents(taskID)
for e := range sub.C {
data, err := json.Marshal(e)
if err != nil {
log.Warn("task event marshal failed", "task", taskID, "kind", e.Kind, "err", err)
log.WarnContext(ctx, "task event marshal failed", "task", taskID, "kind", e.Kind, "err", err)
continue
}
if err := pub.Publish(subject, data); err != nil {
log.Warn("task event publish failed", "task", taskID, "kind", e.Kind, "err", err)
log.WarnContext(ctx, "task event publish failed", "task", taskID, "kind", e.Kind, "err", err)
}
}
}
+1 -1
View File
@@ -247,7 +247,7 @@ func runTask(ctx context.Context, req taskrun.Request, dependencies taskDependen
bus = events.NewBus()
sub := bus.Subscribe(64)
defer sub.Close()
go agentexec.ForwardTaskEvents(sub, dependencies.events, req.Task.ID, log)
go agentexec.ForwardTaskEvents(ctx, sub, dependencies.events, req.Task.ID, log)
}
tc := &workflow.TaskContext{