Skip to content

fix(agents): fail closed on missing Codex harness [AI-assisted] - #83400

Closed
IWhatsskill wants to merge 1 commit into
openclaw:mainfrom
IWhatsskill:fix/codex-harness-fail-closed-83349
Closed

IWhatsskill wants to merge 1 commit into
openclaw:mainfrom
IWhatsskill:fix/codex-harness-fail-closed-83349

Conversation

@IWhatsskill

Copy link
Copy Markdown
Contributor

Summary

  • Problem: a missing explicit Codex agent harness could be treated like a normal model failure.
  • Why it matters: sessions configured for Codex could silently continue on a fallback model such as Sonnet.
  • What changed: missing strict harness selection now throws a typed error, and model fallback fails closed on it.
  • What did NOT change (scope boundary): no Doctor, update, Telegram, auth, or fallback ordering changes.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: strict Codex harness selection must fail closed instead of falling through to a configured model fallback.
  • Real environment tested: local OpenClaw source checkout on Windows, using the real runWithModelFallback() source path through tsx.
  • Exact steps or command run after this patch: ran a local source-run with primary openai/gpt-5.5, fallback anthropic/claude-sonnet-4-6, and a missing Codex harness error.
  • Evidence after fix:
{
  "error": "Requested agent harness \"codex\" is not registered.",
  "code": "agent_harness_not_registered",
  "calls": [
    "openai/gpt-5.5"
  ]
}
  • Observed result after fix: only the requested Codex/OpenAI candidate ran; the Anthropic fallback was not called.
  • What was not tested: a live Telegram/gateway session with real provider credentials.
  • Before evidence: source inspection showed the harness selector threw a plain Error, and runWithModelFallback() continued unknown errors while fallback candidates remained.

Root Cause (if applicable)

  • Root cause: strict harness selection failures were represented as plain unknown errors.
  • Missing detection / guardrail: model fallback had no non-retryable signal for an explicit missing harness.
  • Contributing context (if known): existing fallback logic intentionally continues unknown provider/model errors when more candidates remain.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/agents/model-fallback.test.ts
  • Scenario the test should lock in: missing strict Codex harness does not call the configured Anthropic fallback.
  • Why this is the smallest reliable guardrail: it covers the exact boundary where harness selection errors enter model fallback.
  • Existing test that already covers this (if any): harness selection tests already covered the fail-closed selector behavior, but not model-fallback retry behavior.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Sessions explicitly configured for a missing Codex harness now fail with that harness error instead of silently continuing on a fallback model.

Diagram (if applicable)

Before:
missing strict Codex harness -> plain Error -> model fallback -> Sonnet can run

After:
missing strict Codex harness -> typed error -> fail closed

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Windows local checkout
  • Runtime/container: local Node via OpenClaw test runner
  • Model/provider: openai/gpt-5.5 with fallback anthropic/claude-sonnet-4-6
  • Integration/channel (if any): N/A
  • Relevant config (redacted): no secrets used

Steps

  1. Configure primary openai/gpt-5.5 with fallback anthropic/claude-sonnet-4-6.
  2. Run the fallback path with a missing strict codex harness error.
  3. Observe which candidate models are invoked.

Expected

  • The missing Codex harness error stops the run before model fallback.

Actual

  • The run stopped with agent_harness_not_registered after only openai/gpt-5.5.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Focused checks:

node scripts/run-vitest.mjs src/agents/model-fallback.test.ts -t "does not fall back when strict agent harness selection is missing"
Test Files  2 passed (2)
Tests  2 passed | 112 skipped (114)

node scripts/run-vitest.mjs src/agents/model-fallback.test.ts src/agents/harness/selection.test.ts
Test Files  4 passed (4)
Tests  166 passed (166)

node scripts/run-vitest.mjs src/agents/agent-command.live-model-switch.test.ts
Test Files  2 passed (2)
Tests  38 passed (38)

git diff --check origin/main...HEAD
clean

