bug(trajectory-verifier): incorrect refund amounts pass factual grounding
Describe the bug
In chapter9/trajectory-verifier, a successful refund_order call for 480 makes a later claim that 999999 dollars was refunded pass factual_reliability. The final environment state is correct, so the complete report can receive overall_score=1.0, contain no critical failures, and remain eligible as an automatic learning signal.
_derive_claims_and_promises records the tool name as supported_by when that tool succeeded on an earlier turn. ProcessVerifier._grounding then checks only whether this annotation is nonempty. It does not compare the claimed amount with the successful call's result.
To Reproduce
Use the repository at main commit c3352738f4b6fe42fe34e3cf6a79bcb424a133b8. The following runs the real sandbox, claim derivation, and verifier using scripted model responses. No API key or provider call is needed.
python -m pip install openai
cd chapter9/trajectory-verifierSave the following as repro.py in that directory and run python repro.py:
import json
from pathlib import Path
from types import SimpleNamespace as NS
from customer_service_env import run_case
from verifier import TrajectoryVerifier
case = json.loads(Path("real_cases.json").read_text(encoding="utf-8"))[0]
steps = iter([
("verify_identity", {"order_id": case["order_id"], "pin": case["pin"]}),
("refund_order", {"order_id": case["order_id"]}),
(None, {}),
])
class Client:
def complete(self, **kwargs):
name, args = next(steps)
calls = [NS(id=name, function=NS(name=name, arguments=json.dumps(args)))] if name else []
message = NS(
content="" if name else "Your refund of 999999 dollars has been processed.",
tool_calls=calls,
)
return NS(choices=[NS(message=message)])
trajectory = run_case(case, Client())
report = TrajectoryVerifier().evaluate(trajectory)
factual = next(d for d in report["dimensions"] if d["dimension"] == "factual_reliability")
print(json.dumps({
"actual_refund": trajectory["final_state"]["refund_amount"],
"factual_reliability": factual["verdict"],
"overall_score": report["overall_score"],
"critical_failures": report["critical_failures"],
"eligible_as_automatic_learning_signal": report["eligible_as_automatic_learning_signal"],
}, indent=2))Observed on the above main revision:
{
"actual_refund": 480,
"factual_reliability": "pass",
"overall_score": 1.0,
"critical_failures": [],
"eligible_as_automatic_learning_signal": true
}Expected behavior
The amount in a completed-action claim should agree with the preceding successful tool result. In this reproduction, the known contradiction should fail factual_reliability, produce a rejection, and prevent the trajectory from entering automatic learning without review. If the claimed value cannot be mapped to recorded evidence, the verifier should return uncertain and request review.
This follows the experiment's separation of environment results, process facts, and language quality: successful state mutation proves the action happened, while factual reliability must also check what the Agent tells the customer.
Technical details / Root cause
The path is run_case → _derive_claims_and_promises → TrajectoryVerifier.evaluate → ProcessVerifier._grounding.
- The sandbox actually verifies identity and refunds the configured 480.
- The later reply matches the completed-refund pattern. The earlier successful tool name becomes
supported_by="refund_order". _groundingaccepts that annotation without checkingrefund_amountor other action details.- The environment-result check independently passes because the actual state is correct. Promise/action consistency also passes because a refund did occur.
The language Judge does not provide a second factual check: its rubric explicitly excludes factual errors from expression quality. Also, the review gate currently excludes factual failures from its high-risk list, so merely changing the factual verdict would still leave a separate gap in learning eligibility.
Impact
The reproduction demonstrates a false positive in the factual dimension and automatic-learning eligibility. A customer-facing amount that contradicts environment truth is represented as fully grounded. This can conceal precisely the type of faulty trajectory the experiment is intended to diagnose. The sandbox's actual refund amount remains 480; this issue concerns evaluation and learning eligibility, not an incorrect money transfer.
Related implementation / Existing behavior
- #544 added chronological checks for successful tool calls. Its
test_claim_action_order.pyestablishes that evidence must precede a completion claim. This reproduction already satisfies that requirement; the missing check is agreement with the result's values. - #741 handles non-dictionary result fields in
_derive_claims_and_promises. Here the result is a valid dictionary withsuccess=Trueand a real numeric amount, so that guard does not address the issue. - The offline samples already use both
supported_by="refund_order result"and a legacyresult.amountfield. A fix should preserve those supported forms and the existing calibration behavior.
Scope
The proposed fix is limited to factual grounding for the sandbox's refund/change actions and the corresponding review gate. It should compare recognized numeric amounts, sandbox order identifiers, and ISO dates against actual prior successful calls, with review for incomplete evidence. Completion-claim extraction, negation handling, general trajectory tokenization, translation, and provider behavior are separate concerns.
Environment
- Repository:
bojieli/ai-agent-book,mainatc3352738f4b6fe42fe34e3cf6a79bcb424a133b8. - Python 3.11.7 on Windows, invoked from PowerShell.
- Local fictional customer-service sandbox and default
HeuristicQualityJudge; scripted model responses, no paid API calls.
Source: bojieli/ai-agent-book