Skip to content

fix(cli): preserve sessions_yield over MCP - #90861

Merged
vincentkoc merged 5 commits into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-77426
Jun 16, 2026
Merged

vincentkoc merged 5 commits into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-77426

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

sessions_yield on CLI-backed MCP turns was created without the active run session id or yield callback, so it returned No session context instead of pausing the run.

This change keeps yield ownership inside the existing per-CLI MCP capture:

  • injects the run session id into the loopback MCP request
  • binds the yield callback to the admitted capture generation
  • includes that generation in the short-lived tool cache key, preventing stale callbacks when a capture key is reused
  • records yielded CLI output as paused / end_turn
  • projects the same terminal metadata into lifecycle events

No user config, migration, provider routing, or embedded-runner behavior changes.

Closes #77426

Real behavior proof

  • Behavior addressed: CLI-backed MCP sessions_yield now yields the active run instead of returning No session context.
  • Real environment tested: The production OpenClaw MCP loopback HTTP server and gateway-scoped tool resolver, started from the rebased PR head with an isolated OPENCLAW_STATE_DIR.
  • Exact steps or command run after this patch: Started src/gateway/mcp-http.ts through node --import tsx --input-type=module, registered a real CLI capture, and sent an authenticated HTTP tools/call request for sessions_yield with x-openclaw-session-id and x-openclaw-cli-capture-key.
  • Evidence after fix: Console output from the after-fix production loopback run:
{"httpStatus":200,"rpcIsError":false,"toolResult":{"status":"yielded","message":"real loopback yield"},"yielded":true,"yieldedMessage":"real loopback yield"}
  • Observed result after fix: The production loopback endpoint returned HTTP 200 and status: "yielded"; the admitted CLI capture received the same yield message.
  • What was not tested: A separately installed external Claude CLI binary initiating the MCP call.

Verification

  • Focused Vitest: 3 shards, 12 files, and 372 tests passed after the final rebase.
  • git diff --check: passed.
  • Targeted oxlint for all changed TypeScript files: passed.
  • Remote changed gate: pnpm check:changed passed on AWS Crabbox cbx_9c668236f0f7, run run_d5de9a775bf2.
  • Autoreview: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main returned no findings; overall confidence 0.84.

Risk

The sensitive boundary is reuse of short-lived loopback tool objects. Requests bind to their admitted capture generation, and the generation is part of the cache key, so an older request cannot yield a newer CLI turn.

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

clawsweeper Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 15, 2026, 9:22 AM ET / 13:22 UTC.

Summary
The PR threads MCP loopback run session/yield context through CLI preparation, gateway HTTP tool resolution, loopback tool caching, CLI result metadata, lifecycle events, and regression tests.

PR surface: Source +97, Tests +273. Total +370 across 14 files.

Reproducibility: yes. source-level: current main constructs gateway/MCP tools without the sessionId and onYield fields that sessions_yield requires, so the MCP/CLI path reaches No session context.

Review metrics: 1 noteworthy metric.

  • Loopback Session-State Carriers: 1 internal env/header pair added; 1 cache-key dimension added. These are the fields that bind a CLI MCP tool call to the active run, so maintainers should confirm the lifetime invariant before merge.

Stored data model
Persistent data-model change detected: persistent cache schema: src/gateway/mcp-http.loopback-runtime.ts, persistent cache schema: src/gateway/mcp-http.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Refresh the branch so GitHub no longer reports CONFLICTING / DIRTY.
  • Have a gateway/agent owner confirm whether one active CLI loopback yield context per sessionId is the intended invariant.

Risk before merge

  • [P1] The live PR is currently merge-conflicting, so maintainers need a refreshed merge result before landing.
  • [P1] The PR's yield context registry is keyed by persistent sessionId; if overlapping active CLI loopback runs can share that id, the registry should become run-bound before merge.

Maintainer options:

  1. Refresh And Confirm Session Ownership (recommended)
    Resolve the merge conflicts and have a gateway/agent owner confirm that one active CLI loopback yield context per sessionId is the intended runtime invariant before merge.
  2. Switch To A Run-Bound Registry
    If overlapping CLI loopback runs can share a session id, replace the process-local sessionId map with an explicit run-bound context registry before landing.
  3. Pause For A Replacement
    If this branch becomes too costly to refresh, keep the linked issue open and close this PR only after a narrow replacement with equivalent real CLI proof is ready.

Next step before merge

  • [P2] Manual maintainer review is needed because the live PR is merge-conflicting and the remaining session-state question is an owner invariant, not a narrow automated repair.

Security
Cleared: No concrete security or supply-chain issue found; the diff keeps existing loopback bearer/origin checks and only adds internal run/session context plumbing.

Review details

Best possible solution:

Refresh the branch and land the narrow MCP/CLI yield fix after a gateway/agent owner confirms the process-local yield-context lifetime or changes it to a run-bound owner key.

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

Yes, source-level: current main constructs gateway/MCP tools without the sessionId and onYield fields that sessions_yield requires, so the MCP/CLI path reaches No session context.

Is this the best way to solve the issue?

Yes, with owner confirmation: the patch fixes the boundary that drops run context and aligns yielded lifecycle state, but maintainers still need a refreshed merge result and session-lifetime confirmation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against dd7f2ef002e8.

Label changes

