Skip to content

[Bug]:sessions_yield: always returns "No session context" on MCP/claude-cli agent runtime path (gateway tool resolver missing sessionId + onYield) #77426

Closed

Description

@jarvisagimuspicard-hub

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

sessions_yield always returns "No session context" on MCP/claude-cli agent runtime path — gateway tool resolver missing sessionId and onYield

Steps to reproduce

  1. Configure agents.defaults.agentRuntime.id = "claude-cli" (default when using Claude CLI subscription billing)
  2. Have parent agent spawn a subagent via sessions_spawn
  3. Have parent agent call sessions_yield
  4. Observe: {"status": "error", "error": "No session context"} returned immediately

Expected behavior

sessions_yield should pause the parent session and wait for child completion, as documented and as works in the embedded runner path

Actual behavior

sessions_yield returns "No session context" on every call from the MCP/claude-cli path because sessionId and onYield are not passed by resolveGatewayScopedTools

OpenClaw version

2026.5.3-1 (2eae30e)

Operating system

macOS 15.4

Install method

npm global

Model

anthropic/claude-sonnet-4-6

Provider / routing chain

openclaw -> claude-cli -> anthropic

Additional provider/model setup details

Agent runtime: claude-cli (agents.defaults.agentRuntime.id = "claude-cli")
Auth method: OAuth via Claude CLI subscription (anthropic:claude-cli profile)
Main agent model: anthropic/claude-sonnet-4-6 (set via modelByChannel for Telegram)
Default fallback model: ollama/qwen3.5:9b (local Ollama)
Subagent model tested: ollama/qwen3.5:9b
MCP endpoint: gateway HTTP loopback at 127.0.0.1:55691/mcp
Channel: Telegram (primary)
The failure is channel-independent — occurs on any channel where agentRuntime.id = "claude-cli" is in effect.

Logs, screenshots, and evidence

## Summary

`sessions_yield` always fails with `{status: "error", error: "No session context"}` when called by an MCP client (e.g. `claude-cli` agent runtime) against the gateway's HTTP loopback MCP endpoint. The cause is in the gateway tool resolver, which builds the OpenClaw tool surface for MCP without populating the two parameters the tool requires. This is independent of channel — it surfaces wherever `agentRuntime.id = "claude-cli"` is in use, regardless of whether the originating channel is Telegram, Discord, or anything else.

The 2026.5.3-1 release notes describe a `sessions_yield` fix; that fix landed in the embedded runner path but the gateway/MCP path was not updated.

## Affected versions

Confirmed on **`OpenClaw 2026.5.3-1` (commit `2eae30e`)**. The structural shape (separate embedded vs MCP tool builders) suggests this has been latent since the MCP HTTP loopback was introduced.

## Symptom

For an agent run driven by `claude-cli` (config `agents.defaults.agentRuntime.id = "claude-cli"`):

1. Parent agent calls `mcp__openclaw__spawn` to spawn a subagent — succeeds.
2. Parent agent calls `mcp__openclaw__sessions_yield` to end its turn and wait for child completion — receives:
   
   {"status": "error", "error": "No session context"}
   
3. Parent agent never re-engages with the child completion event.

Subagent spawn and the child's run/announce delivery work correctly. The failure is isolated to `sessions_yield`.

## Root cause

The gateway tool resolver does not pass `sessionId` or `onYield` through to `createOpenClawTools`.

### Tool implementation

`src/agents/tools/sessions-yield-tool.ts` (in this build: `dist/openclaw-tools-D7Zj4hDN.js:8145–8167`):


function createSessionsYieldTool(opts) {
    return {
        name: "sessions_yield",
        execute: async (_toolCallId, args) => {
            const message = readStringParam$1(args, "message") || "Turn yielded.";
            if (!opts?.sessionId) return jsonResult({
                status: "error",
                error: "No session context"          // ← always hit on the MCP path
            });
            if (!opts?.onYield) return jsonResult({
                status: "error",
                error: "Yield not supported in this context"
            });
            await opts.onYield(message);
            return jsonResult({ status: "yielded", message });
        }
    };
}


Both `opts.sessionId` and `opts.onYield` must be set for the tool to function.

### Embedded runner path — wires both, works

`src/agents/pi-embedded-runner/run/attempt.ts` (`runEmbeddedAttempt`, in this build: `dist/selection-DL4MPaGt.js:6515–6552`):


sessionId: params.sessionId,                        // ← set
// ...
onYield: (message) => {                             // ← set
    yieldDetected = true;
    yieldMessage = message;
    queueYieldInterruptForSession?.();
    runAbortController.abort("sessions_yield");
    abortSessionForYield?.();
}


### Gateway/MCP path — wires neither, broken

`src/gateway/tool-resolution.ts` (`resolveGatewayScopedTools`, in this build: `dist/tool-resolution-BmNDC-w0.js:34–68`):


tools: createOpenClawTools({
    agentSessionKey: params.sessionKey,
    agentChannel: params.messageProvider ?? void 0,
    agentAccountId: params.accountId,
    agentTo: params.agentTo,
    agentThreadId: params.agentThreadId,
    allowGatewaySubagentBinding: params.allowGatewaySubagentBinding,
    allowMediaInvokeCommands: params.allowMediaInvokeCommands,
    disablePluginTools: params.disablePluginTools,
    senderIsOwner: params.senderIsOwner,
    config: params.cfg,
    workspaceDir,
    pluginToolAllowlist: ...,
    pluginToolDenylist: ...
    // sessionId: NOT PASSED
    // onYield:   NOT PASSED
})


The MCP HTTP loopback handler (`src/gateway/mcp-http.loopback-runtime.ts`, in this build: `dist/mcp-http-BUaWXl8U.js:343–352`) calls `resolveGatewayScopedTools` with:


const next = resolveGatewayScopedTools({
    cfg: params.cfg,
    sessionKey: params.sessionKey,
    messageProvider: params.messageProvider,
    accountId: params.accountId,
    senderIsOwner: params.senderIsOwner,
    surface: "loopback",
    excludeToolNames: NATIVE_TOOL_EXCLUDE
});


There is no `sessionId` in scope at the MCP-HTTP layer at all — the field is run-bound, and at MCP-tool-call time the gateway is not driving a run; `claude-cli` is.

## Why subagent spawn works but `sessions_yield` doesn't

Subagent tools key off `agentSessionKey` (passed by `resolveGatewayScopedTools`). `sessions_yield` keys off `sessionId` (not passed). Both code paths run through the same MCP loopback, but only the former has all its required inputs populated.

## Architectural note on `onYield`

A drop-in fix that just plumbs `sessionId` through is not sufficient, because the embedded `onYield` semantics don't translate to the MCP path:


runAbortController.abort("sessions_yield");


In the embedded runner the gateway owns the model loop and can abort it. In the MCP/claude-cli path the model loop runs inside `claude-cli`; the gateway has no abort handle for it. The natural turn-end for `claude-cli` is "the tool returned" — it ends its turn after receiving the tool result regardless. So the MCP-path `onYield` should:

1. Mark the parent session as paused for `sessions_yield` in the subagent registry (matches the existing `entry.pauseReason = "sessions_yield"` flag at `dist/subagent-registry-DXnKPE_6.js:849-850` and the gate at `1481`).
2. Ensure pending and future child completion events are queued for the next user turn.
3. Return success synchronously so the tool result reaches `claude-cli` and lets it end its turn naturally.

No abort, no interrupt injection, no transcript stitching needed on the gateway side — the protocol boundary makes that the client's job.

## Suggested fix direction (not prescribing a patch)

1. Plumb a session/run binding through the MCP HTTP layer. The MCP handler already has `params.sessionKey`; resolving the active run/transcript `sessionId` from that (or from the existing per-session context lookup used elsewhere) gives `createSessionsYieldTool` what it needs for the gate check.
2. Provide an MCP-flavored `onYield` that records pause-for-yield in the subagent registry rather than aborting a non-existent local controller. Keep the embedded `onYield` unchanged.
3. Keep the existing parent-channel-context fields (`agentChannel`, `agentTo`, `agentThreadId`, …) as the source of truth for child-completion delivery — those already work.

A repro is straightforward: any `agents.defaults.agentRuntime.id = "claude-cli"` setup with a parent agent that spawns at least one subagent and then calls `sessions_yield`. The error path is hit on every MCP `tools/call` for `sessions_yield`, regardless of channel.

## Side note

The file paths above use this build's hashed dist filenames (`*-BMnDC-w0.js`, `*-DL4MPaGt.js`, `*-D7Zj4hDN.js`, `*-BUaWXl8U.js`). Hashes rotate per build; the source-tree paths (`src/gateway/tool-resolution.ts`, `src/agents/tools/sessions-yield-tool.ts`, `src/agents/pi-embedded-runner/run/attempt.ts`, `src/gateway/mcp-http.loopback-runtime.ts`) and function names (`resolveGatewayScopedTools`, `createSessionsYieldTool`, `runEmbeddedAttempt`) are stable.

Impact and severity

Affected: All users with agentRuntime.id = "claude-cli" (any Claude CLI subscription billing setup)
Severity: Blocks workflow — multi-agent coordination via sessions_yield is completely non-functional
Frequency: Always — 100% reproduction rate
Consequence: Subagents cannot report results back to parent agent; multi-step reasoning chains broken

Additional information

Last known good: unknown. Regression: 5.3-1 changelog claims sessions_yield fix but fix only landed in embedded runner path, not MCP/gateway path. See architectural note in evidence section for fix direction.

