Skip to content

fix(tools): release terminal summaries after nested calls settle - #135398

Merged
steipete merged 3 commits into
mainfrom
codex/perf2-terminal-presentation
Sep 1, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/perf2-terminal-presentation

Conversation

@steipete

@steipete steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a completed tool could fail while recording its terminal summary when private execution arguments could not be cloned. Completed nested Tool Search calls also retained their terminal observer, keeping run state reachable after settlement. Cancellation could finish cleanup before a slow tool returned and registered more retained state.

Why This Change Was Made

Prepare terminal formatting once, snapshot arguments only when a formatter needs them, and retain only the observer metadata required to clear an older summary for plain tools. Publish after raw observation succeeds; consume the record at Tool Search's final result-acceptance boundary; prevent late publication after abort. Raw outcome recording, middleware results, redaction, text bounds and model-call ordering remain intact.

User Impact

Plain tools complete successfully with private uncloneable arguments, and completed or cancelled nested calls release terminal presentation state. Later plain or failed calls clear older summaries without an out-of-order completion restoring stale text.

Evidence

  • Before the fix, the real wrapper regression threw DataCloneError after tool execution. The candidate passes all 75 before-tool-call integration cases.
  • Four new Tool Search owner cases fail before the lifecycle repair and pass afterward: direct completion and at-most-once finalization; accepted replacement result; rejection after raw success; and a cancellation-ignoring late source. The complete Tool Search suite passes 148 tests, including after rebase onto current main. All 162 native Codex dynamic-tool checks pass; 68 embedded terminal/middleware checks also pass.
  • Actual-owner retention proof shows a synthetic observer capture remaining reachable after completed Tool Search and catalog disposal before the fix, and becoming collectable afterward. Late explicit finalization becomes a no-op. The cancellation proof preserves the late raw observation while eliminating the late pending record.
  • In a separate controlled 256-call plain-tool workload, cloned argument snapshots fall from 256 to zero and median retained heap falls from 33,670,928 to 78,112 bytes across three processes. This probe stubs logging/redaction/text truncation and is not a whole-Gateway measurement.
  • Typed lint, isolated Codex autoreview and the full source build pass.
  • Two isolated dev Gateways on this exact build each passed real OpenAI turns with openai/gpt-5.6-luna: the embedded runtime executed an HTTP-200 web_fetch followed by a successful file read within one Code Mode call; native Codex executed the same two tools directly. Durable history verifies the selected runtime, paired results, execution order and final response marker. Both Gateways exited cleanly. An earlier probe supplied an ambiguous test-file location and failed; it is excluded, and the successful probes specify the exact synthetic path.

Production: +93/-80, net +13 lines. Tests: +265/-18, net +247. The additional production lines establish the missing success/error/cancellation cleanup boundary; the obsolete unconditional snapshot and executable-tool retention paths are removed. No public protocol, configuration, dependency or persistence surface changes.

CI follow-up: hosted typechecking caught a missing required details field on the empty error-cleanup result. The field is now explicit; core typechecking and all 148 Tool Search tests pass after the correction. It is ignored on the error branch and does not change terminal behavior. Fresh exact-head CI is required.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 1, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 7:37 PM ET / 23:37 UTC.

ClawSweeper review

What this changes

The branch separates terminal-summary formatting from retained Tool Search state so nested calls publish their final accepted result, failures clear stale summaries, and cancelled late completions do not retain observers.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. This maintainer-authored PR repairs a source-confirmed tool-lifecycle defect with focused owner-boundary coverage; it is not merged or subsumed by the fetched main commit, while exact-head CI is still incomplete.

Priority: P2
Reviewed head: b9f7069b311a51644a01754d3ae01d5b9324e10b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with targeted lifecycle coverage; fresh exact-head CI remains the remaining merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; source review confirms focused owner-boundary tests, while this read-only review did not execute the claimed runtime evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; source review confirms focused owner-boundary tests, while this read-only review did not execute the claimed runtime evidence.
Evidence reviewed 5 items Base defect and proposed owner repair: The PR-base implementation retained every observed tool's executable tool object and unconditionally cloned its final execution parameters; the proposed preparation path retains only observer/name/formatter state and skips cloning when no formatter exists.
Final acceptance boundary: Tool Search now finalizes the pending presentation in its finally block after result validation and acceptance, sending an error-clearing presentation when no accepted result exists.
Focused lifecycle coverage: New owner tests cover direct finalization, executor-replaced results, rejection after raw success, and a cancellation-ignoring source; the integration test covers uncloneable plain-tool execution parameters.
Findings None None.
Security None None.

How this fits together

Agent tools emit raw outcome observations while executing, and Tool Search may accept, replace, or reject those results before presenting the settled outcome. This change keeps terminal summaries aligned with that final acceptance boundary and releases retained per-call state.

flowchart LR
  A[Agent tool call] --> B[Before-call wrapper]
  B --> C[Raw outcome observation]
  C --> D[Tool Search result acceptance]
  D --> E[Terminal-summary finalizer]
  E --> F[Observer presentation]
  D --> G[Cancelled or failed cleanup]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI is still incomplete, so the required-check outcome for b9f7069 is not yet established.
  • Resolve merge risk (P1) - Production code is net +13 lines; the added finalization boundary appears justified by replacing retained executable-tool state, but maintainers should retain that scope rather than add further lifecycle branches.
  • Complete next step (P2) - No mechanical repair is identified; a maintainer should review the fresh exact-head CI result and then make the normal merge decision.
Agent review details

Security

None.

PR surface

Source +13, Tests +255. Total +268 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 93 80 +13
Tests 2 273 18 +255
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 366 98 +268

Review metrics

Metric Value Why it matters
Production versus test delta production +93/-80 (net +13); tests +273/-18 (net +255) The small production increase centralizes final-result cleanup while the larger test delta covers success, rejection, and cancellation ordering.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused lifecycle repair after the exact-head required checks pass, keeping final summary publication solely at Tool Search result acceptance.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the focused lifecycle repair after the exact-head required checks pass, keeping final summary publication solely at Tool Search result acceptance.

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

Yes—source establishes that the base path unconditionally clones observed plain-tool execution parameters after successful execution; the added integration case supplies the private callback shape that makes this fail.

Is this the best way to solve the issue?

Yes. Deferring only the presentation projection and storing it at the Tool Search acceptance owner fixes success, replacement, failure, and cancellation without changing tool, configuration, protocol, or persistence contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded agent-tool lifecycle bug that can leave stale terminal summaries or retained per-call state, without evidence of a broader outage or security impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; source review confirms focused owner-boundary tests, while this read-only review did not execute the claimed runtime evidence.

Evidence

What I checked:

  • Base defect and proposed owner repair: The PR-base implementation retained every observed tool's executable tool object and unconditionally cloned its final execution parameters; the proposed preparation path retains only observer/name/formatter state and skips cloning when no formatter exists. (src/agents/agent-tools.before-tool-call.diagnostics.ts:77, b9f7069b311a)
  • Final acceptance boundary: Tool Search now finalizes the pending presentation in its finally block after result validation and acceptance, sending an error-clearing presentation when no accepted result exists. (src/agents/tool-search-runtime.ts:675, b9f7069b311a)
  • Focused lifecycle coverage: New owner tests cover direct finalization, executor-replaced results, rejection after raw success, and a cancellation-ignoring source; the integration test covers uncloneable plain-tool execution parameters. (src/agents/tool-search.test.ts:1472, b9f7069b311a)
  • Codex runtime contract inspected: The sibling Codex checkout has a local cache origin, so its repository ownership cannot be verified here. Its app-server test shows custom-tool output is submitted by call ID after a completed turn, and its protocol defines item completion as a lifecycle notification; this supports treating OpenClaw's final accepted result as the summary boundary. (codex-rs/app-server/tests/suite/v2/code_mode_host.rs:94, 78c290807ce710180111df227df3b7a4fe845452)
  • History and current-main status: The main behavior dates to the PR commit; the preceding diagnostics work on this path is commit 9830acc. The PR head is not an ancestor of fetched main 50f7f06, so it has not already landed. (src/agents/agent-tools.before-tool-call.diagnostics.ts:62, 423a14eed3fb)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Obtain a fresh green required CI result for b9f7069.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-01T18:54:57.698Z sha 6a8b45b :: needs maintainer review before merge. :: none
  • reviewed 2026-09-01T22:15:03.314Z sha 71f61fe :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/perf2-terminal-presentation branch from 6a8b45b to 71f61fe Compare September 1, 2026 21:47
