Skip to content

fix(agents): disclose 64 KiB code-mode stderr-tail truncation - #130182

Merged
steipete merged 2 commits into
openclaw:mainfrom
Finn763:fix/issue-128967-stderr-tail-disclosure
Aug 29, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
Finn763:fix/issue-128967-stderr-tail-disclosure

Conversation

@Finn763

@Finn763 Finn763 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Partially addresses #128967 for Tool Search's tool_search_code child. Find/grep retention disclosure remains separate work under that issue; this PR must not close it.

A failed child could lose diagnostics arriving after exit, silently discard earlier stderr at the retention cap, and then silently shorten the retained text again for display. A real child probe also found that failure could return while an already-started bridged tool remained alive.

What Changed

The shared bounded-tail helper returns retained text and discarded UTF-8 bytes. All internal callers use that one API; the tracked-helper wrapper and Tool Search test facade are removed. Find/grep keep their existing display behavior.

Node's close event owns failed-exit rendering after stdio drains. The existing 250 ms clean-exit IPC grace remains unchanged; IPC results, spawn/stream errors, abort, and timeout retain prompt settlement. The error distinguishes retention-cap loss from bytes omitted from the trimmed 500-character preview.

The common settlement boundary now aborts outstanding bridge work for every terminal outcome, including fatal exits and successful final results with unfinished calls. It preserves the parent's cancellation reason and timeout error. No per-call controller registry or new timeout is introduced.

Production +48/-44 (net +4); tests/support +272/-140; documentation +5. No config option, dependency, storage schema, or native Codex/QuickJS behavior changes. This is the separate permission-restricted Node Tool Search bridge.

Thanks @Finn763 for the original repair and lifecycle cases. The maintainer rewrite preserves contributor credit and simplifies the owner boundary against current main.

Evidence

  • Eleven regression cases failed on the original implementation. All 197 focused tests now pass across the stream lifecycle, complete Tool Search suite, shared UTF-8 tail accounting, find, and grep.
  • Real public Tool Search control, real scoped catalog, and real permission-restricted Node child: successful IPC control returns {proof:7}; fatal child failure now cancels an already-started host tool exactly once before fixture cleanup. Before the repair, the outer failure returned with that tool unfinished and its signal un-aborted. The timeout positive control also passes.
  • Deterministic event-order tests prove late stderr is included after nonzero exit, clean-exit late IPC still succeeds, result-less clean exit still expires, and abort/timeout remain prompt while waiting for close. Multi-chunk/multibyte tests prove byte conservation.
  • Directly checked Node's documented exit versus close contract. On this Mac, Node's fatal reporter can itself stop writing after 65,536 bytes; that sender-side loss is not counted as parent retention loss. The isolated Linux owner-path proof received 70,355 bytes and exactly reported 4,819 discarded at retention plus 65,035 omitted from the trimmed preview. A read-only child-process observer independently counted received chunks; source hashes matched this candidate. Larger probes also matched the bytes actually received, without claiming sender-discarded bytes. Linux proof run; the Testbox command and timing result passed and the owned lease was stopped.
  • Fresh independent Codex autoreview is clean. The complete changed-file gate passed; exact-head CI passed on the reviewed commit.

Node child-process close contract.

Hosted CI initially timed out fetching the comparison base in check-guards (exit124 after120 seconds), after the duplication and coercion checks passed. The unchanged exact head passed on the retry; no guard or timeout was weakened. The PR evidence-check heading was also corrected.

@Finn763

Finn763 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Split from #128997 per the second-round ruling (issuecomment-5404301364): this PR marks the previously unmarked 64 KiB code-mode stderr-tail truncation (src/agents/sessions/tools/limits.ts helper) with a retention-loss disclosure in the exit error message, without changing the tail retention policy. Regression tests were red before the fix and green after (limits.test.ts 17/17, tool-search.stream-errors.test.ts 4/4, tool-search.test.ts 136/136).

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Aug 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 6:59 PM ET / 22:59 UTC.

