story-kit: mergemaster conflict resolution, vite proxy fix, bug 279
- Upgrade mergemaster prompt to resolve complex conflicts itself instead of just reporting failure. Includes instructions to check git history and story files for context before resolving. - Add proxy error handler to vite config to prevent crashes on backend ECONNREFUSED. - Fix bug 279: auto-assign now checks that preferred agent's stage matches the pipeline stage. Coders won't be assigned to QA/merge. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1468,10 +1468,12 @@ impl AgentPool {
|
||||
let preferred_agent =
|
||||
read_story_front_matter_agent(project_root, stage_dir, story_id);
|
||||
|
||||
// Outcome: (already_assigned, chosen_agent, preferred_busy)
|
||||
// Outcome: (already_assigned, chosen_agent, preferred_busy, stage_mismatch)
|
||||
// preferred_busy=true means the story has a specific agent requested but it is
|
||||
// currently occupied — the story should wait rather than fall back.
|
||||
let (already_assigned, free_agent, preferred_busy) = {
|
||||
// stage_mismatch=true means the preferred agent's stage doesn't match the
|
||||
// pipeline stage, so we fell back to a generic stage agent.
|
||||
let (already_assigned, free_agent, preferred_busy, stage_mismatch) = {
|
||||
let agents = match self.agents.lock() {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
@@ -1481,18 +1483,29 @@ impl AgentPool {
|
||||
};
|
||||
let assigned = is_story_assigned_for_stage(&config, &agents, story_id, stage);
|
||||
if assigned {
|
||||
(true, None, false)
|
||||
(true, None, false, false)
|
||||
} else if let Some(ref pref) = preferred_agent {
|
||||
// Story has a front-matter agent preference.
|
||||
if is_agent_free(&agents, pref) {
|
||||
(false, Some(pref.clone()), false)
|
||||
// Verify the preferred agent's stage matches the current
|
||||
// pipeline stage — a coder shouldn't be assigned to QA.
|
||||
let pref_stage_matches = config
|
||||
.find_agent(pref)
|
||||
.map(|cfg| agent_config_stage(cfg) == *stage)
|
||||
.unwrap_or(false);
|
||||
if !pref_stage_matches {
|
||||
// Stage mismatch — fall back to any free agent for this stage.
|
||||
let free = find_free_agent_for_stage(&config, &agents, stage)
|
||||
.map(|s| s.to_string());
|
||||
(false, free, false, true)
|
||||
} else if is_agent_free(&agents, pref) {
|
||||
(false, Some(pref.clone()), false, false)
|
||||
} else {
|
||||
(false, None, true)
|
||||
(false, None, true, false)
|
||||
}
|
||||
} else {
|
||||
let free = find_free_agent_for_stage(&config, &agents, stage)
|
||||
.map(|s| s.to_string());
|
||||
(false, free, false)
|
||||
(false, free, false, false)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1511,6 +1524,13 @@ impl AgentPool {
|
||||
continue;
|
||||
}
|
||||
|
||||
if stage_mismatch {
|
||||
slog!(
|
||||
"[auto-assign] Preferred agent '{}' stage mismatch for '{story_id}' in {stage_dir}/; falling back to stage-appropriate agent.",
|
||||
preferred_agent.as_deref().unwrap_or("?")
|
||||
);
|
||||
}
|
||||
|
||||
match free_agent {
|
||||
Some(agent_name) => {
|
||||
slog!(
|
||||
@@ -4748,4 +4768,130 @@ stage = "coder"
|
||||
"No agents should be assigned to a spike with review_hold"
|
||||
);
|
||||
}
|
||||
|
||||
// ── Story 279: auto-assign respects agent stage from front matter ──────────
|
||||
|
||||
/// When a story in 3_qa/ has `agent: coder-1` in its front matter but
|
||||
/// coder-1 is a coder-stage agent, auto-assign must NOT assign coder-1.
|
||||
/// Instead it should fall back to a free QA-stage agent.
|
||||
#[tokio::test]
|
||||
async fn auto_assign_ignores_coder_preference_when_story_is_in_qa_stage() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
let qa_dir = sk.join("work/3_qa");
|
||||
std::fs::create_dir_all(&qa_dir).unwrap();
|
||||
std::fs::write(
|
||||
sk.join("project.toml"),
|
||||
"[[agent]]\nname = \"coder-1\"\nstage = \"coder\"\n\n\
|
||||
[[agent]]\nname = \"qa-1\"\nstage = \"qa\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
// Story in 3_qa/ with a preferred coder-stage agent.
|
||||
std::fs::write(
|
||||
qa_dir.join("story-qa1.md"),
|
||||
"---\nname: QA Story\nagent: coder-1\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
|
||||
pool.auto_assign_available_work(tmp.path()).await;
|
||||
|
||||
let agents = pool.agents.lock().unwrap();
|
||||
// coder-1 must NOT have been assigned (wrong stage for 3_qa/).
|
||||
let coder_assigned = agents
|
||||
.values()
|
||||
.any(|a| a.agent_name == "coder-1" && matches!(a.status, AgentStatus::Pending | AgentStatus::Running));
|
||||
assert!(
|
||||
!coder_assigned,
|
||||
"coder-1 should not be assigned to a QA-stage story"
|
||||
);
|
||||
// qa-1 should have been assigned instead.
|
||||
let qa_assigned = agents
|
||||
.values()
|
||||
.any(|a| a.agent_name == "qa-1" && matches!(a.status, AgentStatus::Pending | AgentStatus::Running));
|
||||
assert!(
|
||||
qa_assigned,
|
||||
"qa-1 should be assigned as fallback for the QA-stage story"
|
||||
);
|
||||
}
|
||||
|
||||
/// When a story in 2_current/ has `agent: coder-1` in its front matter and
|
||||
/// coder-1 is a coder-stage agent, auto-assign must respect the preference
|
||||
/// and assign coder-1 (not fall back to some other coder).
|
||||
#[tokio::test]
|
||||
async fn auto_assign_respects_coder_preference_when_story_is_in_current_stage() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
let current_dir = sk.join("work/2_current");
|
||||
std::fs::create_dir_all(¤t_dir).unwrap();
|
||||
std::fs::write(
|
||||
sk.join("project.toml"),
|
||||
"[[agent]]\nname = \"coder-1\"\nstage = \"coder\"\n\n\
|
||||
[[agent]]\nname = \"coder-2\"\nstage = \"coder\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
// Story in 2_current/ with a preferred coder-1 agent.
|
||||
std::fs::write(
|
||||
current_dir.join("story-pref.md"),
|
||||
"---\nname: Coder Story\nagent: coder-1\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
|
||||
pool.auto_assign_available_work(tmp.path()).await;
|
||||
|
||||
let agents = pool.agents.lock().unwrap();
|
||||
// coder-1 should have been picked (it matches the stage and is preferred).
|
||||
let coder1_assigned = agents
|
||||
.values()
|
||||
.any(|a| a.agent_name == "coder-1" && matches!(a.status, AgentStatus::Pending | AgentStatus::Running));
|
||||
assert!(
|
||||
coder1_assigned,
|
||||
"coder-1 should be assigned when it matches the stage and is preferred"
|
||||
);
|
||||
// coder-2 must NOT be assigned (not preferred).
|
||||
let coder2_assigned = agents
|
||||
.values()
|
||||
.any(|a| a.agent_name == "coder-2" && matches!(a.status, AgentStatus::Pending | AgentStatus::Running));
|
||||
assert!(
|
||||
!coder2_assigned,
|
||||
"coder-2 should not be assigned when coder-1 is explicitly preferred"
|
||||
);
|
||||
}
|
||||
|
||||
/// When the preferred agent's stage mismatches and no other agent of the
|
||||
/// correct stage is available, auto-assign must not start any agent for that
|
||||
/// story (no panic, no error).
|
||||
#[tokio::test]
|
||||
async fn auto_assign_stage_mismatch_with_no_fallback_starts_no_agent() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let sk = tmp.path().join(".story_kit");
|
||||
let qa_dir = sk.join("work/3_qa");
|
||||
std::fs::create_dir_all(&qa_dir).unwrap();
|
||||
// Only a coder agent is configured — no QA agent exists.
|
||||
std::fs::write(
|
||||
sk.join("project.toml"),
|
||||
"[[agent]]\nname = \"coder-1\"\nstage = \"coder\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
// Story in 3_qa/ requests coder-1 (wrong stage) and no QA agent exists.
|
||||
std::fs::write(
|
||||
qa_dir.join("story-noqa.md"),
|
||||
"---\nname: QA Story No Agent\nagent: coder-1\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
|
||||
// Must not panic.
|
||||
pool.auto_assign_available_work(tmp.path()).await;
|
||||
|
||||
let agents = pool.agents.lock().unwrap();
|
||||
assert!(
|
||||
agents.is_empty(),
|
||||
"No agent should be started when no stage-appropriate agent is available"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user