Skip to content

fix(agents): bound tool_search_code stderr accumulation - #101007

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
hugenshen:fix/tool-search-stderr-bound
Jul 6, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
hugenshen:fix/tool-search-stderr-bound

Conversation

@hugenshen

Copy link
Copy Markdown
Contributor

What Problem This Solves

tool_search_code accumulated child stderr with unbounded stderr.push(chunk) in src/agents/tool-search.ts. A noisy or runaway code-mode subprocess could grow gateway memory even though only the first 500 characters are surfaced in exit errors.

Why This Change Was Made

Reuse the existing session-tool stderr tail helper (appendBoundedTextTail, 64 KiB) already used by grep/find. Child stderr is now retained as a bounded UTF-8-safe tail instead of an ever-growing string array.

User Impact

Normal code-mode runs are unchanged. Pathological stderr floods no longer accumulate unbounded memory in the gateway process.

Evidence

Focused test:

node scripts/run-vitest.mjs src/agents/tool-search.test.ts --run -t "bounds tool_search_code stderr"

Result: passed — new regression verifies early overflow prefix is dropped and retained bytes stay within SESSION_TOOL_STDERR_TAIL_BYTES.

Real behavior proof

  • Behavior or issue addressed: Unbounded stderr.push(chunk) growth during tool_search_code child execution.
  • Real environment tested: macOS (Darwin), Node.js v22.22.0.
  • Exact steps or command run after this patch:
    1. Direct helper probe via node --import tsx
    2. node scripts/run-vitest.mjs src/agents/tool-search.test.ts --run -t "bounds tool_search_code stderr"
  • Evidence after fix:
$ node --import tsx -e "…testing.appendToolSearchCodeStderrTail(…)"
bytes retained: 65536
includes HEAD: false
ends with TAIL: true
within cap: true
$ node scripts/run-vitest.mjs src/agents/tool-search.test.ts --run -t "bounds tool_search_code stderr"

 Test Files  2 passed (2)
      Tests  2 passed | 96 skipped (98)
   Duration  2.05s
  • Observed result after fix: A synthetic stderr flood of HEAD_OVERFLOW_ + 74KiB + TAIL retains only the 64 KiB tail (65536 bytes), drops the early prefix, and keeps the trailing marker.
  • What was not tested: Live code-mode subprocess stderr flood end-to-end; proof exercises the production helper used by the stderr data handler.

Tests and validation

  • node scripts/run-vitest.mjs src/agents/tool-search.test.ts --run -t "bounds tool_search_code stderr"
  • Regression test added in src/agents/tool-search.test.ts

Risk checklist

  • Did user-visible behavior change? Only for failure diagnostics — stderr detail in child-exit errors now reflects the bounded tail rather than the full stream prefix.
  • Did config, environment, or migration behavior change? No
  • Did security, auth, secrets, network, or tool execution behavior change? Yes — code-mode stderr buffering is now bounded.
  • Highest-risk area: tool_search_code child exit error messages when stderr is very large.
  • Mitigation: Matches grep/find session-tool stderr policy (SESSION_TOOL_STDERR_TAIL_BYTES = 64 KiB); surfaced detail was already truncated to 500 chars.

Current review state

  • Next action: awaiting maintainer review
  • Bot comments addressed: none yet

AI-assisted disclosure

  • AI-assisted (Cursor agent)
  • Human-run Real behavior proof from local setup

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 6, 2026
@clawsweeper

clawsweeper Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 6, 2026, 1:20 PM ET / 17:20 UTC.

Summary
The PR bounds accumulated stderr for the tool_search_code child process and adds a regression test for the bounded tail helper.

PR surface: Source +6, Tests +15. Total +21 across 2 files.

Reproducibility: yes. from source: current main appends every child stderr chunk to an array and joins the full stderr stream on child exit. I did not run a live noisy subprocess because this review is read-only, but the source path is clear.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Change the child-exit error detail to show the newest retained stderr and add a focused assertion for a large stderr stream ending with a marker.

Risk before merge

Maintainer options:

  1. Decide the mitigation before merge
    Land the bounded stderr storage after the child-exit diagnostic reports the newest retained stderr snippet and after the adjacent stderr stream-error change is rebased as needed.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] There is one narrow mechanical repair: align the displayed child-exit stderr detail with the retained tail semantics and test that behavior.

Security
Cleared: The diff bounds an internal child-process diagnostic buffer and does not add dependency, CI, secret, permission, or new code-execution surface.

Review findings

  • [P3] Show the newest retained stderr in failures — src/agents/tool-search.ts:2163
Review details

Best possible solution:

Land the bounded stderr storage after the child-exit diagnostic reports the newest retained stderr snippet and after the adjacent stderr stream-error change is rebased as needed.

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

