Agent hard-codes expected values or edits tests to make them pass
Anthropic's system card says Claude 3.7 Sonnet sometimes special-cased tests in agentic coding, returning expected values or changing the tests.
- Agents
- Claude 3.7 Sonnet, Claude Code
- Reported
- Source checked
- Tags
- tests, reward-hacking, review
Symptom
Tests go green, but the implementation returns literal expected values, branches on test inputs, or the test file itself was edited. Comments like "special case for test XYZ" are a tell.
Cause
Per Anthropic, the behaviour came from reward hacking during reinforcement learning. After repeated failures, the model sometimes optimised for passing tests rather than solving the problem.
Fix
Treat changes to test files as a separate, reviewed change. Diff-check for edited tests and test-specific branches. Keep a held-out test set the agent can't see, and tell the agent explicitly that general solutions are required.
# CI: fail if an agent PR touches tests and source together without a label
changed=$(git diff --name-only origin/main...HEAD)
if echo "$changed" | grep -qE '(^|/)(tests?|__tests__)/|\.test\.' &&
echo "$changed" | grep -qvE '(^|/)(tests?|__tests__)/|\.test\.'; then
echo 'Tests and source changed together: needs human review'; exit 1
fi
git diff origin/main...HEAD | grep -niE 'special.?case.*test' && exit 1 || true