Human Verification (required)

  • Verified scenarios: strict missing Codex harness stops before fallback; existing harness selection behavior stays green; related agent command fallback tests stay green.
  • Edge cases checked: the guard also recognizes the stable error code across possible boundaries, not only same-realm instanceof.
  • What you did not verify: live Telegram/gateway routing with real credentials.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: a missing explicit harness now stops earlier instead of using fallback.
    • Mitigation: this matches the strict runtime contract and the issue's requested fail-closed behavior.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S proof: supplied External PR includes structured after-fix real behavior proof. labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main already implements the useful fail-closed behavior with a broader fix than this branch, including missing-harness preflight before fallback candidate skipping and regression coverage. The PR should close as redundant rather than merging a now-superseded branch.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the current main implementation and close this PR as redundant; track any remaining doctor or session-repair work in the related canonical issue.

Do we have a high-confidence way to reproduce the issue?

Yes. The current-main source path shows strict missing harness selection used to enter generic model fallback, and current regression tests now lock in that it fails closed instead.

Is this the best way to solve the issue?

Yes. Current main is the better solution because it covers both the PR's run-path error and earlier candidate preflight cases before fallback can skip the broken primary route.

Security review:

Security review cleared: The PR and superseding main fix touch internal TypeScript error classification and focused tests only, with no dependency, secret, permission, workflow, or network-surface changes.

What I checked:

  • Current source throws typed missing-harness errors from strict selection: Strict non-auto, non-PI harness selection now throws MissingAgentHarnessError when the requested harness is not registered, preserving implicit Codex-to-PI behavior separately. (src/agents/harness/selection.ts:174, 8f27b3e21f6b)
  • Current source fails closed before fallback routing: runWithModelFallback now preflights each candidate's configured harness runtime before auth cooldown skips or fallback attempts, and rethrows MissingAgentHarnessError if one escapes from the run path. (src/agents/model-fallback.ts:979, 8f27b3e21f6b)
  • Regression tests cover the PR's central behavior and broader edge cases: Current tests assert missing strict plugin harnesses do not call the configured fallback, and also cover fail-closed behavior before auth cooldown skips, agent runtime context, and session runtime overrides. (src/agents/model-fallback.test.ts:560, 8f27b3e21f6b)
  • Fix provenance: git blame ties the missing-harness error class, selection throw, fallback rethrow, and regression tests to commit 8f27b3e, authored as 'fix(agents): fail closed on missing Codex harness'. (src/agents/model-fallback.ts:1214, 8f27b3e21f6b)
  • Commit metadata: The proof commit is on current main with commit time 2026-05-18T12:47:51+08:00 and subject 'fix(agents): fail closed on missing Codex harness'. (8f27b3e21f6b)
  • Release provenance: git tag --contains returned no release tags, while git branch --contains showed main, so this is implemented on current main only and is not in the latest v2026.5.12 release. (CHANGELOG.md:35, 8f27b3e21f6b)

Likely related people:

  • vincentkoc: Introduced the current MissingAgentHarnessError implementation, fallback preflight/rethrow behavior, regression tests, and changelog entry in the proof commit. (role: current-main fix author; confidence: high; commits: 8f27b3e21f6b; files: src/agents/harness/errors.ts, src/agents/harness/selection.ts, src/agents/model-fallback.ts)
  • steipete: The shallow current history/blame shows the surrounding existing model-fallback and harness-selection code carried from commit 47a2efe before the fail-closed fix landed. (role: adjacent area contributor; confidence: medium; commits: 47a2efe483; files: src/agents/model-fallback.ts, src/agents/harness/selection.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against e3d55188384b; fix evidence: commit 8f27b3e21f6b, main fix timestamp 2026-05-18T12:47:51+08:00.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. P1 High-priority user-facing bug, regression, or broken workflow. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. labels May 18, 2026
@IWhatsskill
IWhatsskill marked this pull request as ready for review May 18, 2026 03:07
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels May 18, 2026
@Takhoffman

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper could not start a re-review for this item.

Reason: re-review requires an open issue or PR.

Re-review progress:

@Takhoffman

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 18, 2026
@Takhoffman

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels May 18, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels May 18, 2026
@clawsweeper clawsweeper Bot closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants