fix(model): a failed judge call is recorded and ends the asking (item 5b)

The maintainer's answer of 2026-11-27 to question 2 of the ninth session's menu, "Record and stop
asking", as offered: "a failed judge call adds a degradation to the manifest, with the count; the
report says those questions went unasked; after one transport failure the remaining questions are
not asked." Measured by the ninth session: with a key in the environment and no network, 16 judge
calls failed in one scan of a four-file subject, three attempts each, and each dropped its claim
as a "no" would (model/pipeline.py); the manifest counted model_calls 16 and recorded no failure,
and the report said less than that of a run without an endpoint.

What changed:
- model/scan.py, `_CountingClient`: a call that raises is counted in `failed` and ends the asking.
  The calls left in the question being put are refused without reaching the client (`refused`),
  and the driver withholds the judge from every question after it, as it does when the budget runs
  out. An answer with no decision in it (empty, not JSON, no boolean `vulnerable`) is counted in
  `failed` as well and does not end the asking. The graph still arbitrates every region.
- Two degradations, each with a sentence under "What could not be analysed" (reports.py) and a
  line in the scan skill's list:
  - `judge_calls_failed`, `count`: the judge calls that gave no decision.
  - `judge_withheld`, `questions`: the judge calls refused after the failure in the question
    being put. Of the questions after it the report says that none was put to the judge; they are
    not counted, because some of them would have put nothing to the judge.
- model/pipeline.py: the parsing half of `_ask` is moved as it was into `judge_decision`, so the
  driver reads a decision the way `_ask` does. `_ask` returns what it returned.
- The claim of every such question is still dropped, as before: "Keep the claim" was not chosen.

The session's two readings of the decision, open to correction:
- A transport failure is read as a judge call that raised, whatever the exception. The transport
  has already made its three attempts for what is transient (provider/openrouter.py), so one
  raised call ends the asking for the whole scan. That holds for a connection failure and for a
  timeout, and also for a request the endpoint refuses with an error status, where the transport
  makes one attempt: there the scan withholds every later question, where before it dropped that
  claim alone and went on. The judge_withheld line says so in the report.
- A failed judge call is read as a call that raised or a call whose answer gave no decision. Both
  are counted.

Measured on fresh copies of the four C files the ninth session used, with a placeholder key and
the network off (the scratch is /tmp/opencode/s10_c2_* and is not kept):
- Native, in a network namespace without routes: one "judge call failed" line, file_targets=4,
  findings=15, exit 0, 45 s (s10_c2_native_key3.out). The ninth session's run of the same bytes:
  16 lines, 68 s.
- In a probe image built from openultrasast:dev 3f959b31f2f2 with src copied over, network none:
  one line, file_targets=4, findings=15, exit 0, 43 s (s10_c2_image_key3.out). The ninth
  session's run: 16 lines, 65 s. The probe image is removed.
- Both manifests: model_calls 1, judge_calls_failed with count 1, judge_withheld with questions
  7; report.md carries the two sentences (s10_c2_native_inspect3.out, s10_c2_image_inspect3.out).
  The findings are the 15 the ninth session recorded with a key and without one.

Tests, one at a time, each red before its code:
- test_a_judge_that_cannot_be_reached_is_recorded_and_asked_no_further: on a git archive of
  HEAD, assert 120 == 1; after, one call, model_calls 1, ten regions arbitrated, the two
  degradations with count 1 and questions 5.
- test_a_judge_answer_with_no_decision_in_it_is_counted_and_the_rest_are_still_asked: red with
  no degradation; after, count 120 and no judge_withheld.
- test_a_failed_judge_call_is_reported_as_unasked_and_not_as_a_no: red with the two bare
  reasons; after, the two sentences. The three red runs, with the package imported from the
  archive, are in s10_c2_red8.out: 3 failed, 1 passed.
- GREEN: 657 passed over the 39 test files that name degradations, scan_repository, model_calls
  or write_markdown_report (s10_c2_green9.out); 214 passed over ten model, report and skill files
  (s10_c2_green8.out). ruff, mypy, the three gates and compileall pass, and the gates print what
  they printed before (s10_c2c_exits.txt). `git diff --check` exits 0. No whole-suite run: that is
  step 9.
- The review took three rounds on one reviewer. Round one approved a first shape that counted the
  withheld regions, and remarked that a region with several families was counted as withheld while
  its first family had been put to the judge; its other remarks changed the second sentence,
  `__all__` and a docstring. Round two blocked the sum that replaced that count: it added judge
  calls to region-and-family questions under one name. The count is of judge calls now. Round
  three approved this diff, on the condition that this message carry the measured numbers.

By reading, not measured: a pre-push run makes no judge call (push/runner.py and push/policy.py
pass no client and an execution budget), so the two reasons cannot arise there.

Found and not fixed, for the maintainer:
- .agents/skills/openultrasast-scan/SKILL.md:68-70 and docs/where-we-stand.md:349-350 say that
  `learning_endpoint_unavailable` has no line in report.md. It has had one since f555dee
  (2026-10-02).
- The citations of scan.py in docs/detection-techniques.md: of 24, 19 sit one, two or seven lines
  further down after this commit (5 do not move, 9 move by one line, 1 by two, 9 by seven).