ClawSweeper review

What this changes

The PR reports the exact number of stderr bytes discarded from Code Mode’s 64 KiB retained tail when a child process exits unsuccessfully.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking defect was found in the current PR head: it records loss at the bounded-tail owner, waits for stderr drain before rendering non-clean failures, and retains the clean-exit IPC grace. Keep this PR open for normal merge validation; the local partial clone could not load the current-main tree for a three-way comparison because its promisor remote could not resolve GitHub.

Priority: P2
Reviewed head: 292c38efc58fcab5ca44c74d85e7af1e37d09da4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused lifecycle coverage and reported real owner-path output support a normal good-quality rating, subject to the unavailable current-main comparison.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR’s latest stated owner-boundary evidence invokes the edited runCodeModeChild path with a real spawned child and reports exact retained and discarded stderr totals after the fix.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR’s latest stated owner-boundary evidence invokes the edited runCodeModeChild path with a real spawned child and reports exact retained and discarded stderr totals after the fix.
Evidence reviewed 7 items Owner-boundary implementation: The child stderr listener accumulates the UTF-8-safe retained tail and discarded-byte total; the single failure renderer adds the notice only after the relevant stream lifecycle condition.
Canonical bounded-tail accounting: The shared helper derives discarded bytes from the exact UTF-8 byte difference while preserving the existing string-returning wrapper used by find and grep.
Sibling consumers remain on their prior contract: Find and grep still call the original string-returning tail helper, so this PR scopes disclosure accounting to the Code Mode failure surface rather than changing all stderr consumers.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/tool-search.stream-errors.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130182-xxQ5ee/target

 ✓  agents-core  src/agents/tool-search.stream-errors.test.ts (8 tests) 10062ms

 Test Files  1 passed (1)
      Tests  8 passed (8)
   Start at  23:00:35
   Duration  11.39s (transform 8.87s, setup 941ms, import 48ms, tests 10.06s, environment 0ms)

[test] passed 1 Vitest shard in 17.07s
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130182-xxQ5ee/target

 ✓  agents-core  src/agents/tool-search.stream-errors.test.ts (8 tests) 4792ms

 Test Files  1 passed (1)
      Tests  8 passed (8)
   Start at  23:00:53
   Duration  5.47s (transform 3.01s, setup 440ms, import 21ms, tests 4.79s, environment 0ms)

[test] passed 1 Vitest shard in 11.10s

Assertions:

  • NOT OBSERVED expect_output: Test Files 1 passed — command exited successfully; expected output was not observed in the captured pane

How this fits together

Tool Search gives OpenClaw agents a compact tool catalog and runs tool_search_code in an isolated Node child process. Its stderr is retained as a bounded diagnostic tail, then rendered into a failure returned to the agent when the child cannot complete.

flowchart LR
A[Agent tool request] --> B[Tool Search]
B --> C[Isolated Node child]
C --> D[Stderr stream]
D --> E[Bounded tail accounting]
C --> F[Exit or IPC result]
E --> G[Failure rendering]
F --> G
G --> H[Agent-visible result]
Loading

Before merge

  • Resolve merge risk (P1) - The repair adds 79 net production lines to a timing-sensitive child-process failure path; the added accounting and ordered-lifecycle coverage provide a concrete justification, but current-main integration could not be inspected locally.
  • Complete next step (P2) - No repair job is warranted because no concrete head defect was found; refresh the current-main/mergeability check before landing.
Agent review details

Security

None.

PR surface

Source +82, Tests +301. Total +383 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 106 24 +82
Tests 3 304 3 +301
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 410 27 +383

Review metrics

Metric Value Why it matters
Production versus test delta production +79, tests/test-support +304 The production growth implements exact byte accounting plus ordered failure rendering; focused tests cover the new byte and event-order invariants.

Stored data model

Persistent data-model change detected: serialized state: src/agents/sessions/tools/limits.ts, unknown-data-model-change: src/agents/sessions/tools/limits.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128967
Summary: This PR is a candidate fix for the Code Mode portion of the canonical retention-loss report; the shared find/grep path remains separate work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep loss accounting at the bounded-tail helper and render one disclosure at the Code Mode failure owner, then verify the exact head against an inspectable current-main merge result before landing.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep loss accounting at the bounded-tail helper and render one disclosure at the Code Mode failure owner, then verify the exact head against an inspectable current-main merge result before landing.

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

No high-confidence current-main reproduction was run: the source path and focused regression tests establish the failing event order, but the local partial clone could not load the current-main tree.

Is this the best way to solve the issue?

Yes for the Code Mode path: the patch records loss at its producer and renders it once after stderr drains while leaving find and grep unchanged.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR’s latest stated owner-boundary evidence invokes the edited runCodeModeChild path with a real spawned child and reports exact retained and discarded stderr totals after the fix.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR’s latest stated owner-boundary evidence invokes the edited runCodeModeChild path with a real spawned child and reports exact retained and discarded stderr totals after the fix.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded diagnostic-loss repair in an experimental agent Tool Search path, with limited user blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR’s latest stated owner-boundary evidence invokes the edited runCodeModeChild path with a real spawned child and reports exact retained and discarded stderr totals after the fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR’s latest stated owner-boundary evidence invokes the edited runCodeModeChild path with a real spawned child and reports exact retained and discarded stderr totals after the fix.

Evidence

What I checked:

  • Owner-boundary implementation: The child stderr listener accumulates the UTF-8-safe retained tail and discarded-byte total; the single failure renderer adds the notice only after the relevant stream lifecycle condition. (src/agents/tool-search-code-mode.ts:179, 292c38efc58f)
  • Canonical bounded-tail accounting: The shared helper derives discarded bytes from the exact UTF-8 byte difference while preserving the existing string-returning wrapper used by find and grep. (src/agents/sessions/tools/limits.ts:31, 292c38efc58f)
  • Sibling consumers remain on their prior contract: Find and grep still call the original string-returning tail helper, so this PR scopes disclosure accounting to the Code Mode failure surface rather than changing all stderr consumers. (src/agents/sessions/tools/find.ts:311, 292c38efc58f)
  • Lifecycle regressions: Focused tests cover oversized loss disclosure, data arriving after exit but before stderr close, both clean-exit/late-IPC orderings, and clean-exit grace expiry. (src/agents/tool-search.stream-errors.test.ts:184, 292c38efc58f)
  • Node child-process contract: Directly inspected Node child-process declarations define distinct exit, close, error, and message events; the implementation’s stream-drain ordering is covered by the focused regression scenarios.
  • Implementation boundary: Tool Search documentation explicitly distinguishes this isolated OpenClaw Node subprocess from Codex-native Tool Search and Code Mode, so the sibling Codex runtime gate is not applicable. Public docs: docs/tools/tool-search.md. (docs/tools/tool-search.md:10, 292c38efc58f)

Likely related people:

  • Peter Steinberger: The PR base revision is an agents change authored by Peter Steinberger; file-specific history could not be completed from this partial clone. (role: recent agents-area contributor; confidence: low; commits: f07ac003b837; files: src/agents/tool-search-code-mode.ts, src/agents/sessions/tools/limits.ts)

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 (5 earlier review cycles)
  • reviewed 2026-08-26T15:01:12.776Z sha 2785a84 :: needs real behavior proof before merge. :: [P2] Wait for stderr close before rendering the failure
  • reviewed 2026-08-26T17:17:51.719Z sha da6a547 :: needs real behavior proof before merge. :: [P2] Keep the zero-exit IPC grace when stderr closes
  • reviewed 2026-08-26T18:35:11.996Z sha 292c38e :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-26T18:55:40.585Z sha 292c38e :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-26T22:11:29.389Z sha 292c38e :: needs real behavior proof before merge. :: none

