From 3c1edd4fdd805e1f1268eca1b46f667500f3e2ce Mon Sep 17 00:00:00 2001 From: raymondginger Date: Sun, 22 Nov 2026 07:49:33 +0800 Subject: [PATCH] feat(goal): record reporting faithfulness apart from the review outcome A passing check does not prove the claim that cites it: arXiv:2611.25760 shows task success and reporting faithfulness are distinct properties, and evidence of one cannot vouch for the other. The verifier already rejected unsupported claims, but a single boolean could not say whether evidence was *missing* or *contradicting* -- and the paper's strongest detector reported exactly that collapse as its one false alarm (a real side effect flagged only because no later observation confirmed it). - `GoalVerdict.conflict`: a rejection now distinguishes "a record contradicts the claim" from "no record supports it". - `GoalVerdict.faithfulness`: derived from the two booleans (supported / unsupported / contradicted) rather than stored, so it cannot disagree with them. - `review_record()` carries `faithfulness` next to `result`, so the durable history keeps the report axis; an unavailable review records `unassessed` instead of guessing. Task success stays out of this record on purpose -- the Goal's own state carries it, and merging the two would repeat the mistake the paper documents. No existing behaviour changes: `confirmed` keeps its meaning and no new branch was added to the verdict path. --- core/agent_runtime/goal_verifier.py | 59 +++++++++- tests/test_goal_report_faithfulness.py | 145 +++++++++++++++++++++++++ 2 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 tests/test_goal_report_faithfulness.py diff --git a/core/agent_runtime/goal_verifier.py b/core/agent_runtime/goal_verifier.py index f76b1614e..9b89053e8 100644 --- a/core/agent_runtime/goal_verifier.py +++ b/core/agent_runtime/goal_verifier.py @@ -105,6 +105,15 @@ class GoalVerdict: # Which step reached the verdict: "rule", "checks" or "reviewer"; "none" # when nothing was checked (no verifier and no confirmed checks). stage: str = "" + # A rejection is either *insufficient* (no record proves the claim) or a + # *conflict* (a record contradicts it). arXiv:2611.25760 shows why the two + # must not be collapsed: its strongest detector's one reported false alarm + # was a claim that a real side effect happened, flagged only because no + # later observation confirmed it. Task success and reporting faithfulness + # are separate properties, so "we did not see it" is not "it did not + # happen". Callers that gate on evidence can treat insufficient as a + # request for more evidence rather than as a failure. + conflict: bool = False summary: str = "" requirements: tuple[RequirementFinding, ...] = () checked: tuple[str, ...] = () @@ -116,6 +125,28 @@ def __post_init__(self) -> None: if self.tokens < 0: raise ValueError("tokens cannot be negative") + @property + def faithfulness(self) -> str: + """What this verdict establishes about the *report*, not the work. + + arXiv:2611.25760 separates the two properties and warns that evidence + of task success cannot vouch for reporting faithfulness, or the + reverse. This verdict only reads the Turn's records, so it speaks about + the claim: + + * ``supported`` -- the records back the claim; + * ``unsupported`` -- no record backs it; a gap the model fills, not a + failure; + * ``contradicted`` -- a record contradicts it. + + Task success is deliberately absent: the Goal's own state carries it. + Deriving this from ``confirmed``/``conflict`` instead of storing a third + field means the three can never disagree. + """ + if self.confirmed: + return "supported" + return "contradicted" if self.conflict else "unsupported" + class GoalCompletionVerifier(Protocol): """An async callable that judges one completion claim.""" @@ -210,11 +241,13 @@ async def __call__(self, request: GoalCompletionRequest) -> GoalVerdict: "check", checks[-1], "Fix the problem and run the check again" ), pending_checks, + conflict=True, ) if evidence[-1].status in _UNSUCCESSFUL: return _reject( _unsuccessful("step", evidence[-1], "Resolve it"), request.pending, + conflict=True, ) return GoalVerdict( confirmed=True, @@ -226,14 +259,28 @@ async def __call__(self, request: GoalCompletionRequest) -> GoalVerdict: ) -def _reject(text: str, could_resolve: tuple[GoalEvidenceItem, ...]) -> GoalVerdict: +def _reject( + text: str, + could_resolve: tuple[GoalEvidenceItem, ...], + *, + conflict: bool = False, +) -> GoalVerdict: + """A rejection carries whether a record *contradicts* the claim. + + Default is ``conflict=False`` -- insufficient evidence. Only a recorded + failure of the claimed work sets it, because arXiv:2611.25760 shows the + cost of the opposite mistake: treating "no confirming observation" as + failure flags claims that are true. + """ if could_resolve: text += ( f" {_describe(could_resolve[-1])} ran in the same step as this claim " "and has no recorded result yet; look at its result before claiming " "completion again." ) - return GoalVerdict(confirmed=False, justification=text, stage="rule") + return GoalVerdict( + confirmed=False, justification=text, stage="rule", conflict=conflict + ) CheckRunner = Callable[[tuple[GoalCheckSpec, ...]], Awaitable[tuple[GoalCheckRun, ...]]] @@ -358,6 +405,13 @@ def review_record( ``result`` is ``passed``, ``rejected``, ``impossible`` or ``unavailable`` (the review could not run; ``problem`` says why). + + ``faithfulness`` is the **report** axis -- ``supported``, ``unsupported``, + ``contradicted``, or ``unassessed`` when no verdict exists. It is recorded + separately from task success on purpose: arXiv:2611.25760 shows a passing + test or a healthy service can accompany a claim that was never established, + so the Goal's completion state must not be read as a faithfulness score (or + the reverse). Never merge the two into one boolean. """ runs = verdict.check_runs if verdict is not None else check_runs @@ -367,6 +421,7 @@ def review_record( "recordedAt": datetime.now(UTC).isoformat().replace("+00:00", "Z"), "stage": (verdict.stage or "other") if verdict is not None else "reviewer", "result": result, + "faithfulness": verdict.faithfulness if verdict is not None else "unassessed", "justification": _clip( verdict.justification if verdict is not None else problem, _RECORD_TEXT_MAX_CHARS, diff --git a/tests/test_goal_report_faithfulness.py b/tests/test_goal_report_faithfulness.py new file mode 100644 index 000000000..dbc8cb704 --- /dev/null +++ b/tests/test_goal_report_faithfulness.py @@ -0,0 +1,145 @@ +"""A rejection says whether evidence is *missing* or *contradicting*. + +arXiv:2611.25760 ("Unfaithful Work Reports by Coding Agents") separates task +success from reporting faithfulness, and its strongest detector's one reported +false alarm came from collapsing them: a claim that a real side effect happened +was flagged only because no later observation confirmed it. "We did not see it" +is not "it did not happen". + +``GoalVerdict.conflict`` carries that distinction. This file pins it so a later +refactor cannot quietly turn every rejection into a failure signal: + +* a recorded *failure* of the claimed work is a conflict (``conflict=True``); +* a claim with nothing behind it is merely insufficient (``conflict=False``) -- + the model should produce evidence, not be told the work is wrong. +""" + +from __future__ import annotations + +import pytest + +from core.agent_runtime.goal_verifier import ( + GoalCompletionRequest, + GoalEvidenceItem, + GoalVerdict, + RuleBasedVerifier, + review_record, +) + + +def _request( + *, + evidence: tuple[GoalEvidenceItem, ...], + reason: str = "The tests pass and the file is written.", +) -> GoalCompletionRequest: + return GoalCompletionRequest( + objective="Ship the feature.", + reason=reason, + evidence=evidence, + ) + + +@pytest.mark.asyncio +async def test_failed_check_is_a_conflict() -> None: + verdict = await RuleBasedVerifier()( + _request( + evidence=( + GoalEvidenceItem( + kind="command_execution", + status="failed", + summary="pytest -q exited 1", + ), + ) + ) + ) + assert verdict.confirmed is False + assert verdict.conflict is True + + +@pytest.mark.asyncio +async def test_missing_evidence_is_insufficient_not_a_conflict() -> None: + verdict = await RuleBasedVerifier()(_request(evidence=())) + assert verdict.confirmed is False + assert verdict.conflict is False + + +@pytest.mark.asyncio +async def test_no_reason_is_insufficient_not_a_conflict() -> None: + verdict = await RuleBasedVerifier()( + _request( + evidence=( + GoalEvidenceItem( + kind="file_edit", status="succeeded", summary="wrote app.py" + ), + ), + reason="", + ) + ) + assert verdict.confirmed is False + assert verdict.conflict is False + + +@pytest.mark.asyncio +async def test_supported_claim_is_confirmed_without_conflict() -> None: + verdict = await RuleBasedVerifier()( + _request( + evidence=( + GoalEvidenceItem( + kind="command_execution", + status="succeeded", + summary="pytest -q exited 0", + ), + ) + ) + ) + assert verdict.confirmed is True + assert verdict.conflict is False + + +# --- the report axis is recorded next to the outcome, never merged -------- + + +@pytest.mark.asyncio +async def test_faithfulness_is_derived_for_all_three_states() -> None: + """One property, three states, derived from the two booleans. + + Storing a third field would let it disagree with ``confirmed``/``conflict``; + deriving it means a verdict can never claim to be faithful and contradicted + at once. + """ + supported = await RuleBasedVerifier()( + _request(evidence=(GoalEvidenceItem("command_execution", "succeeded", "ok"),)) + ) + contradicted = await RuleBasedVerifier()( + _request(evidence=(GoalEvidenceItem("command_execution", "failed", "boom"),)) + ) + unsupported = await RuleBasedVerifier()(_request(evidence=())) + + assert supported.faithfulness == "supported" + assert contradicted.faithfulness == "contradicted" + assert unsupported.faithfulness == "unsupported" + + +def test_review_record_keeps_faithfulness_beside_the_result() -> None: + """The durable record carries the report axis, not just passed/rejected.""" + record = review_record( + goal_id="goal_1", + turn_id="turn_1", + result="rejected", + verdict=GoalVerdict( + confirmed=False, justification="a record contradicts it", conflict=True + ), + ) + assert record["result"] == "rejected" + assert record["faithfulness"] == "contradicted" + + +def test_review_record_without_a_verdict_says_unassessed() -> None: + """An unavailable review assessed nothing -- say so instead of guessing.""" + record = review_record( + goal_id="goal_1", + turn_id="turn_1", + result="unavailable", + problem="the verifier could not run", + ) + assert record["faithfulness"] == "unassessed"