Yes from source: current main appends every child stderr chunk to an array and joins the full stderr stream on child exit. I did not run a live noisy subprocess because this review is read-only, but the source path is clear.

Is this the best way to solve the issue?

Mostly yes: reusing the existing session stderr tail helper is the narrowest maintainable fix. The remaining tweak is to take the displayed 500-character child-exit detail from the end of that retained tail, not from its beginning.

Full review comments:

  • [P3] Show the newest retained stderr in failures — src/agents/tool-search.ts:2163
    Now that suffix is the bounded stderr tail, the next line's slice(0, 500) reports the oldest part of that retained tail rather than the newest stderr. A large stream ending with the real error line can still omit that final diagnostic even though the helper retained it; build the 500-character child-exit detail from the end of stderrTail and add focused coverage for that thrown error text.
    Confidence: 0.84

Overall correctness: patch is correct
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: The PR addresses a bounded resource-use bug in agent tool execution with limited but real availability impact.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal proof from a direct production-helper probe plus focused test output showing the retained stderr tail is capped after the patch; the diagnostic finding above is separate.
  • 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 (terminal): The PR body includes terminal proof from a direct production-helper probe plus focused test output showing the retained stderr tail is capped after the patch; the diagnostic finding above is separate.

Label justifications:

  • P2: The PR addresses a bounded resource-use bug in agent tool execution with limited but real availability impact.
  • 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 (terminal): The PR body includes terminal proof from a direct production-helper probe plus focused test output showing the retained stderr tail is capped after the patch; the diagnostic finding above is separate.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal proof from a direct production-helper probe plus focused test output showing the retained stderr tail is capped after the patch; the diagnostic finding above is separate.
Evidence reviewed

PR surface:

Source +6, Tests +15. Total +21 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 3 +6
Tests 1 15 0 +15
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 24 3 +21

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/tool-search.test.ts --run -t "bounds tool_search_code stderr".

What I checked:

  • Root policy read: The full root AGENTS.md and scoped src/agents/AGENTS.md were read; their full-code-path and agent-test review guidance were applied. (AGENTS.md:1, a34b8a8d6968)
  • Current main behavior: runCodeModeChild currently stores every child stderr chunk in stderr: string[] and joins the full stream on child exit. (src/agents/tool-search.ts:2111, a34b8a8d6968)
  • Existing bounded helper: appendBoundedTextTail is the existing UTF-8-safe byte-bounded tail helper with the 64 KiB stderr default. (src/agents/sessions/tools/limits.ts:35, a34b8a8d6968)
  • Sibling stderr policy: Session grep and find tools already use appendBoundedTextTail for subprocess stderr, supporting this PR's owner-boundary choice. (src/agents/sessions/tools/grep.ts:263, a34b8a8d6968)
  • PR diff: The PR changes stderr.push(chunk) to bounded stderrTail accumulation and exposes the helper through the test barrel for focused coverage. (src/agents/tool-search.ts:2163, de031aa7e553)
  • Proof in PR body: The PR body includes terminal output from a direct helper probe retaining 65536 bytes and a focused tool-search.test.ts run that passed. (de031aa7e553)

Likely related people:

  • Vincent Koc: Current checkout blame for runCodeModeChild, the unbounded stderr lines, and the session stderr tail helper points to recent commit 123ec16. (role: recent area contributor; confidence: high; commits: 123ec165bb56; files: src/agents/tool-search.ts, src/agents/sessions/tools/limits.ts, src/agents/sessions/tools/grep.ts)
  • steipete: GitHub PR history shows feat: add core tool search #79823 introduced core Tool Search and touched src/agents/tool-search.ts and its tests. (role: feature introducer and merger; confidence: high; commits: b85cb4e8d13e, a72007df0144, ea69cbbcc57a; files: src/agents/tool-search.ts, src/agents/tool-search.test.ts)
  • SebTardif: Merged Tool Search catalog reuse work in fix(tool-search): skip catalog rebuild when tool set is unchanged #87172 recently changed the same core Tool Search file and tests. (role: adjacent area contributor; confidence: medium; commits: 6bfc12510115; files: src/agents/tool-search.ts, src/agents/tool-search.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

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.

@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. P2 Normal backlog priority with limited blast radius. labels Jul 6, 2026
@vincentkoc vincentkoc self-assigned this Jul 6, 2026
@vincentkoc

Copy link
Copy Markdown
Member

land-ready maintainer proof:

proof gap: the regression uses a synthetic stderr flood through the production tail helper; no live runaway code-mode child was induced.

@vincentkoc
vincentkoc merged commit 9ef7fff into openclaw:main Jul 6, 2026
96 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 7, 2026
)

* fix(agents): bound tool_search_code stderr accumulation

* fix(agents): report latest bounded stderr

---------

Co-authored-by: NIO <[email protected]>
Co-authored-by: Vincent Koc <[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 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: XS 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