Repository navigation
fix(agents): Astra answer lost when sessions_yield waits on its own async tools - #166876
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 11:37 PM ET / October 8, 2026, 03:37 UTC (Revision 7). ClawSweeper reviewWhat this changesThe branch keeps sessions_yield synchronous on eligible Astra requests and carries the optional async opt-out through session and worker tool definitions. Example: A user requests a Splitwise checklist while Astra checks two files.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains necessary and has no outstanding review blocker. The recorded, verified maintainer acceptance resolves the previous API-direction concern, and the before/after Telegram evidence demonstrates the repaired answer delivery. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherOpenClaw’s built-in agent runtime sends tool definitions to the model provider and returns tool results on continuation. This change lets its wait tool pause Astra generation so the final answer can incorporate those results before channel delivery. flowchart TD
A[User request] --> B[Agent tool definitions]
B --> C[Session and worker projections]
C --> D[Astra request preparation]
D --> E[Other tools run asynchronously]
D --> F[Yield pauses generation]
E --> G[Continuation receives results]
F --> G
G --> H[Complete answer delivered]
Technical reviewBest possible solution: Keep the accepted provider-scoped opt-out at the shared request owner while preserving yield deferral and existing execution behavior elsewhere. Do we have a high-confidence way to reproduce the issue? Yes: current-main source still advertises the wait tool as async, and the supplied baseline Telegram run shows the resulting checklist loss. This review established the current source mechanism without executing target code. Is this the best way to solve the issue? Yes: the repair follows the provider’s synchronous wait-tool contract at the shared request owner, preserves existing yield safeguards, and carries metadata through the affected projections; its public scope has been accepted. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f0fff3ce7b88. Provenance checked
TestingProof path: shipped entry point. Added test files: 2. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +17, Tests +36, Docs +13. Total +66 across 12 files. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (6 earlier review cycles)
|
b434927 to
08acaf0
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Maintainer decision on the API direction: @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…sync tools (openclaw#166876) ## What Problem This Solves Fixes: with GPT-6 Astra async tools, the model's real answer was lost when it called `sessions_yield` to wait for its own parallel tool results. Telegram received only a short follow-up "supplement", never the answer itself. On our setup (Telegram forum topic, `openai/gpt-6-astra`, built-in runtime), one response ran `memory_search`, `exec` and `read` in parallel. It then wrote commentary plus `sessions_yield` ("Await source rows exec + memory recall + planning ref read"), and then, still in the same response, a 2,967-character `final_answer` checklist. The model wrote that checklist before seeing any tool result. A second model call (no new user input) saw the results and wrote a 332-character note: "One additional booking to check…". Only the note was sent. ## User Impact When Astra waits for its own async tool results with `sessions_yield`, the response now really pauses. The model sees the results first and writes one complete answer. There are no new messages, notices or settings. ## Why This Change Was Made The model's wait tool was not allowed to wait. - openclaw#138046 (`8995a7eeac9`) added Astra async tools and marks **every** function tool `async: true` (`openai-responses-client.ts`, `prepareRequest`), including `sessions_yield`. OpenAI's [async tool guide](https://developers.openai.com/api/docs/guides/async-tool-calling#add-a-wait-tool) says a wait tool must be an ordinary synchronous function: a sync call pauses the response, and the next request delivers the async results before the wait status. Because `sessions_yield` was async, Astra kept generating after the yield and answered without the results. - The `sessions_yield` deferral (`hasUnobservedAsyncToolResults`, from openclaw#146667 `6293548dcd5`, reworded as `deferred` in openclaw#149983 `5f070d3ee30`) was **not** spurious. The results were already in the transcript, but async results only reach the model in the next request, so the model had not seen them. The gate correctly keeps the yield from ending the turn. Its old text ("Finish this response to receive them") could never help, because the model only reads it in that next request. The fix, at the owners: - `Tool.async?: false` (llm-core) lets a tool opt out of async calls. The Responses transport keeps such tools synchronous and still marks every other function tool async. The two session tool projections that pick fields (`projectAgentToolDefinition`, `wrapToolDefinition`) carry the flag next to `executionMode`. The closed worker tool-surface schema (`WorkerToolSurfaceSchema`) accepts it, so worker-environment turns that carry `sessions_yield` still start. - `sessions_yield` sets `async: false`. Its deferral now says what is true for a synchronous yield: the earlier results arrive with this result. - `async: false` is documented as a supported tool property in `docs/plugins/tool-plugins.md`, next to `executionMode`, `hideFromChannelProgress` and `catalogMode`. Plugins can already reach it through `api.registerTool`. Other providers, Code Mode and Tool Search catalog calls are unchanged. Maintainer decision (API direction): `async: false` is accepted as a supported, additive tool property. Scope: it keeps a directly visible function tool synchronous on GPT-6 Astra async-tool requests. Other providers, Code Mode and Tool Search catalog calls are unchanged. We chose this over a private carrier because the field is already reachable through `api.registerTool`, and a second private path (a transport option listing synchronous tool names) would add more code across agent-core stream options and the worker native runtime. Kept from earlier decisions: the deferral gate and its non-error `deferred` status (openclaw#146667, openclaw#149983), and async execution for every other direct tool (openclaw#138046). Code Mode and non-Astra routes are untouched. Not changed: other ways the model might wait, such as `process` polling. Boundaries a `sessions_yield` definition crosses on its way to an Astra async-tool request: the local and sub-agent session projections (both carry the flag), the shared `prepareRequest` (used by SSE, WebSocket, steering continuation, and compaction or retry rebuilds), and the worker tool surface (schema fixed here; the worker side spreads the definition). The native worker runtime passes `context.tools` through unchanged. Gateway-placed worker inference copies only name, description and parameters, but that path never enables async tool execution, so no tool is async there. Ordinary local turns do not cross the worker surface; its only producer is `src/gateway/worker-environments/worker-turn-execution.ts:358`. ## Evidence **Regressions** - `packages/ai/src/transports/openai-responses-client.continuation.test.ts`: the real `createSessionsYieldTool` and a plain tool go through the real session projections (`toToolDefinitions` → `wrapToolDefinition`) into the real Responses transport for `gpt-6-astra` with async tools on. The test asserts `exec` is sent `async: true` and `sessions_yield` is not. With the transport fix reverted it **fails** (`sessions_yield` is sent with `"async": true`). On this branch it passes (47 tests). - `src/gateway/worker-environments/worker-gateway-tool-runtime.test.ts`: the gateway issues the real `sessions_yield` through `getSurface`, and the surface must validate and keep `async: false`. With the schema line reverted it **fails** with `Worker tool surface is invalid` (the round-1 review blocker: worker turns could not start). - Also green on the final code: `prepared-tool-surface`, `agent-tool-definition-adapter*`, `tool-definition-wrapper`, `worker.runtime`, `worker-gateway-tools`, `worker-turn-rpc`, `sessions-yield-tool` (11 files, 230 tests), `pnpm tsgo:core`, `pnpm tsgo:core:test`, oxfmt/oxlint on changed files, `docs:check-links`, `docs:check-mdx`, `git diff --check`. **Live: Telegram Test Server with real `gpt-6-astra`.** Each run used its own forum topic and an isolated gateway on built `dist` (state under `/tmp`). The config matches our setup: the official `https://api.openai.com/v1` endpoint (async tools on), built-in runtime, code mode off, tool search on, `streaming.progress` with tool progress and commentary, thinking `low`. After the round-1 fix the build was `08acaf0afac`, which has the same code as this head (only `docs/plugins/tool-plugins.md` changed since). Message ids are the userbot's. Incident shape (a). Same prompt both sides: a rough card list, then "start both checks together: cat card-export.csv with exec and open trip-notes.md with the read tool, and call sessions_yield to wait for them. Don't hold the checklist for the files: right after the sessions_yield call, write the dated checklist from my list; when the results arrive, add only what they change." The files hold two facts the list lacks: the hotel was personal, and one dinner was split four ways. | | `origin/main` `a2ab6c2cf57` | this PR (`08acaf0afac` build) | | --- | --- | --- | | `sessions_yield` call | `async: true`, `deferred` | synchronous, `deferred` ("arrive with this result") | | Response 1 after the yield | kept generating a 416-token "**Provisional Splitwise checklist**" `final_answer` before any result arrived | ends at the yield call (`toolUse`) | | Response 2 | "Two corrections from the files: …" | the full checklist plus "File-check changes: Hotel: exclude … Jalan Alor: four ways, ₹1,102.50 each …" | | Model requests | 2 | 2 | | Bot messages (userbot view) | 1: msg 39, "Two corrections from the files: …". **The checklist never arrived.** | 1: msg 90, "Splitwise checklist — 8 October 2026 / From your rough list … File-check changes … Final shared total: ₹88,944 …" | Both sides also posted a progress draft (`Working / Exec / Read…`), which was deleted when the answer landed. Sibling runs on the same build: | Case | Model path | Bot messages (userbot) | | --- | --- | --- | | (b) sub-agent: `sessions_spawn` → `sessions_yield` → completion | yield `deferred`, then `yielded`; the completion wake writes the answer | msg 43 once: "Dev skipped the Jalan Alor dinner. The ₹4,410 bill is split four ways: … ₹1,102.50 …"; draft deleted | | (c) background `exec` (`sleep 30; echo BG-…-done`) with completion wake | exec background; yield `deferred`, then `nothing_pending`; short waiting reply; the exit wake writes the output | msg 97 "Running in the background. I'll report its exact output when it finishes.", then msg 98 "BG-5C861F-done" once | | (e) plain single-tool turn ("read trip-notes.md, who skipped the dinner?") | `read` (async), then a synchronous yield `deferred`; one answer | msg 99 "Dev skipped the Jalan Alor dinner." once; draft deleted | | (d) `NO_REPLY` on a direct user request | model says `NO_REPLY`; the required-reply retry asks for a visible answer | msg 69 "Noted for this thread." **Same on `origin/main`** (`a2ab6c2cf57`): msg 95 "Noted for this thread." | On (d): every live `NO_REPLY` shape we tried reached a reply contract that requires visible text, and this PR changes none of that code. A direct user request in a group is a required-reply turn. After a yield, the requester's completion wake must produce a visible final ("A yield owes the conversation a visible final unless private findings let the requester choose silence", `subagent-announce.requester-settle-state.ts:170-172`). The three completion-wake runs showed the same retry (`empty response detected … visible-answer continuation`). Ambient room events never reached the model. The user-request case matches `origin/main` exactly. (f) worker-placed turn: our setup has no worker environments, so ordinary turns never cross the worker surface. The worker regression above covers it. LOC vs `origin/main`: production +19/−2 (7 files), tests +36, docs +18/−5. ## Bounded cost - Runtime: one `Set` built from the request's tool list, only on Astra async-tool requests. No new requests, timers, state, settings or messages. A yield that waits for async results no longer produces a blind answer, so the incident case saves one wasted answer of about 400 output tokens. - Live proof spend: about $8.56 of `gpt-6-astra` across 20 Telegram Test Server runs. That is $3.59 for exploration and the first before/after pair, and $4.97 for the final-head siblings and the `origin/main` `NO_REPLY` baseline. Figures are summed from transcript usage costs, including sub-agents. Every run-owned forum topic has been deleted. Co-authored-by: Ayaan Zaidi <[email protected]>
Backport the branch-relevant #166876 tool contract required by the extended-stable harness recovery fixtures and regenerate the branch prompt snapshots. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes: with GPT-6 Astra async tools, the model's real answer was lost when it called
sessions_yieldto wait for its own parallel tool results. Telegram received only a short follow-up "supplement", never the answer itself.On our setup (Telegram forum topic,
openai/gpt-6-astra, built-in runtime), one response ranmemory_search,execandreadin parallel. It then wrote commentary plussessions_yield("Await source rows exec + memory recall + planning ref read"), and then, still in the same response, a 2,967-characterfinal_answerchecklist. The model wrote that checklist before seeing any tool result. A second model call (no new user input) saw the results and wrote a 332-character note: "One additional booking to check…". Only the note was sent.User Impact
When Astra waits for its own async tool results with
sessions_yield, the response now really pauses. The model sees the results first and writes one complete answer. There are no new messages, notices or settings.Why This Change Was Made
The model's wait tool was not allowed to wait.
a637374e435) added Astra async tools and marks every function toolasync: true(openai-responses-client.ts,prepareRequest), includingsessions_yield. OpenAI's async tool guide says a wait tool must be an ordinary synchronous function: a sync call pauses the response, and the next request delivers the async results before the wait status. Becausesessions_yieldwas async, Astra kept generating after the yield and answered without the results.sessions_yielddeferral (hasUnobservedAsyncToolResults, from fix(agents): recover yielded subagents and preserve sidebar nesting #1466672f663805b4c, reworded asdeferredin fix(agents): report deferred sessions_yield as a normal outcome #149983e252366ffe2) was not spurious. The results were already in the transcript, but async results only reach the model in the next request, so the model had not seen them. The gate correctly keeps the yield from ending the turn. Its old text ("Finish this response to receive them") could never help, because the model only reads it in that next request.The fix, at the owners:
Tool.async?: false(llm-core) lets a tool opt out of async calls. The Responses transport keeps such tools synchronous and still marks every other function tool async. The two session tool projections that pick fields (projectAgentToolDefinition,wrapToolDefinition) carry the flag next toexecutionMode. The closed worker tool-surface schema (WorkerToolSurfaceSchema) accepts it, so worker-environment turns that carrysessions_yieldstill start.sessions_yieldsetsasync: false. Its deferral now says what is true for a synchronous yield: the earlier results arrive with this result.async: falseis documented as a supported tool property indocs/plugins/tool-plugins.md, next toexecutionMode,hideFromChannelProgressandcatalogMode. Plugins can already reach it throughapi.registerTool. Other providers, Code Mode and Tool Search catalog calls are unchanged.Maintainer decision (API direction):
async: falseis accepted as a supported, additive tool property. Scope: it keeps a directly visible function tool synchronous on GPT-6 Astra async-tool requests. Other providers, Code Mode and Tool Search catalog calls are unchanged. We chose this over a private carrier because the field is already reachable throughapi.registerTool, and a second private path (a transport option listing synchronous tool names) would add more code across agent-core stream options and the worker native runtime.Kept from earlier decisions: the deferral gate and its non-error
deferredstatus (#146667, #149983), and async execution for every other direct tool (#138046). Code Mode and non-Astra routes are untouched. Not changed: other ways the model might wait, such asprocesspolling.Boundaries a
sessions_yielddefinition crosses on its way to an Astra async-tool request: the local and sub-agent session projections (both carry the flag), the sharedprepareRequest(used by SSE, WebSocket, steering continuation, and compaction or retry rebuilds), and the worker tool surface (schema fixed here; the worker side spreads the definition). The native worker runtime passescontext.toolsthrough unchanged. Gateway-placed worker inference copies only name, description and parameters, but that path never enables async tool execution, so no tool is async there. Ordinary local turns do not cross the worker surface; its only producer issrc/gateway/worker-environments/worker-turn-execution.ts:358.Evidence
Regressions
packages/ai/src/transports/openai-responses-client.continuation.test.ts: the realcreateSessionsYieldTooland a plain tool go through the real session projections (toToolDefinitions→wrapToolDefinition) into the real Responses transport forgpt-6-astrawith async tools on. The test assertsexecis sentasync: trueandsessions_yieldis not. With the transport fix reverted it fails (sessions_yieldis sent with"async": true). On this branch it passes (47 tests).src/gateway/worker-environments/worker-gateway-tool-runtime.test.ts: the gateway issues the realsessions_yieldthroughgetSurface, and the surface must validate and keepasync: false. With the schema line reverted it fails withWorker tool surface is invalid(the round-1 review blocker: worker turns could not start).prepared-tool-surface,agent-tool-definition-adapter*,tool-definition-wrapper,worker.runtime,worker-gateway-tools,worker-turn-rpc,sessions-yield-tool(11 files, 230 tests),pnpm tsgo:core,pnpm tsgo:core:test, oxfmt/oxlint on changed files,docs:check-links,docs:check-mdx,git diff --check.Live: Telegram Test Server with real
gpt-6-astra. Each run used its own forum topic and an isolated gateway on builtdist(state under/tmp). The config matches our setup: the officialhttps://api.openai.com/v1endpoint (async tools on), built-in runtime, code mode off, tool search on,streaming.progresswith tool progress and commentary, thinkinglow. After the round-1 fix the build was08acaf0afac, which has the same code as this head (onlydocs/plugins/tool-plugins.mdchanged since). Message ids are the userbot's.Incident shape (a). Same prompt both sides: a rough card list, then "start both checks together: cat card-export.csv with exec and open trip-notes.md with the read tool, and call sessions_yield to wait for them. Don't hold the checklist for the files: right after the sessions_yield call, write the dated checklist from my list; when the results arrive, add only what they change." The files hold two facts the list lacks: the hotel was personal, and one dinner was split four ways.
origin/mainc73c99d9e0308acaf0afacbuild)sessions_yieldcallasync: true,deferreddeferred("arrive with this result")final_answerbefore any result arrivedtoolUse)Both sides also posted a progress draft (
Working / Exec / Read…), which was deleted when the answer landed.Sibling runs on the same build:
sessions_spawn→sessions_yield→ completiondeferred, thenyielded; the completion wake writes the answerexec(sleep 30; echo BG-…-done) with completion wakedeferred, thennothing_pending; short waiting reply; the exit wake writes the outputread(async), then a synchronous yielddeferred; one answerNO_REPLYon a direct user requestNO_REPLY; the required-reply retry asks for a visible answerorigin/main(c73c99d9e03): msg 95 "Noted for this thread."On (d): every live
NO_REPLYshape we tried reached a reply contract that requires visible text, and this PR changes none of that code. A direct user request in a group is a required-reply turn. After a yield, the requester's completion wake must produce a visible final ("A yield owes the conversation a visible final unless private findings let the requester choose silence",subagent-announce.requester-settle-state.ts:170-172). The three completion-wake runs showed the same retry (empty response detected … visible-answer continuation). Ambient room events never reached the model. The user-request case matchesorigin/mainexactly.(f) worker-placed turn: our setup has no worker environments, so ordinary turns never cross the worker surface. The worker regression above covers it.
LOC vs
origin/main: production +19/−2 (7 files), tests +36, docs +18/−5.Bounded cost
Setbuilt from the request's tool list, only on Astra async-tool requests. No new requests, timers, state, settings or messages. A yield that waits for async results no longer produces a blind answer, so the incident case saves one wasted answer of about 400 output tokens.gpt-6-astraacross 20 Telegram Test Server runs. That is $3.59 for exploration and the first before/after pair, and $4.97 for the final-head siblings and theorigin/mainNO_REPLYbaseline. Figures are summed from transcript usage costs, including sub-agents. Every run-owned forum topic has been deleted.