Skip to content

fix(anthropic): stop reporting success after OpenClaw MCP startup fails - #176154

Merged
obviyus merged 3 commits into
openclaw:mainfrom
xyi74976-del:fix/claude-cli-mcp-startup
Oct 30, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
xyi74976-del:fix/claude-cli-mcp-startup

Conversation

@xyi74976-del

@xyi74976-del xyi74976-del commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #176138

What Problem This Solves

Claude Code can explicitly report that its required openclaw MCP server failed to connect, then complete a turn successfully without Gateway tools. OpenClaw previously ignored that startup status and could retain the affected process for later turns.

Reported by @Oldrich333; original fix and commits by @xyi74976-del are retained.

User Impact

A Claude CLI turn whose init explicitly reports a non-connected OpenClaw MCP server now fails visibly with a concrete retry instruction. The process is retired and joined so the next request starts fresh. A connected OpenClaw server remains reusable even when an unrelated optional server failed; an init without an OpenClaw entry keeps its existing behavior.

Why This Change Was Made

The Anthropic plugin's existing init owner now checks the reported OpenClaw server and routes startup failure through the existing session-close owner before accepting more output. No timeout override, automatic replay, dependency, permission, authentication or SDK change is introduced.

Evidence

Captured built-Gateway / genuine Claude Code proof and focused checks.

Independently built pinned main 5eda466704861324a87e05a488cb10888e66b8a7 and contributor candidate 55e9b8579bb58d5916d069d78b53d6a91e60d84f. The current revision changes tests only; the production guard is unchanged from the proven candidate.

Used real official Claude Code 2.1.309, the built Gateway, normal claude-cli backend and shipped agent command. A trusted-CA HTTPS CONNECT Messages fixture supplies local responses without a login or paid key; the container had no external network during proof. An in-process latency preload holds the actual Gateway MCP request dispatch beyond native startup/fallback timeouts; it does not manufacture native init or tool-result records.

  • Main twice: genuine system/init.mcp_servers reports openclaw: failed, but the Gateway returns completed success with 0 tool calls.
  • Candidate twice: the same genuine failed init produces CLI exit 1 and the visible startup error/retry guidance.
  • Normal-connect controls on both refs: genuine init reports connected, actual ToolSearch and Gateway-backed Read execute, and the real file marker reaches the local Messages fixture.
  • The committed failed/pending regressions fail on main because their promises incorrectly resolve. Candidate: 91 passed across the owner suite and two transport/process consumers; wrapper 61.82 s. Baseline selected regression: 2 failed /65 skipped, wrapper 44.15 s.
  • Changed-file formatting passes. Direct strict local lint reports only the existing documented 710/700 runtime file-size limit; no suppression/config change was made. Hosted CI owns broad lint, typechecks and ratchets.

The separate added test file is removed. The existing native-stdio suite retains startup rejection, exited-process retirement, fresh-process recovery, warm reuse, optional-server failure and absent-entry contracts. Shared warm assertions replace duplicate assertions/setup without removing their independent checks.

Whole-PR surface: production +15/-0, tests/support +31/-31 (net 0), docs +5/-0. No new test file or allocation.

Merge Risk

Two-way door: reverting restores the previous startup acceptance behavior; this changes no persisted schema or configuration. Blast radius is Claude CLI turns whose init explicitly names a non-connected openclaw MCP server. Healthy and absent-entry startup behavior remains covered. Genuine CLI failures retain the existing fallback behavior.

@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: anthropic size: S labels Oct 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Reject Claude CLI turns when startup explicitly reports a disconnected OpenClaw MCP server, retire the process, and explain how to retry.

Example: Claude Code 2.1.309 reports openclaw status failed after delayed Gateway MCP startup.

  • Before: The Gateway reports completed success with zero tool calls and can retain the process.
  • After: The request fails visibly with retry guidance, and the failed process is retired.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A small, complete owner-level repair with shipped-entry-point fault proof, healthy controls, and focused red/green lifecycle regressions.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): obviyus supplied captured output through built gateway run and agent commands with genuine Claude Code 2.1.309 in isolated Docker: delayed real MCP dispatch produces native failed init and false success on main, then visible rejection on the candidate; connected controls execute actual Gateway-backed Read, and the current head preserves the proven production code.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An agent can report a successful turn despite having lost the configured Gateway tools during Claude startup.
Reason: The linked report and genuine native-client proof establish silent workflow failure, and the narrow fix preserves the existing host and plugin ownership boundaries.

Merge readiness

✅ Ready for maintainer review

This PR fixes a confirmed current-main failure without introducing an actionable defect; exact-head CI remains pending.

Priority: P1
Reviewed head: 64e6d000ddd5d95d4fc5a8ef9fcfada7bfe75f69

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Anthropic plugin consumes Claude Code stream-json records, delivers turn output to the shared CLI runner, and owns subprocess reuse and retirement.

