Skip to content

fix #84857: skip CLI runtime harness preflight during compaction#84878

Closed
zhangguiping-xydt wants to merge 1 commit into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-84857
Closed

fix #84857: skip CLI runtime harness preflight during compaction#84878
zhangguiping-xydt wants to merge 1 commit into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-84857

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: compaction preflight routes claude-cli runtime sessions through harness selection and throws MissingAgentHarnessError, so over-threshold sessions fail before dispatch and leak the warning text back to users.
  • Solution: skip harness compaction preflight when the resolved runtime is a CLI runtime alias.
  • What changed: added a CLI runtime bypass in src/agents/harness/selection.ts and locked it in with a regression test in src/agents/harness/selection.test.ts.
  • What did NOT change: no changes to normal harness selection, non-CLI compaction behavior, or runtime policy resolution.

Fixes #84857

Real behavior proof

  • Behavior or issue addressed: compaction preflight no longer throws MissingAgentHarnessError(\"claude-cli\") for claude-cli runtime sessions, which avoids user-visible warning replies and lets the queued compaction path continue.
  • Real environment tested: Linux 4.19.112-2.el8.x86_64 x86_64 GNU/Linux, Node v22.22.0, OpenClaw v2026.5.20, worktree SHA 79d2597
  • Exact steps or command run after this patch:
    pnpm install --frozen-lockfile
    node --import tsx <<'EOF'
    import { maybeCompactAgentHarnessSession } from './src/agents/harness/selection.ts';
    
    const config = {
      agents: {
        defaults: {
          models: {
            'anthropic/claude-opus-4-7': {
              agentRuntime: { id: 'claude-cli' },
            },
          },
        },
      },
    };
    
    const result = await maybeCompactAgentHarnessSession({
      sessionId: 'session-1',
      sessionKey: 'agent:main:main',
      sessionFile: '/tmp/session.jsonl',
      workspaceDir: '/tmp/workspace',
      provider: 'anthropic',
      model: 'claude-opus-4-7',
      config,
    });
    
    console.log('RESULT', result === undefined ? 'undefined' : JSON.stringify(result));
    EOF
    npx vitest run src/agents/harness/selection.test.ts
  • Evidence after fix:
    RESULT undefined
    
     RUN  v4.1.6 /media/vdc/code/ai/openclaw-84857
    
     Test Files  2 passed (2)
          Tests  54 passed (54)
       Start at  16:08:07
       Duration  5.37s (transform 2.21s, setup 566ms, import 4.08s, tests 177ms, environment 0ms)
    
  • Observed result after fix: the compaction preflight returns undefined instead of throwing MissingAgentHarnessError, so the caller can continue into the non-harness compaction path; the regression test covering the claude-cli runtime case now passes.
  • What was not tested: no known gaps

Regression Test Plan

  • Coverage level: Unit test
  • Target test file: src/agents/harness/selection.test.ts
  • Scenario locked in: maybeCompactAgentHarnessSession returns undefined instead of throwing when the resolved model runtime is claude-cli.
  • Why this is the smallest reliable guardrail: the failure happens before any live channel or model dispatch, so a focused unit test on the preflight helper covers the exact regression with minimal setup.

Root Cause

  • Root cause: maybeCompactAgentHarnessSession unconditionally called selectAgentHarness, so model runtime policy values like claude-cli were treated as harness ids and triggered MissingAgentHarnessError.
  • Missing detection / guardrail: compaction preflight lacked the CLI-runtime bypass already present in the main dispatch/fallback path.

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

clawsweeper Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Workflow note: Future ClawSweeper reviews update this same comment in place.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Summary
This PR adds a CLI runtime alias bypass to maybeCompactAgentHarnessSession and adds a regression test for claude-cli runtime compaction preflight.

Reproducibility: yes. Source inspection shows current main resolves claude-cli as a configured runtime, then harness selection treats the non-auto runtime as a harness id and throws when no claude-cli harness is registered.

PR rating
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Summary: The PR is a focused, well-tested bug fix with sufficient helper-level runtime proof and no blocking correctness findings.

Rank-up moves:

  • none
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Real behavior proof
Sufficient (terminal): The PR body includes terminal output from a real checkout showing the helper returning undefined for claude-cli after the patch plus the focused Vitest file passing.

Risk before merge

  • I did not run tests in this read-only review, and the supplied proof exercises the helper path rather than a full over-threshold live channel turn.

Maintainer options:

  1. Decide the mitigation before merge
    Merge the targeted CLI-alias bypass with its regression test after normal CI, keeping broader CLI compaction behavior separate unless a real runtime API gap appears.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge
No automated repair lane is needed because this PR already contains the narrow code and regression-test fix; it should proceed through normal review and CI.

Security
Cleared: The diff only reuses an existing runtime alias helper and adds a focused unit test; no security or supply-chain surface changes were found.

Review details

Best possible solution:

Merge the targeted CLI-alias bypass with its regression test after normal CI, keeping broader CLI compaction behavior separate unless a real runtime API gap appears.

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

Yes. Source inspection shows current main resolves claude-cli as a configured runtime, then harness selection treats the non-auto runtime as a harness id and throws when no claude-cli harness is registered.

Is this the best way to solve the issue?

Yes. The PR uses the existing CLI alias contract to skip only CLI-runtime harness preflight and lets the current non-harness compaction path continue, which is the narrowest maintainable fix for this call site.

Label changes:

  • add P1: The PR fixes an urgent agent runtime regression that can block over-threshold CLI-backed sessions before dispatch and surface the harness error to users.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal output from a real checkout showing the helper returning undefined for claude-cli after the patch plus the focused Vitest file passing.
  • add rating: 🐚 platinum hermit: Current PR rating is 🐚 platinum hermit because proof is 🐚 platinum hermit, patch quality is 🐚 platinum hermit, and The PR is a focused, well-tested bug fix with sufficient helper-level runtime proof and no blocking correctness findings.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes terminal output from a real checkout showing the helper returning undefined for claude-cli after the patch plus the focused Vitest file passing.

Label justifications:

  • P1: The PR fixes an urgent agent runtime regression that can block over-threshold CLI-backed sessions before dispatch and surface the harness error to users.
  • rating: 🐚 platinum hermit: Current PR rating is 🐚 platinum hermit because proof is 🐚 platinum hermit, patch quality is 🐚 platinum hermit, and The PR is a focused, well-tested bug fix with sufficient helper-level runtime proof and no blocking correctness findings.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes terminal output from a real checkout showing the helper returning undefined for claude-cli after the patch plus the focused Vitest file passing.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal output from a real checkout showing the helper returning undefined for claude-cli after the patch plus the focused Vitest file passing.

What I checked:

  • Current main routes compaction through harness selection: On current main, maybeCompactAgentHarnessSession immediately calls selectAgentHarness for the compaction target and only continues to non-harness compaction when that selected harness is PI without a compactor. (src/agents/harness/selection.ts:442, 43c6c260deb0)
  • Current main throws for unmatched explicit runtimes: selectAgentHarnessDecision treats non-auto runtimes as harness ids and throws MissingAgentHarnessError when no registered plugin harness has that id. (src/agents/harness/selection.ts:153, 43c6c260deb0)
  • CLI runtime aliases are not harness ids: The docs explicitly say claude-cli executes canonical Anthropic models through the CLI backend and must not be passed to AgentHarness selection. Public docs: docs/concepts/agent-runtimes.md. (docs/concepts/agent-runtimes.md:37, 43c6c260deb0)
  • Existing alias helper matches the proposed guard: isCliRuntimeAlias already identifies configured CLI backend aliases such as claude-cli and google-gemini-cli, so using it before harness selection follows the existing runtime contract. (src/agents/model-runtime-aliases.ts:139, 43c6c260deb0)
  • Undefined preserves the queued compaction fallback path: The queued compaction caller only returns early when maybeCompactAgentHarnessSession returns a harness result; undefined continues into the regular queued compaction flow. (src/agents/pi-embedded-runner/compact.queued.ts:119, 43c6c260deb0)
  • PR regression coverage: The PR head adds a test that expects maybeCompactAgentHarnessSession to resolve undefined for an Anthropic model configured with agentRuntime.id: "claude-cli". (src/agents/harness/selection.test.ts:597, 79d259768c80)

Likely related people:

  • Peter Steinberger: Blame ties the current maybeCompactAgentHarnessSession, isCliRuntimeAlias, and queued compaction call path to the same current-main import commit in the reviewed shallow history. (role: introduced current helper and alias surface; confidence: high; commits: 1fdeee380e75; files: src/agents/harness/selection.ts, src/agents/model-runtime-aliases.ts, src/agents/pi-embedded-runner/compact.queued.ts)
  • Gio Della-Libera: Recent shallow-history commits touched pre-prompt compaction decisions and stale runtime override cleanup, both adjacent to this compaction/runtime policy area. (role: recent adjacent contributor; confidence: medium; commits: 79be9401306f, 8284c035a096; files: src/agents/pi-embedded-runner/run/preemptive-compaction.ts, src/commands/doctor-session-state-providers.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 43c6c260deb0.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Neon Crabkin

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.

Rarity: 🥚 common.
Trait: sparkles near resolved comments.
Image traits: location merge queue dock; accessory review stamp; palette violet, aqua, and starlight; mood celebratory; pose sitting proudly on a smooth stone; shell starlit enamel shell; lighting tiny status-light glow; background delicate sparkle particles.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Neon Crabkin in ClawSweeper.

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.

@Takhoffman

Copy link
Copy Markdown
Contributor

@clawsweeper automerge

@clawsweeper

clawsweeper Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

🦞🔧
ClawSweeper automerge is enabled.

Draft PRs stay fix-only until GitHub marks them ready for review. Pause with /clawsweeper stop.

Automerge progress:

  • 2026-05-23 23:09:52 UTC review queued 79d259768c80 (queued)

@clawsweeper clawsweeper Bot added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label May 23, 2026
@clawsweeper

clawsweeper Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper 🐠 reef update

Thanks for the contribution. ClawSweeper hit a branch-permission wall on this PR, so it opened a replacement branch to keep review moving while preserving credit.

Why replacement: ClawSweeper could not update the source PR branch directly; GitHub did not grant sufficient push rights to the bot for that branch.
Replacement PR: #85862
Why close: this run explicitly closes the superseded source PR after the credited replacement PR is open, so review continues in one place.
Closing this source PR because this run explicitly enabled source-PR closeout.
The replacement PR keeps the contributor trail visible for review and changelog credit.
Co-author credit kept:

fish notes: model gpt-5.5, reasoning high; reviewed against de553c3.

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

Labels

agents Agent runtime and tooling clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Compaction preflight throws MissingAgentHarnessError("claude-cli") for claude-cli runtime sessions over contextThreshold

2 participants