fix(gateway): cap task_spawn titles and carry instructions into the body

This commit is contained in:
sam committed 2026-10-26 18:24:47 +11:00
1 parent c578c8e954
commit c4c50ea70d
2 files changed
+80 -1

No files matched your search

+18 -1
View File
@@ -24,6 +24,12 @@ const (
// maxTaskLogLimit bounds what the model can ask for in one call.
maxTaskLogLimit = 2000
// maxTaskTitleRunes bounds the title task_spawn will accept. The title is
// rendered on every surface that lists the task and becomes the PR title,
// so an unbounded one would bloat all of them; 80 matches the dashboard's
// work-request API.
maxTaskTitleRunes = 80
)
// ChatTaskSummary is the per-task view the task tools return. It is
@@ -218,8 +224,15 @@ func taskSpawnTool(creator TaskCreator, identity string) tools.ToolEntry {
"type": "object",
"properties": map[string]any{
"title": map[string]any{
"type": "string",
"description": fmt.Sprintf(
"What the task should accomplish, as one line of at most %d characters. Details go in instructions.",
maxTaskTitleRunes,
),
},
"instructions": map[string]any{
"type": "string",
"description": "What the task should accomplish, as a single instruction.",
"description": "The full request: context, acceptance criteria and constraints. Omit when the title says everything.",
},
"repo": map[string]any{
"type": "string",
@@ -241,6 +254,9 @@ func taskSpawnTool(creator TaskCreator, identity string) tools.ToolEntry {
if title == "" {
return nil, fmt.Errorf("task_spawn: title is required")
}
if len([]rune(title)) > maxTaskTitleRunes {
return nil, fmt.Errorf("task_spawn: title must be %d characters or fewer; put details in instructions", maxTaskTitleRunes)
}
var inputs map[string]any
if value, supplied := input["inputs"]; supplied {
@@ -253,6 +269,7 @@ func taskSpawnTool(creator TaskCreator, identity string) tools.ToolEntry {
id, err := creator.CreateTask(ctx, SpawnRequest{
Title: title,
Body: strings.TrimSpace(asString(input["instructions"])),
Repo: strings.TrimSpace(asString(input["repo"])),
Workflow: strings.TrimSpace(asString(input["workflow"])),
Inputs: inputs,
+62
View File
@@ -0,0 +1,62 @@
package gateway
import (
"context"
"strings"
"testing"
)
type recordingTaskCreator struct {
req SpawnRequest
called bool
}
func (r *recordingTaskCreator) CreateTask(_ context.Context, req SpawnRequest) (int64, error) {
r.req = req
r.called = true
return 1, nil
}
func TestTaskSpawnBoundsTitleAndCarriesInstructions(t *testing.T) {
cases := []struct {
name string
title string
instructions string
wantErr bool
wantBody string
}{
{"title at the 80 character limit", strings.Repeat("a", 80), " the details ", false, "the details"},
{"title over the 80 character limit", strings.Repeat("a", 81), "", true, ""},
{"title alone is complete", "Fix the flaky test", "", false, ""},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
creator := &recordingTaskCreator{}
entry := taskSpawnTool(creator, "identity")
input := map[string]any{"title": tc.title}
if tc.instructions != "" {
input["instructions"] = tc.instructions
}
_, err := entry.Handler(context.Background(), input)
if tc.wantErr {
if err == nil {
t.Fatal("expected an error")
}
if creator.called {
t.Fatal("task was created despite the error")
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if creator.req.Title != tc.title {
t.Errorf("title = %q, want %q", creator.req.Title, tc.title)
}
if creator.req.Body != tc.wantBody {
t.Errorf("body = %q, want %q", creator.req.Body, tc.wantBody)
}
})
}
}