Skip to content

fix(tier3): turn off Claude Code's refusal model fallback in eval trials - #337

Merged
rng1995 merged 5 commits into
mainfrom
naren/port-claude-refusal-fallback-off
Nov 5, 2026
Merged

rng1995 merged 5 commits into
mainfrom
naren/port-claude-refusal-fallback-off

Conversation

@rng1995

@rng1995 rng1995 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add CLAUDE_CODE_DISABLE_REFUSAL_FALLBACK=1 to the evaluator-managed task environment (_EVALUATOR_MANAGED_RUNTIME_ENV in tier3/harbor/adapter.py), next to CLAUDE_CODE_DISABLE_BACKGROUND_TASKS from fix(tier3): disable Claude Code background tasks in eval trials #268.
  • Every generated task (with and without the skill) and every staged native task writes it into [environment.env], so Harbor applies it to the agent in every env mode, including local mode, and on every provider route, Vertex AI included.
  • The managed value is merged last, so a native task's [environment.env] cannot set it back. harbor.runtime_env already rejects CLAUDE_CODE_* names. Other agents ignore the variable.
  • With the fallback off, Claude Code stops a refused turn with model_refusal_no_fallback, and Harbor 0.24's own Claude Code classifier raises its typed AgentSafetyRefusalError. No SkillEvaluator classifier change is needed.
  • Documents the behavior in docs/agents-and-sandboxes.mdx (Supported agents) and adds a Troubleshooting entry for AgentSafetyRefusalError in docs/tier3-live-evaluation.mdx. The docs and the CHANGELOG entry (Unreleased > Fixed) say the variable was checked with the pinned Claude Code 2.1.292, and that local mode keeps the fallback off only if the host's Claude Code honors it.

Why

When the model provider's safety classifier stops the selected model, Claude Code 2.1.292 (the version Harbor installs) retries the turn on another model from its own fixed table, for example claude-opus-4-8 after Claude Opus 5.5. It sends that bare Anthropic model ID, and nothing in SkillEvaluator maps it.

  • A route that does not serve that ID, such as a gateway that serves only the selected model, answers HTTP 403. Harbor records UnknownApiError, and the attempt reads as a broken credential or API, not as a refusal.
  • Where the retry succeeds, for example on the Anthropic API, the trial finishes on another model but is scored as the selected one.

With the fallback off, the pinned Claude Code does not retry a refused turn on another model, and a refusal is reported as a refusal. A scratch run on main shows the switch is missing from staged tasks, and that Harbor reads the fallback's 403 stream as UnknownApiError but the no-fallback stream as AgentSafetyRefusalError.

The refused attempt is still not scored, like any other failed trial, and counts against the arm's scored-attempt coverage. This PR does not change how a refusal is scored or counted.

Kept from public

  • The task-environment mechanism from fix(tier3): disable Claude Code background tasks in eval trials #268 (_EVALUATOR_MANAGED_RUNTIME_ENV, merged last into generated and native tasks) is reused as is. No per-agent environment or extra Harbor --ae argument is added.
  • Harbor 0.24's ClaudeCode._classify_exec_error is kept. It reads only the CLI's result and error events of its own stream-json launch and uses high-precision refusal patterns, so refusal text in tool output or model replies does not become a refusal. New tests run each Claude Code agent's real launch through it, so a Harbor upgrade that changes the launch or the filter fails them.
  • The collector still treats AgentSafetyRefusalError as an ordinary trial failure, not an agent-runtime or infrastructure failure (pinned by tests/test_harbor_collector_runtime_failures.py). Scoring, coverage and lift are unchanged.
  • The gateway route's staged agent environment is unchanged: still only ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL and CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS (pinned by tests/test_gateway_defaults.py). The fallback model is not mapped or rerouted.
  • The Claude Code agent wrappers in installed_agents.py and local_agents.py are not changed.

Tests

  • New tests/test_harbor_claude_refusal_fallback.py (32 tests) with stream fixtures in tests/claude_refusal_fixtures.py:
    • generated tasks with and without the skill carry the switch
    • for the gateway, Anthropic, Bedrock, NVIDIA Build and Vertex AI routes (Vertex AI in GKE mode with Workload Identity and an explicit Claude model), the task built from the route's runtime plan carries the switch, and no route's credential set carries or replaces it. Each route except NVIDIA Build also checks a credential name its plan stages, so the case proves it took that route.
    • harbor.runtime_env cannot turn it off (rejected, and the staged task still has 1)
    • a native task's [environment.env] cannot turn it off
    • local mode passes 1 to the agent command over a host value of 0 (POSIX only, like the fix(tier3): disable Claude Code background tasks in eval trials #268 test)
    • the name is not one Harbor redacts as a secret
    • the docs paragraph names the pinned Claude Code version and the local-mode limit, so a Claude Code pin bump has to re-check the variable
    • Harbor 0.24 pins run the real run() of Harbor's ClaudeCode, the container and local wrappers, and the container wrapper on the Vertex AI route. A stub Harbor environment uses Harbor's own task and exec environment merging and fails the launch command the agent builds. On each of the 4 lanes: the staged switch reaches the launch environment (on Vertex AI, after the wrapper filters the agent's variables); the no-fallback stream gives AgentSafetyRefusalError; the fallback 403 stream gives UnknownApiError; refusal text in tool output and model text gives ApiOverloadedError when a 529 ends the stream, and a plain NonZeroAgentExitCodeError when a max-turns result that matches no Harbor pattern ends it.
  • 15 of the 32 fail on main: every task-environment test, the 4 launch-environment tests and the docs test. The 17 Harbor classification and redaction tests pass on both, as expected.
  • The max-turns case is what catches a Harbor change. With Harbor's launch rewritten to --output-format stream-json in a scratch run, Harbor scanned all of stdout, and the 4 max-turns tests failed with AgentSafetyRefusalError. The 529 case stays green either way, because the last match in stdout wins.
  • Every test module that imports the Harbor adapter or reads the docs or CHANGELOG, plus tests/test_ci_workflows.py, tests/test_gateway_defaults.py and tests/test_harbor_collector_runtime_failures.py (59 modules): 4313 passed, 8 skipped, 15 failed. All 15 fail the same way on main on the test host: 2 tests/test_harbor_secure_docker_environment.py sidecar Compose tests, and 13 tests/tier3/test_judge_failure_artifacts.py custom-only script tests that run the host's Python 3.9 python3, which cannot evaluate int | float.
  • ruff check and ruff format --check are clean on the changed Python files.
  • scripts/check_oss_boundary.py passed.
  • Not run live for this PR. The variable was checked against the Claude Code 2.1.292 binary that Harbor installs; a later CLI pin must re-check it. Local mode uses the host's Claude Code, so it keeps the fallback off only if that release honors the variable.

🤖 Generated with Claude Code

When the model provider's safety classifier stops the selected model,
Claude Code 2.1.292 retries the turn on another model from its own fixed
table (for example claude-opus-4-8 after Claude Opus 5.5) under that bare
Anthropic model ID. A route that does not serve the ID, such as a gateway
that serves only the selected model, answers HTTP 403 and Harbor records
UnknownApiError. Where the retry succeeds, the trial finishes on another
model but is scored as the selected one.

Add CLAUDE_CODE_DISABLE_REFUSAL_FALLBACK=1 to the evaluator-managed task
environment that every generated and native task writes into
[environment.env], next to CLAUDE_CODE_DISABLE_BACKGROUND_TASKS. Harbor
applies it in every env mode and on every provider route. The managed
value is merged last, so a native task cannot set it back, and
harbor.runtime_env already rejects CLAUDE_CODE_* names. Other agents
ignore the variable.

With the fallback off, the CLI stops with model_refusal_no_fallback and
Harbor 0.24's own Claude Code classifier raises AgentSafetyRefusalError.
Tests pin that classification for Harbor's ClaudeCode and the container
and local wrappers, including that refusal text in tool output is not a
refusal. Scoring is unchanged: the refused attempt is an unscored trial
failure that counts against scored-attempt coverage.

Document the behavior and add a troubleshooting entry.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rng1995
rng1995 marked this pull request as ready for review November 5, 2026 17:06

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: 3 findings (0 P1, 0 P2, 3 P3); 3 posted inline.

Comment thread docs/agents-and-sandboxes.mdx Resolved
rng1995 and others added 4 commits November 5, 2026 10:09
The Harbor pins classified a hand-written launch command. Harbor 0.24's
Claude Code classifier reads only the CLI's terminal events when the
command contains --output-format=stream-json, and scans all of stdout
otherwise. A Harbor upgrade that changed its real launch would leave the
pins green while refusal text in tool output became a safety refusal
again.

The pins now run the real run() of Harbor's ClaudeCode, the container and
local wrappers, and the container wrapper on the Vertex AI route, against
a Harbor environment stub that fails the launch the agent builds. A new
case ends the stream with a max-turns result that matches no Harbor
pattern, so the only refusal text is in tool output and model text; it
fails if the stream-json filter stops applying. The 529 case alone could
not show that, because the last match in stdout wins.

The launch tests also check that the staged switch reaches the launch
environment on every lane, including after the Vertex AI wrapper filters
the agent's variables. The provider-route test gains a Vertex AI route
(GKE mode, Workload Identity, explicit Claude model), and each route
asserts a credential name its plan stages.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Code

CLAUDE_CODE_DISABLE_REFUSAL_FALLBACK was checked with Claude Code
2.1.292, the release Harbor installs. Local mode runs the Claude Code
already on the host, which may be any release from 2.1.280 for Claude
5.5 models. The docs said one model answers the whole trial in every env
mode.

Say that the behavior holds for the pinned release, and that local mode
keeps the fallback off only if the host's Claude Code honors the
variable. The CHANGELOG entry says the same. A test ties the docs
paragraph to the pinned version, so a Claude Code pin bump has to
re-check the variable and update it.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the CHANGELOG.md conflict: keep main's PII entry (#304) and add
this PR's refusal-fallback entry after it.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs/agents-and-sandboxes.mdx and the adapter comment said that, with the
fallback off, one model answers the whole trial. The switch only stops
Claude Code's refusal retry. Harbor pins Claude Code's Haiku and subagent
model aliases to the selected model only on routes that set
ANTHROPIC_BASE_URL, so on the Anthropic API, Bedrock and Vertex AI routes
helper and subagent calls can still use another model. Both now say a
refused turn is not retried on another model.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rng1995
rng1995 enabled auto-merge (squash) November 5, 2026 18:28
@rng1995
rng1995 merged commit 48870f1 into main Nov 5, 2026
22 checks passed
@rng1995
rng1995 deleted the naren/port-claude-refusal-fallback-off branch November 5, 2026 18:52
rng1995 added a commit that referenced this pull request Nov 5, 2026
No conflicts. main's Claude Code refusal-fallback switch (#337) adds one
evaluator-managed runtime variable in harbor/adapter.py, apart from this
PR's judge policy variables, and the CHANGELOG and docs entries sit side by
side.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
rng1995 added a commit that referenced this pull request Nov 5, 2026
…age (#347)

The CHANGELOG entry, the Supported agents paragraph and the Troubleshooting
entry for the Claude Code refusal switch (#337) said only that a refused
attempt counts against scored-attempt coverage. They now name the visible
result: the arm reports an incomplete coverage line such as
`Scored attempt coverage is 59/60`, its execution fails, and
`tier3 evaluate` and `validate --block-on-agent-eval` exit 1. On a route
that serves the fallback model, a run that completed before can now fail.
A new test checks the coverage message and that the docs state it.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@rng1995 rng1995 mentioned this pull request Nov 6, 2026
7 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant