Repository navigation
fix(cli): agent --json waits for a yielded turn's follow-up through the Gateway - #208755
Merged
Merged
Conversation
…he Gateway The Gateway route returned at sessions_yield with an empty success while the subagents still worked. --json now shares text mode's wait, writes the turn's response once the session resumes, and writes the standard failure envelope when the follow-up fails or the wait ends early.
Contributor
|
🦞👀 ClawSweeper review endedClawSweeper stopped reviewing this revision because the pull request closed. |
Collaborator
Author
|
Landed as 531c797. Bug: Gateway |
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 30, 2026
…he Gateway (openclaw#208755) ## What Problem This Solves `openclaw agent --json` through the Gateway returns too early when the agent hands work to a subagent and yields (`sessions_yield`). The CLI prints the yielding turn's envelope (`status: "ok"`, `result.payloads: []`, `result.meta.yielded: true`, `result.requesterContinuationSettled: true`) and exits 0 before the subagent reports and the session resumes. A script, CI job or orchestrator then tears down or moves on while the real work is still pending. Text mode already waits (openclaw#207491), and `--local --json` waits too. Reproduced on main (be5d7c6) through a real isolated Gateway and a scripted model: the turn spawns one child and yields, the child answers after 8 s. | route | exit | time | resumed turn | |---|---|---|---| | Gateway `agent --json` | 0 | 8 s | reaches the model after the CLI exits | | Gateway `agent` (text) | 0 | 24 s | before exit | | `agent --local --json` | 0 | 23 s | before exit; prints the yielding turn's envelope | ## Solution `--json` now uses the same wait as text mode: the existing `createYieldFollower` in `src/commands/agent-gateway-reply.ts`. The two `json ||` early returns are gone. - `--json` writes one document after the follow-up settles: the yielding turn's response, with today's fields. That is the same timing as text mode and `--local --json`. - If the follow-up fails or is aborted, or the wait ends early (explicit `--timeout` or a dropped connection), `--json` writes the documented `ok: false` failure envelope (with `runId` and `origin: "gateway"`) instead of an empty success, prints the same stderr line as text mode, and exits 1. - `SIGINT`/`SIGTERM` during the wait keep the documented signal exit status (130/143) and write nothing to stdout, like any interrupted run: the CLI's signal exit owner exits before the command returns. Text mode behaves the same on main. Not a success, so no empty-success case remains. - No new field, flag, timer, RPC or second envelope. No change to `sessions_yield`. The follow-up's reply text is not added to the `--json` document. The resumed turn is a separate Gateway run, and its full envelope (`result.meta`, `deliveryStatus`) reaches only the in-process announce caller; nothing on the CLI connection supplies it. Putting it on stdout needs a Gateway protocol decision and is out of scope here. The reply is in the session, as with `--local --json` today. ## Bounds - The CLI adds no deadline. The wait ends on the follow-up's terminal `chat` event, an explicit `--timeout` (text-mode rule from openclaw#207491), a signal or connection loss. - Without `--timeout`, the follow-up run gets the Gateway's resolved run deadline (`resolveAgentTimeoutMs`, `agent-turn-source-admission.ts:250`). - Accepted edge, inherited from text mode and not changed here: a native subagent spawned without `runTimeoutSeconds` has no run deadline by default (`agents.defaults.subagents.runTimeoutSeconds`, 0 = no timeout, documented in `docs/tools/subagents/tool-reference.md`). Such a child, or a settle wake the Gateway loses while it stays up, keeps a `--json` wait without `--timeout` open until a signal or disconnect. Bounding that from the CLI would need either a CLI-side deadline (a second owner, which openclaw#208522 removed) or a Gateway-supplied deadline (protocol). A child with a deadline is bounded: in the repro, a child with `runTimeoutSeconds: 10` timed out, the session resumed, and the CLI exited. ## User Impact - `openclaw agent --json` against a Gateway returns after the resumed turn settles, with exit 0, or exits nonzero with the standard failure envelope when the follow-up fails or the wait ends early. It never returns an empty success at the yield. - Text mode and `--local` are unchanged. ## Evidence - Red on main, green here: `src/commands/agent-via-gateway.yield.test.ts`. The three `--json` cases (reply, failed follow-up, aborted follow-up) fail on main (the CLI stopped waiting before the follow-up) and pass here. The other `agent-via-gateway*` and agent CLI suites pass. - Real CLI and Gateway: new case in `test/e2e/agent-route-parity.built-cli.e2e.test.ts`. A scripted model spawns one child and yields; the child answers once the CLI exits or after 3 s. Main dist: the CLI exits before the resumed turn (red). This branch's dist: the resumed turn runs while the CLI waits, stdout is one JSON document with `result.meta.yielded: true`, exit 0 (green). - Real CLI and Gateway, scripted model, isolated state, this branch's dist: - spawn, yield, child answers in 8 s: `agent --json` exits 0 at 16 s, after the resumed turn's model call (main: exit 0 at 8 s, before it); - Gateway stopped during the wait: exit 1, stdout is `{"ok": false, "runId": "…", "origin": "gateway", "error": {"type": "cli_error", "message": "Stopped waiting for the subagents. Their result will still be added to session agent:main:main."}}`, the same line on stderr; - `SIGTERM` during the wait: exit 143, empty stdout (no truncated document; nothing is written on that path). - Docs: `docs/cli/agent.md` notes, `docs/tools/agent-send.md`. Co-authored-by: Ayaan Zaidi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
openclaw agent --jsonthrough the Gateway returns too early when the agent hands work to a subagent and yields (sessions_yield). The CLI prints the yielding turn's envelope (status: "ok",result.payloads: [],result.meta.yielded: true,result.requesterContinuationSettled: true) and exits 0 before the subagent reports and the session resumes. A script, CI job or orchestrator then tears down or moves on while the real work is still pending. Text mode already waits (#207491), and--local --jsonwaits too.Reproduced on main (9389d99) through a real isolated Gateway and a scripted model: the turn spawns one child and yields, the child answers after 8 s.
agent --jsonagent(text)agent --local --jsonSolution
--jsonnow uses the same wait as text mode: the existingcreateYieldFollowerinsrc/commands/agent-gateway-reply.ts. The twojson ||early returns are gone.--jsonwrites one document after the follow-up settles: the yielding turn's response, with today's fields. That is the same timing as text mode and--local --json.--timeoutor a dropped connection),--jsonwrites the documentedok: falsefailure envelope (withrunIdandorigin: "gateway") instead of an empty success, prints the same stderr line as text mode, and exits 1.SIGINT/SIGTERMduring the wait keep the documented signal exit status (130/143) and write nothing to stdout, like any interrupted run: the CLI's signal exit owner exits before the command returns. Text mode behaves the same on main. Not a success, so no empty-success case remains.sessions_yield.The follow-up's reply text is not added to the
--jsondocument. The resumed turn is a separate Gateway run, and its full envelope (result.meta,deliveryStatus) reaches only the in-process announce caller; nothing on the CLI connection supplies it. Putting it on stdout needs a Gateway protocol decision and is out of scope here. The reply is in the session, as with--local --jsontoday.Bounds
chatevent, an explicit--timeout(text-mode rule from fix: show a yielded agent turn's acknowledgment and its subagents' reply in the CLI #207491), a signal or connection loss.--timeout, the follow-up run gets the Gateway's resolved run deadline (resolveAgentTimeoutMs,agent-turn-source-admission.ts:250).runTimeoutSecondshas no run deadline by default (agents.defaults.subagents.runTimeoutSeconds, 0 = no timeout, documented indocs/tools/subagents/tool-reference.md). Such a child, or a settle wake the Gateway loses while it stays up, keeps a--jsonwait without--timeoutopen until a signal or disconnect. Bounding that from the CLI would need either a CLI-side deadline (a second owner, which fix(cli): one run deadline for openclaw agent on both routes #208522 removed) or a Gateway-supplied deadline (protocol). A child with a deadline is bounded: in the repro, a child withrunTimeoutSeconds: 10timed out, the session resumed, and the CLI exited.User Impact
openclaw agent --jsonagainst a Gateway returns after the resumed turn settles, with exit 0, or exits nonzero with the standard failure envelope when the follow-up fails or the wait ends early. It never returns an empty success at the yield.--localare unchanged.Evidence
src/commands/agent-via-gateway.yield.test.ts. The three--jsoncases (reply, failed follow-up, aborted follow-up) fail on main (the CLI stopped waiting before the follow-up) and pass here. The otheragent-via-gateway*and agent CLI suites pass.test/e2e/agent-route-parity.built-cli.e2e.test.ts. A scripted model spawns one child and yields; the child answers once the CLI exits or after 3 s. Main dist: the CLI exits before the resumed turn (red). This branch's dist: the resumed turn runs while the CLI waits, stdout is one JSON document withresult.meta.yielded: true, exit 0 (green).agent --jsonexits 0 at 16 s, after the resumed turn's model call (main: exit 0 at 8 s, before it);{"ok": false, "runId": "…", "origin": "gateway", "error": {"type": "cli_error", "message": "Stopped waiting for the subagents. Their result will still be added to session agent:main:main."}}, the same line on stderr;SIGTERMduring the wait: exit 143, empty stdout (no truncated document; nothing is written on that path).docs/cli/agent.mdnotes,docs/tools/agent-send.md.