feat(934): typed Stage enum replaces directory-string state model
The state machine's `Stage` enum becomes the source of truth for pipeline
state. Six stages of work land together:
1. Clean wire vocabulary (`coding`, `merge`, `merge_failure`, ...) replaces
legacy directory-style strings (`2_current`, `4_merge`, ...) on the wire.
`Stage::from_dir` accepted both during deployment; new writes always
emit the clean form via `stage_dir_name`. Lexicographic `dir >= "5_done"`
checks in lifecycle.rs become typed `matches!` checks since the new
vocabulary doesn't sort in pipeline order.
2. `crdt_state::write_item` takes typed `&Stage`, serialising via
`stage_dir_name` at the CRDT boundary. `#[cfg(test)] write_item_str`
parses legacy strings for test fixtures.
3. `WorkItem::stage()` returns typed `crdt_state::Stage`; `stage_str()`
is gone from the public API. Projection dispatches on the typed enum.
4. `frozen` becomes an orthogonal CRDT register. `Stage::Frozen` and
`PipelineEvent::Freeze`/`Unfreeze` are removed; `transition_to_frozen`/
`unfrozen` set the flag directly without touching the stage register.
5. Watcher sweep and `tool_update_story`'s `blocked` setter route through
`apply_transition` so the typed transition table validates every
stage change. `update_story` gains a `frozen` field for symmetry.
6. One-shot startup migration rewrites pre-934 directory-style stage
registers (and sets `frozen=true` on items previously at `7_frozen`).
`Stage::from_dir` drops legacy aliases. The db boundary keeps a small
normaliser so callers with legacy strings (MCP, tests) still work.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -243,7 +243,7 @@ max_turns = 10
|
||||
let story_id = "42_story_runaway";
|
||||
let initial = "---\nname: Runaway Story\n---\n# Runaway Story\n";
|
||||
crate::db::write_content(story_id, initial);
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
story_id,
|
||||
"2_current",
|
||||
Some("Runaway Story"),
|
||||
@@ -274,10 +274,10 @@ max_turns = 10
|
||||
let item = crate::crdt_state::read_item(story_id)
|
||||
.expect("story must be in CRDT after watchdog termination");
|
||||
assert_eq!(
|
||||
item.stage_str(),
|
||||
"2_blocked",
|
||||
item.stage().as_dir(),
|
||||
"blocked",
|
||||
"story stage must be 2_blocked after limit termination with max_retries=1 — got: {}",
|
||||
item.stage_str()
|
||||
item.stage().as_dir()
|
||||
);
|
||||
|
||||
// Sanity: the agent itself is also Failed with the right reason.
|
||||
@@ -371,7 +371,7 @@ max_turns = 10
|
||||
|
||||
let story_id = "story_e_per_session";
|
||||
crate::db::write_content(story_id, "---\nname: Per-Session Test\n---\n");
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
story_id,
|
||||
"2_current",
|
||||
Some("Per-Session Test"),
|
||||
@@ -416,8 +416,8 @@ max_turns = 10
|
||||
let item = crate::crdt_state::read_item(story_id)
|
||||
.expect("story must be in CRDT after per-session overrun");
|
||||
assert_eq!(
|
||||
item.stage_str(),
|
||||
"2_blocked",
|
||||
item.stage().as_dir(),
|
||||
"blocked",
|
||||
"story stage must be 2_blocked after per-session overrun with max_retries=1"
|
||||
);
|
||||
}
|
||||
@@ -451,7 +451,7 @@ max_turns = 10
|
||||
let initial = "---\nname: Retry Test\n---\n";
|
||||
crate::crdt_state::init_for_test();
|
||||
crate::db::write_content(story_id, initial);
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
story_id,
|
||||
"2_current",
|
||||
Some("Retry Test"),
|
||||
@@ -478,8 +478,8 @@ max_turns = 10
|
||||
"after session 1, retry_count should be 1 in CRDT"
|
||||
);
|
||||
assert_ne!(
|
||||
item.stage_str(),
|
||||
"2_blocked",
|
||||
item.stage().as_dir(),
|
||||
"blocked",
|
||||
"story should NOT be blocked after session 1"
|
||||
);
|
||||
}
|
||||
@@ -498,8 +498,8 @@ max_turns = 10
|
||||
"after session 2, retry_count should be 2 in CRDT"
|
||||
);
|
||||
assert_ne!(
|
||||
item.stage_str(),
|
||||
"2_blocked",
|
||||
item.stage().as_dir(),
|
||||
"blocked",
|
||||
"story should NOT be blocked after session 2"
|
||||
);
|
||||
}
|
||||
@@ -513,10 +513,10 @@ max_turns = 10
|
||||
|
||||
let item = crate::crdt_state::read_item(story_id).expect("story must be in CRDT");
|
||||
assert_eq!(
|
||||
item.stage_str(),
|
||||
"2_blocked",
|
||||
item.stage().as_dir(),
|
||||
"blocked",
|
||||
"story must be blocked after session 3 (retry_count=3 >= max_retries=3) — got: {}",
|
||||
item.stage_str()
|
||||
item.stage().as_dir()
|
||||
);
|
||||
// retry_count resets to 0 on stage transition (Bug 780) — the fact
|
||||
// that the story reached 2_blocked proves the retry limit was hit.
|
||||
|
||||
Reference in New Issue
Block a user