Label justifications:

  • P1: The PR targets a broken CLI-backed multi-agent sessions_yield workflow that can block affected users from pausing and resuming parent sessions after subagent work.
  • merge-risk: 🚨 session-state: The PR changes how MCP loopback tool calls bind a yield callback to active CLI run/session state, where a bad lifetime invariant could pause the wrong run.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body has terminal smoke proof for the real loopback HTTP endpoint, and a member comment adds a real local claude CLI strict-MCP smoke invoking sessions_yield.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body has terminal smoke proof for the real loopback HTTP endpoint, and a member comment adds a real local claude CLI strict-MCP smoke invoking sessions_yield.
Evidence reviewed

PR surface:

Source +97, Tests +273. Total +370 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 8 99 2 +97
Tests 6 275 2 +273
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 374 4 +370

What I checked:

Likely related people:

  • jriff: Authored the merged sessions_yield feature commit that introduced the tool contract this PR extends to the MCP/CLI path. (role: introduced behavior context; confidence: high; commits: 3fa91cd69d5d; files: src/agents/tools/sessions-yield-tool.ts, src/agents/embedded-agent-runner/run/attempt.ts)
  • eleqtrizit: Authored recent MCP loopback owner/tool-cache work near the cache-key surface changed here. (role: recent gateway loopback contributor; confidence: medium; commits: b6a3f2988c66; files: src/gateway/mcp-http.runtime.ts, src/gateway/tool-resolution.ts)
  • openperf: Authored the recent yielded-subagent lifecycle fix that defines how yielded terminal events pause rather than complete subagent runs. (role: recent adjacent lifecycle contributor; confidence: high; commits: cd3eb438f07f; files: src/agents/subagent-registry.ts)
  • obviyus: Recent history shows repeated maintenance of CLI lifecycle/event bridging adjacent to the lifecycle propagation changed by this PR. (role: recent CLI lifecycle contributor; confidence: medium; commits: 0c4fc0a2e3b3, bd96e4d22daf, e1ac2d09259a; files: src/auto-reply/reply/agent-runner-cli-dispatch.ts)
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.

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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 6, 2026
@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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 6, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 6, 2026
@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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 6, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 7, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 7, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 7, 2026
@hxy91819

Copy link
Copy Markdown
Member

Additional local verification:

I ran a real local claude CLI binary smoke against this PR head using a generated strict MCP config pointed at OpenClaw's loopback MCP endpoint.

Proof summary:

  • Prewarmed the same loopback session with initialize + tools/list; sessions_yield was present.
  • Ran claude -p --strict-mcp-config --mcp-config <temp> --allowedTools=mcp__openclaw__sessions_yield ....
  • Claude issued mcp__openclaw__sessions_yield with the expected message.
  • The MCP tool result returned status: "yielded" with the same message.
  • The OpenClaw loopback yield context recorded yielded: true.

This closes the earlier proof gap around a real CLI client consuming the generated MCP config and invoking the loopback sessions_yield path. The remaining review question is still the maintainer decision on the sessionId-keyed process-local yield owner invariant.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jun 14, 2026
@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. and removed 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. labels Jun 15, 2026
@vincentkoc vincentkoc self-assigned this Jun 16, 2026
@vincentkoc vincentkoc changed the title fix #77426: [Bug]:sessions_yield: always returns "No session context" on MCP/claude-cli agent runtime path (gateway tool resolver missing sessionId + onYield) fix(cli): preserve sessions_yield over MCP Jun 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. proof: supplied External PR includes structured after-fix real behavior proof. and removed proof: supplied External PR includes structured after-fix real behavior proof. proof: sufficient ClawSweeper judged the real behavior proof convincing. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 16, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Land-ready maintainer verification for head 711573184aaa0f8bee8147889217860e33f9617e:

  • Narrowed the fix to the existing per-CLI MCP capture owner; no second process-global session registry remains.
  • Requests bind yield callbacks to their admitted capture generation, and that generation participates in the loopback tool cache key.
  • Real behavior proof: production loopback HTTP sessions_yield returned HTTP 200 / status: yielded, and the admitted CLI capture received the same message.
  • Focused proof: node scripts/run-vitest.mjs src/gateway/tool-resolution.test.ts src/gateway/mcp-http.test.ts src/agents/cli-runner/execute.supervisor-capture.test.ts src/agents/cli-runner.reliability.test.ts src/agents/cli-runner/prepare.test.ts src/auto-reply/reply/agent-runner-cli-dispatch.test.ts — 3 shards, 12 files, 372 tests passed.
  • Broad proof: AWS Crabbox cbx_9c668236f0f7, run run_d5de9a775bf2, pnpm check:changed passed.
  • Autoreview: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main — no findings, confidence 0.84.
  • Exact-head GitHub checks are green, including type/lint/guards, agent-runtime Critical Quality, MCP/security boundaries, and real-behavior proof.
  • Known proof gap: no separately installed external Claude CLI binary initiated the MCP call; the production OpenClaw loopback endpoint and resolver were exercised directly.

Best-fix verdict: best bounded fix at the current ownership boundary. Ready for rebase merge without squash.

@vincentkoc
vincentkoc merged commit 2b05bd7 into openclaw:main Jun 16, 2026
207 of 219 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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]:sessions_yield: always returns "No session context" on MCP/claude-cli agent runtime path (gateway tool resolver missing sessionId + onYield)

3 participants