From c4c50ea70ddbee9dac668d30f5fe51710df9e5ca Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 26 Oct 2026 18:19:09 +1100 Subject: [PATCH] fix(gateway): cap task_spawn titles and carry instructions into the body --- internal/gateway/task_tools.go | 19 ++++++++- internal/gateway/task_tools_test.go | 62 +++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 internal/gateway/task_tools_test.go diff --git a/internal/gateway/task_tools.go b/internal/gateway/task_tools.go index c20300bc4..525724b3a 100644 --- a/internal/gateway/task_tools.go +++ b/internal/gateway/task_tools.go @@ -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, diff --git a/internal/gateway/task_tools_test.go b/internal/gateway/task_tools_test.go new file mode 100644 index 000000000..b23d95076 --- /dev/null +++ b/internal/gateway/task_tools_test.go @@ -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) + } + }) + } +}