diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-04-04 21:59:58 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-05-03 17:58:25 +0000 |
| commit | 25cf4c9d4d6f3c18ee7565bf8e6172896fff00c3 (patch) | |
| tree | c5e2556800d428209f367af574e64765856b835d /internal/executor/executor_test.go | |
| parent | 49cdcd70f275c858b0511a2e88ab30a48b157fa3 (diff) | |
fix: prevent SHIPPABLE stories and wrong READY state on failed tasks
Three related bugs fixed:
1. maybeUnblockParent: guard against promoting QUEUED leaf tasks (no
subtasks) to READY. The vacuously-true 'all subtasks done' check was
advancing tasks that stalled in QUEUED (due to a prior SQLite lock
error) to READY on server restart via RecoverStaleBlocked, despite
having only failed executions and no commits.
2. checkStoryCompletion: require COMPLETED (not just READY) for all
top-level tasks before advancing a story to SHIPPABLE. READY means
the checker agent is still pending or the task awaits human review;
a story with READY tasks is not ready to ship.
3. handleAcceptTask: call CheckStoryCompletion after a task is accepted
so stories with parent tasks (whose subtasks are all done and then
the parent is manually accepted) can auto-advance to SHIPPABLE.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/executor/executor_test.go')
| -rw-r--r-- | internal/executor/executor_test.go | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/internal/executor/executor_test.go b/internal/executor/executor_test.go index 94ba65d..cb8205d 100644 --- a/internal/executor/executor_test.go +++ b/internal/executor/executor_test.go @@ -783,13 +783,80 @@ func TestPool_RecoverStaleBlocked_PromotesQueuedParentWithAllSubtasksDone(t *tes t.Errorf("parent state: want READY, got %s", got.State) } - // Story should have been advanced to SHIPPABLE. + // Story should still be IN_PROGRESS — READY tasks don't satisfy the completion check; + // the task must be accepted (READY → COMPLETED) before the story advances to SHIPPABLE. s, err := store.GetStory(story.ID) if err != nil { t.Fatalf("GetStory: %v", err) } - if s.Status != task.StoryShippable { - t.Errorf("story status: want SHIPPABLE, got %s", s.Status) + if s.Status != task.StoryInProgress { + t.Errorf("story status: want IN_PROGRESS, got %s", s.Status) + } +} + +// TestPool_RecoverStaleBlocked_DoesNotPromoteQueuedLeafTask verifies that a top-level +// QUEUED task with NO subtasks is not promoted to READY by RecoverStaleBlocked. +// This guards against the bug where a task that failed to start (stuck in QUEUED due +// to a DB error) was incorrectly promoted to READY because the "all subtasks done" +// check is vacuously true when there are no subtasks. +func TestPool_RecoverStaleBlocked_DoesNotPromoteQueuedLeafTask(t *testing.T) { + store := testStore(t) + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})) + pool := NewPool(2, map[string]Runner{"claude": &mockRunner{}}, store, logger) + + // A top-level task stuck in QUEUED with no subtasks (e.g. DB lock prevented RUNNING transition). + leaf := makeTask("queued-leaf-no-subtasks") + leaf.State = task.StateQueued + store.CreateTask(leaf) + + pool.RecoverStaleBlocked() + + got, err := store.GetTask(leaf.ID) + if err != nil { + t.Fatalf("GetTask: %v", err) + } + if got.State != task.StateQueued { + t.Errorf("leaf task state: want QUEUED (unchanged), got %s", got.State) + } +} + +// TestPool_CheckStoryCompletion_ReadyTasksNotSufficient verifies that READY tasks +// alone do not advance a story to SHIPPABLE — tasks must be COMPLETED. +func TestPool_CheckStoryCompletion_ReadyTasksNotSufficient(t *testing.T) { + store := testStore(t) + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})) + pool := NewPool(2, map[string]Runner{"claude": &mockRunner{}}, store, logger) + + now := time.Now().UTC() + story := &task.Story{ + ID: "story-ready-only", + Name: "Ready Only Story", + Status: task.StoryInProgress, + CreatedAt: now, + UpdatedAt: now, + } + store.CreateStory(story) + + // One task driven to READY (checker pending), one COMPLETED. + tk1 := makeTask("ro-task-1") + tk1.StoryID = story.ID + store.CreateTask(tk1) + for _, s := range []task.State{task.StateQueued, task.StateRunning, task.StateReady} { + store.UpdateTaskState(tk1.ID, s) + } + + tk2 := makeTask("ro-task-2") + tk2.StoryID = story.ID + store.CreateTask(tk2) + for _, s := range []task.State{task.StateQueued, task.StateRunning, task.StateReady, task.StateCompleted} { + store.UpdateTaskState(tk2.ID, s) + } + + pool.checkStoryCompletion(context.Background(), story.ID) + + got, _ := store.GetStory(story.ID) + if got.Status != task.StoryInProgress { + t.Errorf("story status: want IN_PROGRESS (tk1 still READY/checker pending), got %s", got.Status) } } @@ -1652,7 +1719,7 @@ func TestPool_CheckStoryCompletion_AllComplete(t *testing.T) { t.Fatalf("CreateStory: %v", err) } - // Create two top-level story tasks and drive them through valid transitions to READY. + // Create two top-level story tasks and drive them through valid transitions to COMPLETED. for i, id := range []string{"sctask-1", "sctask-2"} { tk := makeTask(id) tk.StoryID = "story-comp-1" @@ -1660,7 +1727,7 @@ func TestPool_CheckStoryCompletion_AllComplete(t *testing.T) { if err := store.CreateTask(tk); err != nil { t.Fatalf("CreateTask %d: %v", i, err) } - for _, s := range []task.State{task.StateQueued, task.StateRunning, task.StateReady} { + for _, s := range []task.State{task.StateQueued, task.StateRunning, task.StateReady, task.StateCompleted} { if err := store.UpdateTaskState(id, s); err != nil { t.Fatalf("UpdateTaskState %s → %s: %v", id, s, err) } |
