Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions local/skills/devflow/config/workflow.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "2.0",
"max_stage_failures": 2,
"stage_timeout_minutes": 60,
"max_batch_tasks": 3,
"required_approval_gates": ["REQUIREMENT"],
"manual_gates": ["DESIGN", "REVIEW", "TEST"],
Expand Down
23 changes: 23 additions & 0 deletions local/skills/devflow/scripts/workflow_state.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,28 @@ def command_status(args: argparse.Namespace) -> int:
return 0


def command_check_stalled(args: argparse.Namespace) -> int:
data = load(args.state)
timeout = DEFAULTS.get("stage_timeout_minutes", 60)
stamp = datetime.now(timezone.utc)
stalled = False
for name in data.get("route", []):
stage = data["stages"][name]
if stage.get("status") != "in_progress":
continue
started_at = stage.get("started_at")
if not started_at:
print(f"{name}: in_progress elapsed=unknown")
continue
elapsed = int((stamp - datetime.fromisoformat(started_at)).total_seconds() // 60)
if elapsed > timeout:
stalled = True
print(f"{name}: in_progress elapsed={elapsed}m STALLED (timeout={timeout}m)")
else:
print(f"{name}: in_progress elapsed={elapsed}m")
return 1 if stalled else 0


def can_upgrade_to_team(data: dict) -> bool:
if (
data.get("execution_policy_version") != 2
Expand Down Expand Up @@ -1202,6 +1224,7 @@ def main() -> int:
item.set_defaults(func=command_approve)
for name, func in (
("validate", command_validate), ("status", command_status),
("check-stalled", command_check_stalled),
("upgrade-team", command_upgrade_team), ("rotate-team", command_rotate_team),
):
item = sub.add_parser(name)
Expand Down
33 changes: 33 additions & 0 deletions local/skills/devflow/tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,39 @@ def test_codebuddy_adapter_requires_team_member_dispatch(self):
self.assertIn("cleanup_team.py", adapter)
self.assertIn("不得读取 Team 配置、成员、inbox 或状态", adapter)

def test_check_stalled_flags_stage_over_timeout(self):
from datetime import datetime, timedelta, timezone

with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
state_path = Path(
run_script(
"workflow_state.py", "init", "--project-root", root,
"--slug", "stall-check", "--size", "medium", "--mode", "auto",
"--execution-mode", "isolated", "--host-adapter", "codebuddy",
"--coordinator-id", "main-1",
).stdout.strip()
)
run_script("workflow_state.py", "prepare", "--state", state_path, "--stage", "REQUIREMENT")
run_script("workflow_state.py", "start", "--state", state_path, "--stage", "REQUIREMENT")
fresh = run_script(
"workflow_state.py", "check-stalled", "--state", state_path, check=False,
)
self.assertEqual(0, fresh.returncode)
self.assertIn("REQUIREMENT", fresh.stdout)
self.assertNotIn("STALLED", fresh.stdout)

state = json.loads(state_path.read_text(encoding="utf-8"))
old = datetime.now(timezone.utc) - timedelta(hours=2)
state["stages"]["REQUIREMENT"]["started_at"] = old.isoformat(timespec="seconds")
state_path.write_text(json.dumps(state), encoding="utf-8")
stalled = run_script(
"workflow_state.py", "check-stalled", "--state", state_path, check=False,
)
self.assertEqual(1, stalled.returncode)
self.assertIn("REQUIREMENT", stalled.stdout)
self.assertIn("STALLED", stalled.stdout)

def fill_stage_artifacts(self, state_path, stage):
state = json.loads(state_path.read_text(encoding="utf-8"))
artifact_root = Path(state["artifacts_dir"])
Expand Down