Activity

  1. clawsweeper commented on May 4, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 14, 2026, 3:09 PM ET / 19:09 UTC.

    Summary
    Keep open: current main and v2026.6.6 still lack the MCP/CLI loopback session/yield context required by sessions_yield, and the issue is already paired with an open closing PR that has not merged.

    Reproducibility: yes. source-level. Current main constructs gateway/MCP tools without the sessionId and onYield fields that sessions_yield requires, so a loopback call reaches the documented No session context error path.

    Next step
    Do not queue a separate ClawSweeper repair job while an open closing PR already targets this issue.

    Review details

    Best possible solution:

    Refresh, review, and land #90861 or an equivalent narrow fix that threads run session/yield context through the MCP loopback path and preserves yielded lifecycle state.

    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 a loopback call reaches the documented No session context error path.

    Is this the best way to solve the issue?

    Yes, the remaining fix direction is clear: update the gateway/MCP loopback context plumbing and lifecycle handling, preferably by landing the open linked PR after conflicts and maintainer review. Creating a separate automated fix PR now would duplicate that open implementation path.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The linked fix PR is open but currently conflicting, so the issue remains unresolved until a refreshed equivalent lands.
    • No live current-main claude-cli run was executed in this read-only sweep; the reproduction is source-level and matches the reporter’s logs and current code.

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

    Label changes

    Label changes:

    • remove clawsweeper:no-new-fix-pr: Current issue advisory state no longer selects this label.
    • remove clawsweeper:linked-pr-open: Current issue advisory state no longer selects this label.

    Label justifications:

    • P1: The report describes a broken CLI-backed multi-agent sessions_yield workflow that blocks affected users from pausing and resuming parent sessions after subagent work.
    • impact:session-state: The failure is caused by missing run session context and prevents yielded parent-session state from being recorded on the MCP/CLI path.
    Evidence reviewed

    What I checked:

    • Repository policy read: Root AGENTS.md and scoped gateway/agents/tool AGENTS.md files were read fully; their high-confidence source/history review and session-state guidance affected this decision. (AGENTS.md:1, a189baa4b344)
    • Current main tool contract: sessions_yield returns No session context when constructed without sessionId, and separately requires onYield before it can return yielded. (src/agents/tools/sessions-yield-tool.ts:27, a189baa4b344)
    • Current main gateway omission: resolveGatewayScopedTools calls createOpenClawTools without sessionId or onYield, so loopback-scoped tools cannot satisfy the sessions_yield contract. (src/gateway/tool-resolution.ts:159, a189baa4b344)
    • Current main loopback request context omission: The MCP request context extracts session key and channel headers but has no run sessionId field to forward into gateway tool resolution. (src/gateway/mcp-http.request.ts:356, a189baa4b344)
    • Current main loopback config omission: The injected MCP server config includes session-key and routing headers but no x-openclaw-session-id header for a CLI MCP client to echo back. (src/gateway/mcp-http.loopback-runtime.ts:42, a189baa4b344)
    • Embedded runner sibling works differently: The embedded runner path wires an onYield callback that marks yield detection and aborts the local model loop, confirming the reported missing sibling behavior is specific to the gateway/MCP path. (src/agents/embedded-agent-runner/run/attempt.ts:1312, a189baa4b344)

    Likely related people:

    • jriff: Authored the merged sessions_yield feature PR that added the tool contract and embedded-runner yield behavior this issue compares against. (role: introduced behavior context; confidence: high; commits: 3fa91cd69d5d; files: src/agents/tools/sessions-yield-tool.ts, src/agents/openclaw-tools.ts, src/agents/embedded-agent-runner/run/attempt.ts)
    • jalehman: Merged the original sessions_yield PR and authored commits in that PR tightening yield timing and payload-hook behavior. (role: merger and adjacent contributor; confidence: high; commits: 3fa91cd69d5d, 05512341176d, 9903cc87c0b2; files: src/agents/embedded-agent-runner/run/attempt.ts, src/agents/tools/sessions-yield-tool.ts)
    • Peter Steinberger: Recent subagent lifecycle stabilization touched session/subagent lifecycle paths adjacent to yielded completion behavior. (role: recent adjacent contributor; confidence: medium; commits: d6bb36730b50; files: src/agents/subagent-announce.ts, src/agents/subagent-registry-run-manager.ts, src/utils/delivery-context.ts)
    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.
  2. openclaw-barnacle commented on May 31, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  3. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    on Jun 14, 2026
  4. vincentkoc commented on Jun 16, 2026

    @vincentkoc
    Member

    Fixed on main by PR #90861.

    Landed as five preserved commits (rebase merge, no squash), ending at 2b05bd7b0d9a10ab6b0e3d78433263520efd4afd. The fix routes CLI-backed MCP sessions_yield through the existing generation-bound capture owner, propagates paused/end-turn metadata, and avoids stale cached yield callbacks.

    Proof: production loopback HTTP call returned HTTP 200 with status: yielded; 372 focused tests passed; AWS Crabbox check:changed, exact-head CI/security/CodeQL, and final autoreview all passed.

  5. locked as resolved and limited conversation to collaborators on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.regressionBehavior that previously worked and now failsstaleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions