Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/forge_loop/cli_status_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def _cmd_status(self, args: SimpleNamespace) -> int:
)
except json.JSONDecodeError:
pass
runner_stale = state_blob.get("state") == "running" and not pid_alive
active_workers = list(active_workers_by_issue.values())
runner_stale = state_blob.get("state") == "running" and not pid_alive and not active_workers
if not active_workers and state_blob.get("state") == "running":
for entry in state_blob.get("dispatched") or []:
if (
Expand Down
41 changes: 41 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,47 @@ def test_status_json_reports_active_workers_from_events(
assert blob["active_workers"][0]["status"] == "running"


def test_status_json_does_not_mark_confirmed_foreground_worker_stale(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path, capsys: pytest.CaptureFixture[str]
) -> None:
fake_cfg = SimpleNamespace(
pid_file=tmp_path / "pid",
state_dir=tmp_path,
stop_file=tmp_path / "stop",
state_file=tmp_path / "state.json",
events_file=tmp_path / "events.jsonl",
github_repo="o/r",
labels=SimpleNamespace(ready="loop:ready"),
)
fake_cfg.state_file.write_text(
json.dumps({"state": "running", "tick": 3, "dispatched": [{"issue": 9, "title": "x"}]})
)
fake_cfg.events_file.write_text(
json.dumps(
{
"ts": "2026-05-30T10:00:00Z",
"kind": "worker_start",
"issue": 9,
"title": "x",
}
)
+ "\n"
)
monkeypatch.setattr(cli, "load", lambda: fake_cfg)
monkeypatch.setattr(
cli.subprocess,
"run",
lambda *a, **k: (_ for _ in ()).throw(FileNotFoundError("gh")),
)

rc = cli._cmd_status(SimpleNamespace(json=True))

assert rc == 0
blob = json.loads(capsys.readouterr().out)
assert blob["runner_stale"] is False
assert blob["active_workers"][0]["status"] == "running"


def test_status_json_falls_back_to_dispatched_state_when_worker_events_missing(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path, capsys: pytest.CaptureFixture[str]
) -> None:
Expand Down
Loading