@Finn763

Finn763 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 26, 2026
@Finn763

Finn763 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Round-5 [P2] addressed at head 292c38e (commit fix(agents): preserve the zero-exit IPC grace across stderr close):

  • stderr close-triggered finalization now returns early on a clean exit; only nonzero/signaled exits finalize on close. A shared isCleanExit predicate keeps both call sites aligned.
  • Clean exits keep their existing outcome path unchanged: the sole race breaker remains the 250 ms grace timer armed at exit. Late IPC results after exit->close deliver normally in both orderings (exit->close->result and close->exit->result).
  • Result-less children remain covered: the third new regression case pins that a clean exit with no IPC result still rejects with "exited with 0" after grace expiry.

PR description updated with a matching "Round-5 follow-up" Evidence subsection documenting all of this.

Verification run at exactly this head just now:

  • node scripts/run-vitest.mjs src/agents/tool-search.stream-errors.test.ts -> Test Files 2 passed, Tests 16 passed (includes the 3 new cases).
  • src/agents/sessions/tools/limits.test.ts + find/grep stream-error files -> Tests 39 passed.
  • src/agents/tool-search.test.ts family -> Tests 272 passed.
  • pnpm exec oxfmt --check and pnpm exec oxlint on the two touched files: clean.

On the real-behavior proof ask: the standing real-child evidence (Evidence section) already proves byte-exact 64 KiB accounting against a live spawned child, including event-order disclosure. Extending it to observe exit->close->late-IPC-result delivery live requires driving runCodeModeChild's runtime/IPC worker bridge standalone, which is the same constraint documented in the body; we attempted no partial substitute there and did not want to overstate coverage — happy to attempt it if you consider it necessary beyond the unit regressions pinning the ordering deterministically.

CI on this fresh head was still reporting at post time.

@Finn763

Finn763 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Round-7 real owner-boundary evidence (runCodeModeChild invocation with a real spawned Node child, 70,414 B stderr → 65,536 B retained tail + 4,878 B exact disclosed, non-zero exit) was added to the PR body at 22:08:19Z — one second after the last auto-review snapshot was taken. Re-requesting review so the fresh snapshot includes it.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 26, 2026
@steipete steipete self-assigned this Aug 29, 2026
Record retention loss at the shared bounded-tail owner and render failed
child diagnostics after Node closes its stdio. Preserve the clean-exit IPC
grace and disclose the separately bounded display preview. End outstanding
bridge work at the common settlement boundary, including fatal exits.

Co-authored-by: Finn763 <[email protected]>
@steipete
steipete force-pushed the fix/issue-128967-stderr-tail-disclosure branch from 292c38e to b96f14a Compare August 29, 2026 04:45
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 29, 2026
@steipete

Copy link
Copy Markdown
Contributor

Maintainer refresh at b96f14a: simplified the existing repair against current main, preserving @Finn763's co-author credit. One bounded-tail API replaces the wrapper pair; Node close owns stderr drain; retention and display-preview losses are separately disclosed. A connected real-child reproduction also proved orphaned bridge work after fatal failure, now canceled at the shared settlement boundary. Eleven before-fix failures became 197 passing tests; actual fatal/timeout owner probes pass. No persistence schema changed. The PR body distinguishes the Mac reporter's sender-side loss from the remaining Linux overflow probe.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 29, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 29, 2026
@steipete
steipete merged commit 027df17 into openclaw:main Aug 29, 2026
488 of 493 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
…aw#130182)

* fix: preserve child stderr diagnostics and cancel settled bridge work

Record retention loss at the shared bounded-tail owner and render failed
child diagnostics after Node closes its stdio. Preserve the clean-exit IPC
grace and disclose the separately bounded display preview. End outstanding
bridge work at the common settlement boundary, including fatal exits.

Co-authored-by: Finn763 <[email protected]>

* test: align child lifecycle regressions with lint rules

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

2 participants