flowchart TD
  A[Gateway agent request] --> B[Shared CLI runner]
  B --> C[Anthropic CLI runtime]
  C --> D[Claude Code process]
  D --> E[Startup MCP status]
  E --> C
  C --> F[Turn output or startup error]
  C --> G[Existing session cleanup]
Loading

Technical review

Best possible solution:

Use the existing init and session-cleanup owners to reject explicitly disconnected OpenClaw startup while preserving healthy and absent-entry behavior.

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

Current-main source still accepts failed init followed by success, and the supplied built-Gateway reproduction demonstrates that failure on pinned main; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch restores the configured tool-surface contract at its existing protocol owner, preserves cleanup ordering, and avoids timeout changes, automatic replay, or a second lifecycle path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 176c9c7496fd.

Provenance checked

  • Claude init handling and process retirement keeps the original intent (58d8871: The direct transport keeps native protocol handling in the Anthropic plugin while retaining shared host admission, MCP lifetime, and process cleanup.)
  • Concurrent startup consumption and cleanup joins keeps the original intent (3c29dcf: Consume startup events while initialization proceeds to prevent bounded-stream deadlock, preserving ordering and cancellation settlement.)
  • Existing native-stdio regression consolidation keeps the original intent (000465e: Consolidate repeated fixture setup while retaining distinct lifecycle, recovery, and transport contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +15, Tests 0, Docs +5. Total +20 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 15 0 +15
Tests 2 31 31 0
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 51 31 +20

Review metrics

Metric Value Why it matters
Production versus test LOC Production +15/-0; tests/support +31/-31 The focused init guard adds no parallel lifecycle machinery, and regression consolidation keeps whole-PR test growth at zero.

Root-cause cluster

Relationship: same_root_cause
Canonical: #176138
Summary: This PR implements the linked failed-init repair; general required-server retry policy is separate work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: Failed Claude MCP startup silently removes Gateway tools while agent workflows report success and can reuse the affected process.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-18T09:00:39.519Z sha 55b358e21894feb4b605e4cb4970ec28e7826769 :: needs real behavior proof before merge. :: [P3] Add a recovery instruction to the MCP startup error
  • reviewed 2026-10-19T11:51:23.297Z sha 26931797510d92753381fa3ece4ab887da869fa9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-19T12:21:26.499Z sha 26931797510d92753381fa3ece4ab887da869fa9 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-30T11:34:11.442Z sha 55e9b85 :: needs maintainer review before merge. :: none

Reviewed October 30, 2026, 8:00 AM ET / 12:00 UTC (Revision 5).

@xyi74976-del

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Recovery guidance is fixed in 26931797. The updated PR body includes real Claude Code 2.1.278 evidence through the production executor: failed MCP startup rejects the turn, retires the original process, and the next request succeeds on a fresh process. Official npm 2026.10.4 configuration is accepted unchanged at this head. This is configuration compatibility, not a running Gateway or state-database upgrade. The CI gate has passed for 26931797.

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 19, 2026
@xyi74976-del

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added captured test output and the recorded runtime JSON to the PR body for 26931797, including the failed-process exit and successful retry on a different PID. The real Claude Code executable used isolated state and local MCP/API responses; no live Gateway upgrade or external model request is claimed. No code changes since the previous review.

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 19, 2026
@xyi74976-del
xyi74976-del force-pushed the fix/claude-cli-mcp-startup branch from 2693179 to 0724208 Compare October 24, 2026 04:59
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Built Gateway / genuine Claude Code startup proof

Independently installed and built pinned main 5eda466704861324a87e05a488cb10888e66b8a7 and contributor head 55e9b8579bb58d5916d069d78b53d6a91e60d84f in secretless Docker, Node 24.22.1. The subsequent repair consolidates tests only; the reviewed production startup guard is unchanged.

Used official Claude Code 2.1.309, normal claude-cli backend, shipped gateway run, sessions.patch, and agent --session-key ... --json commands. Every process used an explicit isolated profile and task-owned HOME/config/state/workspace. The built CLI's config file and sessions --json paths were checked before Gateway startup.

No account, login, paid key or external model request: a synthetic API-key profile feeds the normal credential path. Genuine Claude traffic to api.anthropic.com:443 traversed an allowlisted HTTPS CONNECT fixture with an isolated trusted test CA; TLS verification remained enabled. Docker networking was disconnected before proof (Networks: {}). The fixture emits standard Messages SSE, not native protocol records or tool results. Healthy controls execute actual ToolSearch and Gateway-backed Read; the fixture observes TASK_176154_ACTUAL_READ_RECEIPT returned by the real read.

Stall and observed outcomes

A process-local preload delays only the built Gateway's /mcp HTTP request dispatch by 60 seconds, leaving normal Gateway RPC, native auth, tool permissions and Claude timeout settings unchanged. Native attempts start approximately five seconds apart; Claude's complete startup/fallback budget produces init after about 30 seconds. A preliminary 6.5-second hold allowed native fallback to reconnect, so it was not counted as a failed-startup reproduction. No clock was changed.

Native stdout is observed passively at the real child-process pipe. The following mcp_servers comes from genuine system/init records, not fixture-authored JSON:

{"type":"system","subtype":"init","mcp_servers":[{"name":"openclaw","status":"failed","source":"dynamic"}]}
Built ref Case Real init openclaw status CLI exit / Gateway outcome Actual tool activity
main delayed 1 failed 0 / status: ok, summary: completed 0 calls
main delayed 2 failed 0 / status: ok, summary: completed 0 calls
candidate delayed 1 failed 1 / ok: false, cli_error no read receipt
candidate delayed 2 failed 1 / ok: false, cli_error no read receipt
main normal connect connected 0 / completed ToolSearch + real Read; marker confirmed
candidate normal connect connected 0 / completed ToolSearch + real Read; marker confirmed

Main delayed elapsed: 32,256 ms and 31,775 ms. Candidate delayed elapsed: 32,608 ms and 31,802 ms. Healthy controls: 1,853 ms main / 1,957 ms candidate.

Both candidate failures surface this exact operator-facing JSON:

{
  "ok": false,
  "origin": "gateway",
  "error": {
    "type": "cli_error",
    "message": "Claude Code started without the OpenClaw MCP server (status failed). The CLI process was retired; retry the request to start a fresh process."
  }
}

Both main runs instead return:

{
  "status": "ok",
  "summary": "completed",
  "toolSummary": {"calls": 0, "tools": [], "failures": 0}
}

The matrix above uses the retained main run and the completed candidate run. An additional candidate observation emitted pending at the same native startup deadline and was also correctly rejected; it is not substituted for either of the two failed cases above. All task-owned Gateways and fixture servers exited at the end of each run.

Regression consolidation

Removed the separate startup-test file and folded failed/pending rejection, exited-process retirement, fresh-process recovery and subsequent warm reuse into the existing native-stdio suite. Existing argument/private-context warm-turn coverage now also covers a connected OpenClaw server despite an optional failed server, and an absent OpenClaw entry. Shared warm-turn assertions preserve the original independent contracts while removing duplicated setup/assertions. Whole-PR test-line delta is 0, with no allocation or new test file.

Focused validation

  • On pinned main, both consolidated startup regressions fail for the intended reason: promise resolved ... instead of rejecting after native-style failed/pending init followed by success. 2 failed, 65 skipped; wrapper 44.15 s.
  • Candidate: 91/91 passed across cli-runtime.test.ts, cli-process.test.ts, and cli-transport.close.test.ts; wrapper 61.82 s (Vitest 52.97 s). The owning runtime suite includes both healthy-server controls and fresh-process recovery/warm reuse after rejection.
  • Changed-file formatting passes.
  • Direct strict local lint reports only the already-documented file-size limit: cli.runtime.ts is 710 nonblank/noncomment lines vs 700. No suppression, lint config change, or unrelated production refactor was added. Hosted repository lint/ratchets remain the authority for merge gating.
  • Whole-PR production +15/-0, tests/support +31/-31 (net 0), docs +5/-0. No added test file or test allocation remains.

@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@obviyus
obviyus merged commit f964859 into openclaw:main Oct 30, 2026
123 of 126 checks passed
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Landed in f964859. Thanks @xyi74976-del. Claude CLI turns now report it when the openclaw MCP server fails to start, instead of running without tools.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…ls (openclaw#176154)

fix(anthropic): fail the Claude CLI turn when the openclaw MCP server fails to start

Fixes openclaw#176138.

When the Gateway was slow to answer and Claude Code's own 5-second MCP connect timeout expired, Claude reported the openclaw MCP server as `failed` in its `system/init` message. OpenClaw ignored that, so the turn ran without any OpenClaw tools and still reported success. OpenClaw now checks the init message, ends the session through the existing closeSession path and reports a startup failure with retry guidance.

Evidence: real Claude Code 2.1.309 routed through a trusted-CA HTTPS CONNECT fixture (no login, no paid key) with built Gateways. A delayed Gateway MCP dispatch produced `system/init.mcp_servers: [{name:"openclaw",status:"failed"}]`. Main reported success with 0 tool calls (twice); with this change the turn exited with the startup failure and retry guidance (twice). With a normal connect, both refs ran ToolSearch and a Gateway-backed Read with the file contents. Details: openclaw#176154 (comment).

Thanks @xyi74976-del.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Retire the existing CLI process when its init message reports disconnected OpenClaw MCP, and give actionable retry guidance rather than reporting a tool-less success. Preserve optional-server and absent-status behavior.

(cherry picked from commit f964859)

Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: anthropic gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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]: claude-cli turn runs without OpenClaw tools when init reports the openclaw MCP server failed

2 participants