From 4b4ad951407ef45e4389314c5c0f9e384a82f25a Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 24 Feb 2026 17:11:59 +0000 Subject: [PATCH] story-kit: create 161_bug_auto_assign_only_triggers_on_agent_completion_not_on_failure_or_periodically --- ...mpletion_not_on_failure_or_periodically.md | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .story_kit/work/1_upcoming/161_bug_auto_assign_only_triggers_on_agent_completion_not_on_failure_or_periodically.md diff --git a/.story_kit/work/1_upcoming/161_bug_auto_assign_only_triggers_on_agent_completion_not_on_failure_or_periodically.md b/.story_kit/work/1_upcoming/161_bug_auto_assign_only_triggers_on_agent_completion_not_on_failure_or_periodically.md new file mode 100644 index 0000000..250c3f8 --- /dev/null +++ b/.story_kit/work/1_upcoming/161_bug_auto_assign_only_triggers_on_agent_completion_not_on_failure_or_periodically.md @@ -0,0 +1,45 @@ +--- +name: "Auto-assign only triggers on agent completion, not on failure or periodically" +--- + +# Bug 161: Auto-assign only triggers on agent completion, not on failure or periodically + +## Description + +`auto_assign_available_work()` is only called in two places: +1. On server startup (`server/src/main.rs:128`) +2. Inside `run_pipeline_advance_for_completed_agent` (`server/src/agents.rs` lines 830, 883, 945) + +This means when agents **fail** (e.g. after a server restart kills their PTY processes), work items sitting in `2_current/`, `3_qa/`, or `4_merge/` are never picked up by free agents. Auto-assign only fires when an agent completes successfully, not when one fails. + +## How to Reproduce + +1. Have agents running on stories +2. Restart the server — agents become Failed (orphaned PTY processes) +3. Move new stories into `2_current/` +4. Observe that no coder picks them up, even though coders are free (Failed status) + +## Expected Behavior + +Auto-assign should also trigger when: +- An agent transitions to Failed status +- A work item file appears in a pipeline stage directory (watcher event) + +## Suggested Fix + +Add an `auto_assign_available_work` call in the watcher event handler. When a `WatcherEvent::WorkItem` fires for `2_current/`, `3_qa/`, or `4_merge/`, trigger auto-assign. This way, moving a story file into a pipeline directory automatically tries to assign a free agent. + +Alternatively (or additionally), trigger auto-assign when `check_orphaned_agents` marks an agent as Failed. + +## Key Files + +- `server/src/agents.rs:1276` — `auto_assign_available_work()` +- `server/src/agents.rs:830,883,945` — only call sites after startup +- `server/src/agents.rs:1828` — `check_orphaned_agents()` — marks agents Failed but doesn't trigger auto-assign +- `server/src/main.rs:128` — startup call + +## Acceptance Criteria + +- [ ] When an agent fails, auto-assign runs to pick up unassigned work +- [ ] When a story file is moved into `2_current/`, `3_qa/`, or `4_merge/`, auto-assign runs +- [ ] Free agents pick up waiting work items without manual intervention