Stop false "ended without calling finish_scan" error on PR reviews (#1449)
Some checks are pending
CI / python (push) Waiting to run
CI / tui (push) Waiting to run
CI / viewer (push) Waiting to run
CI / package (push) Waiting to run
CI / workflows (push) Waiting to run
CI / ci-passed (push) Blocked by required conditions

* fix: don't log missing finish_scan when a PR review finished with finish_pr_review

* Updated comment
This commit is contained in:
ian-at-strix 2026-10-05 19:58:20 -04:00 • committed by GitHub
parent 03d2c6c168
commit d6db4f1f89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 10 deletions

View file

@ -592,16 +592,10 @@ async def run_strix_scan(
)
if not interactive and result is not None:
final = getattr(result, "final_output", None)
scan_completed = False
if isinstance(final, str):
try:
parsed = json.loads(final)
scan_completed = bool(isinstance(parsed, dict) and parsed.get("scan_completed"))
except (ValueError, TypeError):
scan_completed = False
elif isinstance(final, dict):
scan_completed = bool(final.get("scan_completed"))
if not scan_completed:
# Lifecycle tools mark the root completed.
async with coordinator._lock:
root_completed = coordinator.statuses.get(root_id) == "completed"
if not root_completed:
logger.error(
"Scan %s ended without calling finish_scan. The agent "
"emitted a text-only turn instead of a lifecycle tool call, "

View file

@ -91,3 +91,31 @@ async def test_a_live_child_is_settled_before_sessions_close(
task = child_task["t"]
assert task.done(), "the child task was left running past scan teardown"
assert task.cancelled(), "the child was not cancelled cleanly on a finish"
@pytest.mark.parametrize(("root_status", "logged"), [("completed", False), ("stopped", True)])
@pytest.mark.asyncio
async def test_missing_finish_is_logged_only_when_root_did_not_complete(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Any,
caplog: pytest.LogCaptureFixture,
root_status: str,
logged: bool,
) -> None:
_wire_runner(monkeypatch, tmp_path)
coordinator = AgentCoordinator()
async def _root_ends_with_text(**kwargs: Any) -> Any:
await coordinator.set_status(kwargs["agent_id"], root_status)
return types.SimpleNamespace(final_output="The review is complete.")
monkeypatch.setattr(runner, "run_agent_loop", _root_ends_with_text)
await runner.run_strix_scan(
scan_config={"targets": [], "scan_mode": "deep"},
scan_id="scan-test",
image="img",
coordinator=coordinator,
)
assert ("ended without calling finish_scan" in caplog.text) is logged