Skip to content

fix(harness): route CLI runtime aliases (claude-cli, google-gemini-cli) through PI harness - #83552

Closed
SkyWolfDreamer wants to merge 2 commits into
openclaw:mainfrom
SkyWolfDreamer:fix/cli-runtime-alias-harness-selection
Closed

SkyWolfDreamer wants to merge 2 commits into
openclaw:mainfrom
SkyWolfDreamer:fix/cli-runtime-alias-harness-selection

Conversation

@SkyWolfDreamer

@SkyWolfDreamer SkyWolfDreamer commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: When agentRuntime.id is set to a CLI runtime alias (claude-cli, google-gemini-cli), selectAgentHarnessDecision throws MissingAgentHarnessError because CLI aliases are not registered as plugin harnesses — they are dispatched internally via the cli-backend.
  • Why it matters: Any session using claude-cli as agentRuntime crashes on compaction (context overflow) and on any other code path that calls selectAgentHarness directly. Sessions become permanently unrecoverable once context exceeds the limit.
  • What changed: Added a guard in selectAgentHarnessDecision that detects CLI runtime aliases via isCliRuntimeAlias() and routes them to the PI harness (which dispatches through the cli-backend), parallel to the existing implicit-codex fallback.
  • What did NOT change: Normal plugin harness selection, explicit pi / auto routing, codex implicit fallback, and the cli-backend dispatch path are all untouched.

Change Type

  • Bug fix

Scope

  • Gateway / orchestration

Linked Issue/PR

  • This PR fixes a bug or regression.

Real behavior proof

  • Behavior addressed: Sessions configured with agentRuntime: { id: "claude-cli" } crash on compaction with MissingAgentHarnessError: Requested agent harness "claude-cli" is not registered. and the session becomes permanently unrecoverable once it exceeds its context window.
  • Real environment tested: OpenClaw 2026.5.16-beta.7 on WSL2 Ubuntu, gateway running locally, claude-cli backend, Anthropic models (claude-sonnet-4-6 and claude-opus-4-7). A pre-existing session at 143 % of its context window (1.5 m / 1.0 m tokens) that had been failing every compaction attempt was used as the reproduction target.
  • Before evidence: production gateway logs from the affected install, captured before the patch:
    [diagnostic] lane task error: error="MissingAgentHarnessError: Requested agent harness \"claude-cli\" is not registered."
    [ws] ⇄ res ✗ sessions.compact errorCode=UNAVAILABLE
    
    Every compaction attempt on the affected session returned UNAVAILABLE; the session could not recover and could not be reused.
  • Exact steps or command run after this patch: rebuilt OpenClaw from the patched source, restarted the local gateway onto the new build, and resumed the same already-overflowing session by sending a normal user message that triggers the gateway-side compaction path:
    pnpm build && openclaw gateway restart
    # then send a turn into the previously stuck session
    
  • Evidence after fix: redacted gateway logs from the patched run:
    [agent/cli-backend] claude live session turn: provider=claude-cli model=claude-opus-4-7 durationMs=135114 rawLines=322
    [agent/cli-backend] cli exec: provider=claude-cli model=sonnet ... activeSessions=2
    
    No MissingAgentHarnessError is emitted; the compaction completes and the next turn streams normally.
  • Observed result after fix: the previously stuck session compacted on the first attempt, the gateway returned OK on sessions.compact, and the session continued to accept turns. The harness-selection path now routes agentRuntime.id = "claude-cli" to the PI harness instead of throwing.
  • What was not tested: behaviour for non-claude-cli CLI aliases other than the existing google-gemini-cli (the guard is keyed off the existing isCliRuntimeAlias() helper, so any alias it already recognises is covered, but I did not separately rebuild and reproduce against a Gemini-pinned session); behaviour under explicit agentRuntime.id: "pi" or "auto" (unchanged code path, not re-exercised after the patch).

Root Cause

selectAgentHarnessDecision has a special case for implicit codex but no equivalent for CLI runtime aliases. CLI aliases are not plugin harnesses — they are backend aliases dispatched by PI's cli-backend. The utility isCliRuntimeAlias() already existed in model-runtime-aliases.ts but was never called in the harness-selection path, so any caller that hit selectAgentHarness("claude-cli") (compaction, several other code paths) threw MissingAgentHarnessError. Any config using agentRuntime: { id: "claude-cli" } — the documented way to pin Claude models to Claude Code — therefore broke on the first context overflow.

Regression Test Plan

The fix is a 14-line guard in selectAgentHarnessDecision that mirrors the existing implicit-codex fallback. The smallest reliable test is a unit test against selectAgentHarnessDecision asserting that { id: "claude-cli" } (and { id: "google-gemini-cli" }) resolves to the PI harness. Happy to add it on request if the maintainers prefer it in this PR; flagging it explicitly rather than skipping it silently.

User-visible / Behavior Changes

None — restores the documented behaviour. Sessions pinned to claude-cli no longer die on compaction.

Diagram

Before:
  [compaction] -> selectAgentHarness("claude-cli") -> MissingAgentHarnessError -> session dead

After:
  [compaction] -> selectAgentHarness("claude-cli") -> isCliRuntimeAlias() -> PI harness -> cli-backend -> ok

Security Impact

  • New permissions: No
  • New secrets handling: No
  • New network calls: No
  • New exec surface: No
  • New data access: No

Repro + Verification

  • Environment: any OpenClaw install with agentRuntime: { id: "claude-cli" } in agent config, a long-running session that approaches its context window.
  • Steps: keep the session running until the gateway-side compaction kicks in, or trigger it explicitly via sessions.compact.
  • Expected: the compaction completes and the session continues.
  • Actual (before): MissingAgentHarnessError on every compaction attempt; the session permanently fails further turns.

Evidence

  • Trace logs / terminal capture (before: production logs; after: patched-build gateway logs).

Human Verification

I rebuilt OpenClaw from the patched source on the affected WSL box, restarted the local gateway onto the new build, and resumed the same previously stuck session. The session compacted on the first attempt and continued; no MissingAgentHarnessError appears in the gateway log on or after the patched build. NOT verified: explicit-pi / explicit-auto paths (unchanged), Gemini-pinned sessions (alias covered by the same guard but not separately re-exercised), and the documented test (would be a selectAgentHarnessDecision unit covering both aliases — happy to add if maintainers want it landed in this PR).

Review Conversations

  • Will resolve bot review threads before merge
  • Will respond to maintainer review comments

Compatibility / Migration

Backward compatible. No config or migration. The guard only affects callers that previously threw MissingAgentHarnessError; existing callers that resolved successfully are unchanged.

Risks and Mitigations

  • Risk: PI harness receiving a claude-cli runtime policy may behave differently in edge cases.
    Mitigation: PI already dispatches claude-cli provider sessions through cli-backend (confirmed by the patched-build gateway logs above). This patch aligns the compaction path with what the main session path already does.
  • Risk: A future CLI alias registered in isCliRuntimeAlias() but not actually dispatchable by the PI harness would silently fall into this path.
    Mitigation: isCliRuntimeAlias() is currently exhaustive for the registered CLI backends (claude-cli, google-gemini-cli); future additions to that helper should land alongside their PI-harness dispatch wiring.

@SkyWolfDreamer
SkyWolfDreamer requested a review from a team as a code owner May 18, 2026 09:58
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser app: android App: android app: ios App: ios app: macos App: macos gateway Gateway runtime extensions: copilot-proxy Extension: copilot-proxy extensions: diagnostics-otel Extension: diagnostics-otel extensions: llm-task Extension: llm-task extensions: lobster Extension: lobster extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: the reported CLI-runtime harness bug is valid, but #85631 now owns the safer landing path with provider-owned alias validation and focused regression tests, while this branch would broadly route any known CLI alias through PI.

Canonical path: Use #85631 as the canonical fix, and preserve this PR's live repro logs as supporting evidence there.

So I’m closing this here and keeping the remaining discussion on #85631.

Review details

Best possible solution:

Use #85631 as the canonical fix, and preserve this PR's live repro logs as supporting evidence there.

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

Yes. Current main source shows the explicit-runtime MissingAgentHarnessError path, and the PR body plus bkvargyas' v2026.5.18 Linux/Node 24 comment provide live logs showing the failure and local fix.

Is this the best way to solve the issue?

No. The central direction is right for valid CLI aliases, but this branch is not the best landing candidate because it lacks provider validation and tests; the superseding PR is narrower and safer.

Security review:

Security review cleared: No new dependency, secret handling, permissions, or supply-chain surface was added; the auth-provider concern is a functional routing compatibility risk.

What I checked:

Likely related people:

  • steipete: Recent commits shaped the Codex fallback and CLI runtime-alias migration contracts around harness selection and model-runtime aliases. (role: recent feature owner; confidence: high; commits: 225e48f63291, a0f35574d047, 365c986a5b2a; files: src/agents/harness/selection.ts, src/agents/model-runtime-aliases.ts, docs/concepts/agent-runtimes.md)
  • joshavant: Recent work touched native compaction failure surfacing in harness selection and Anthropic CLI auth routing, both adjacent to this reported failure mode. (role: recent adjacent contributor; confidence: high; commits: b8e9ab9385c0, f6de2b3885ba; files: src/agents/harness/selection.ts, src/agents/model-runtime-aliases.ts, src/agents/command/attempt-execution.ts)
  • vincentkoc: The recent fail-closed missing-Codex-harness change is in the same explicit-runtime selection branch that this PR modifies. (role: introduced fail-closed behavior; confidence: medium; commits: 8f27b3e21f6b; files: src/agents/harness/selection.ts)
  • pashpashpash: Recent runtime-policy work scoped agent runtime policy to providers and models, which is central to keeping CLI aliases provider-owned. (role: runtime policy contributor; confidence: medium; commits: 02fe0d8978db, 1c3399010815; files: src/agents/harness/selection.ts, src/agents/model-runtime-policy.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 0d7d99befab4.

When agentRuntime.id is set to a CLI runtime alias like "claude-cli",
selectAgentHarnessDecision was throwing MissingAgentHarnessError because
CLI aliases are not registered as plugin harnesses — they are dispatched
internally via the cli-backend.

Add a special case (parallel to the existing codex implicit fallback) that
routes CLI runtime aliases to the PI harness, which then dispatches the
run through the appropriate cli-backend. This fixes compaction and other
harness-selection paths that would break when context exceeded the limit
for sessions using claude-cli as agentRuntime.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@bkvargyas

Copy link
Copy Markdown

Confirming repro on v2026.5.18 stable (Linux, Node 24.15) — applied this PR's fix locally and it resolved the issue.

Config:

  • Agent main with model.primary: "anthropic/claude-opus-4-7" and
    agents.defaults.models["anthropic/claude-opus-4-7"].agentRuntime: { id: "claude-cli" }
  • agents.defaults.cliBackends.claude-cli configured (bundled anthropic plugin)

Symptom: Every Telegram inbound message immediately failed with:
[diagnostic] lane task error: lane=main durationMs=14 error="MissingAgentHarnessError: Requested agent harness
"claude-cli" is not registered."
[diagnostic] lane task error: lane=session:agent:main:telegram:direct: durationMs=18
error="MissingAgentHarnessError: ..."

Key asymmetry: Cron-triggered runs worked fine — agent-runner-execution.ts's isCliProvider(cliExecutionProvider,
...) check at the run dispatch correctly routed CLI providers to runCliAgentWithLifecycle. The failure path was a
different caller of selectAgentHarness (compaction / followup / similar) that doesn't get the CLI-dispatch escape
hatch and hits the throw new MissingAgentHarnessError(runtime) branch directly.

Fix verified: Patched selectAgentHarnessDecision to fall back to PI for isCliRuntimeAlias(runtime) (parallel to the
existing implicit-codex fallback). Telegram messages now complete normally, cron path unchanged.

Happy to share more diagnostic detail if useful for the merge-risk review.

@clawsweeper

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🥚 Incubating: this PR egg is tucked into the review nest.

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.
What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@clawsweeper

clawsweeper Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants