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
59 changes: 57 additions & 2 deletions core/agent_runtime/goal_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...] = ()
Expand All @@ -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."""
Expand Down Expand Up @@ -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,
Expand All @@ -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, ...]]]
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
145 changes: 145 additions & 0 deletions tests/test_goal_report_faithfulness.py
Original file line number Diff line number Diff line change
@@ -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"
Loading