This commit is contained in:
Marius Ciepluch
2026-11-27 17:06:25 +01:00
parent 55583b34c3
commit f6b1406541
6 changed files with 173 additions and 6 deletions
+88
View File
@@ -40,6 +40,31 @@ class _Backend:
return CpgResult(cpg_path=Path("cpg.bin"), run=lambda q, p: [])
class _AnsweringJudge:
"""The judge as it is when the endpoint answers: one call per question put to it, each answered `yes`."""
def __init__(self) -> None:
self.calls = 0
def complete(self, **kw): # type: ignore[no-untyped-def]
from openultrasast.tool_hunter import ChatResponse
self.calls += 1
return ChatResponse(content='{"vulnerable": true}')
def _ten_files_with_six_sinks(tmp_path): # type: ignore[no-untyped-def]
"""Ten identical files with six sinks each, in two families: twenty questions that each put six to the judge."""
source = (
"import os\nimport subprocess\n\n\ndef run(cmd):\n"
" os.system(cmd)\n subprocess.call(cmd, shell=True)\n eval(cmd)\n"
" exec(cmd)\n open(cmd).read()\n os.popen(cmd)\n"
)
for i in range(10):
(tmp_path / f"f{i}.py").write_text(source)
return tuple(_region(path=f"f{i}.py", families=("injection", "path")) for i in range(10))
def test_one_cpg_is_built_for_the_whole_repository() -> None:
from openultrasast.model.scan import scan_repository
@@ -122,6 +147,69 @@ def test_a_region_the_budget_could_not_afford_is_not_reported_as_clean(tmp_path)
assert starved.regions_scanned == generous.regions_scanned == 10
def test_a_judge_that_cannot_be_reached_is_recorded_and_asked_no_further(tmp_path) -> None:
"""A failed judge call is no verdict. It used to be read as one: with a key set and the network off, every
call failed, three attempts each, each dropped its claim as a `no` would, and nothing recorded it. The first
failure is now counted and the questions after it are not put to the judge.
"""
from openultrasast.model.scan import ScanBudget, scan_repository
class _Unreachable(_AnsweringJudge):
def complete(self, **kw): # type: ignore[no-untyped-def]
self.calls += 1
raise ConnectionError("network is unreachable")
regions = _ten_files_with_six_sinks(tmp_path)
budget = ScanBudget(max_model_calls=500, max_regions=10)
agreeing = _AnsweringJudge()
scan_repository(tmp_path, regions, backend=_Backend(), client=agreeing, model="m", budget=budget)
per_question = agreeing.calls // 20
assert agreeing.calls == per_question * 20 and per_question > 1, "twenty questions with the same calls each, more than one"
judge = _Unreachable()
result = scan_repository(tmp_path, regions, backend=_Backend(), client=judge, model="m", budget=budget)
assert judge.calls == 1, "a judge that could not be reached is not asked again"
assert result.model_calls == 1, "the call that was made and failed is counted as one"
assert result.regions_scanned == 10, "the graph still arbitrated every region"
failed = [dict(d) for d in result.degradations if d.get("reason") == "judge_calls_failed"]
assert failed == [{"stage": "model", "reason": "judge_calls_failed", "count": 1}]
withheld = [dict(d) for d in result.degradations if d.get("reason") == "judge_withheld"]
# The judge calls refused after the failure in the first question. The nineteen questions after it (the
# other family of the first region, and nine regions with both of theirs) are not counted here: the count
# is of judge calls, and the report says of the rest that none was put to the judge.
assert withheld == [{"stage": "model", "reason": "judge_withheld", "questions": per_question - 1}]
def test_a_judge_answer_with_no_decision_in_it_is_counted_and_the_rest_are_still_asked(tmp_path) -> None:
"""An answer that decides nothing drops its claim as a call that raises does. The judge was reached, so the
questions after it are still put; the scan counts the failures and goes on.
"""
from openultrasast.model.scan import ScanBudget, scan_repository
class _Rambling(_AnsweringJudge):
def complete(self, **kw): # type: ignore[no-untyped-def]
from openultrasast.tool_hunter import ChatResponse
self.calls += 1
return ChatResponse(content="I cannot say.")
regions = _ten_files_with_six_sinks(tmp_path)
budget = ScanBudget(max_model_calls=500, max_regions=10)
agreeing = _AnsweringJudge()
scan_repository(tmp_path, regions, backend=_Backend(), client=agreeing, model="m", budget=budget)
judge = _Rambling()
result = scan_repository(tmp_path, regions, backend=_Backend(), client=judge, model="m", budget=budget)
assert judge.calls == agreeing.calls, "a judge that answered is asked the next question"
assert result.findings == ()
failed = [dict(d) for d in result.degradations if d.get("reason") == "judge_calls_failed"]
assert failed == [{"stage": "model", "reason": "judge_calls_failed", "count": judge.calls}]
assert not [d for d in result.degradations if d.get("reason") == "judge_withheld"]
def test_the_budget_is_spent_on_the_highest_ranked_regions_first() -> None:
from openultrasast.model.scan import ScanBudget, scan_repository
+22
View File
@@ -569,6 +569,28 @@ def test_every_recorded_scan_degradation_is_rendered(tmp_path) -> None: # type:
assert needle in text, needle
def test_a_failed_judge_call_is_reported_as_unasked_and_not_as_a_no(tmp_path) -> None:
"""With a key set and the network off, 16 judge calls failed in one scan and each dropped its claim as a
`no` would; the report then said less than that of a run without an endpoint.
"""
from openultrasast.reports import write_markdown_report
path = tmp_path / "report.md"
write_markdown_report(
[],
path,
[],
degradations=[
{"stage": "model", "reason": "judge_calls_failed", "count": 3},
{"stage": "model", "reason": "judge_withheld", "questions": 5},
],
)
section = path.read_text().split("### What could not be analysed", 1)[1]
assert "3 judge call(s) gave no decision" in section
assert "went unanswered: its finding is not in this report, and that is not a `no` from the judge" in section
assert "5 further question(s) were refused in the question being put, and no question after it was put to the judge" in section
def test_an_unwritable_ledger_is_stated_in_the_report(tmp_path) -> None: # type: ignore[no-untyped-def]
"""What was not written, and where this scan's learnings are instead: a reader told only a code cannot
find them."""