Prepare isolated formatter inputs only for tools that use them. Plain tools
retain only the observer metadata needed to clear older terminal summaries,
so private uncloneable execution parameters cannot fail completed calls.

Consume nested Tool Search presentations after final result acceptance and
prevent late publication after cancellation. Preserve raw outcome recording,
result middleware, formatter bounds and model-call ordinal ordering.
@steipete
steipete force-pushed the codex/perf2-terminal-presentation branch from 71f61fe to b9f7069 Compare September 1, 2026 23:32
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Fresh retained-memory proof for the unchanged implementation on this head: the probe loads 29 hashed production modules and exercises 256 calls with distinct 128-KiB payloads. The compared owner code is from eee230d0 and 71f61fe3; the latest rebase preserves the candidate patch.

Actual-owner workload Before: post-GC heap growth After: post-GC heap growth
Pending plain-tool arguments 33,628,496 B 29,832 B
Completed calls with observer captures 33,987,416 B 298,104 B

These are the matched snapshot-instrumented pair. Two further pairs without snapshots are recorded separately and show the same release behavior. The snapshots trace 256 payload strings through the real pending-presentation map before the repair and zero afterward: 33,558,528 bytes of aggregate string self-size, not dominator retained size. Explicit baseline cleanup releases those strings too, confirming the lifetime owner. Unnecessary terminal argument clones fall from 256 to zero; all 256 required replay clones remain.

Four lifecycle controls fail before and pass after: accepted-result replacement, rejection after raw success, late completion after abort, and private uncloneable plain-tool arguments. All 12 successful probe children exit and their private state is removed. A separate reviewer checked the raw measurements, snapshot nodes, representative retainer edges, source/compiled hashes, paired outcomes and cleanup. The initial probe setup failure is retained and excluded.

This deliberately amplified synthetic owner workload uses explicit fixtures at unrelated boundaries. It does not measure ordinary per-session memory, whole-Gateway RSS or vendor execution. The earlier real embedded/native OpenAI web/read evidence remains separate.

The ClawSweeper rank-up request is satisfied: exact-head CI passed for b9f7069b311a51644a01754d3ae01d5b9324e10b. Production remains +13 lines: the added acceptance/abort ownership is needed to prevent late publication and release captures; no further lifecycle branches were added.

@steipete
steipete merged commit 9eb3250 into main Sep 1, 2026
269 checks passed
@steipete
steipete deleted the codex/perf2-terminal-presentation branch September 1, 2026 23:58
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
…nclaw#135398)

* fix(agents): release terminal presentation state with tool calls

Prepare isolated formatter inputs only for tools that use them. Plain tools
retain only the observer metadata needed to clear older terminal summaries,
so private uncloneable execution parameters cannot fail completed calls.

Consume nested Tool Search presentations after final result acceptance and
prevent late publication after cancellation. Preserve raw outcome recording,
result middleware, formatter bounds and model-call ordinal ordering.

* fix(agents): complete rejected tool cleanup result

* test: use complete catalog tool execution signature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

1 participant