Repository navigation
fix(agents): cap tool results at LLM boundary - #92613
TurboTheTurtle wants to merge 2 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 15, 2026, 2:37 PM ET / 18:37 UTC. Summary PR surface: Source +179, Tests +100. Total +279 across 2 files. Reproducibility: yes. at source level: current main has no Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the boundary guard after maintainer re-review accepts the latest-batch retention policy, ideally with one focused provider-payload conversion check for a pruned long history. Do we have a high-confidence way to reproduce the issue? Yes at source level: current main has no Is this the best way to solve the issue? Yes as a boundary-layer mitigation if maintainers accept the policy: it runs immediately before provider conversion and leaves persisted history untouched. The safer alternative is a provider-payload check or provider-specific cap if a hard limit is required. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c40db057da33. Label changesLabel justifications:
Evidence reviewedPR surface: Source +179, Tests +100. Total +279 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
vincentkoc
left a comment
There was a problem hiding this comment.
Thanks for the focused fix. I found one blocker that makes this unsafe to land as-is.
Blocking finding:
- The new cap keeps the last 24
toolResultmessages globally. If the most recent assistant turn emits 25 parallel tool calls, the boundary drops the first current-batch result and the matching assistant tool call before the continuation LLM call. That means the model proceeds without seeing output for a tool it just requested.
Why this matters:
- The boundary should trim old replay context, not silently remove current tool outputs from the active/recent assistant tool-call batch.
- A safe shape likely needs to preserve all results for the latest assistant tool-call batch, then prune older completed batches or hand off to compaction/summarization.
Verification I ran before stopping:
node_modules/.bin/oxfmt --check src/agents/embedded-agent-runner/run/attempt.llm-boundary.ts src/agents/embedded-agent-runner/run/attempt.llm-boundary.test.tsnode scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt.llm-boundary.test.ts src/agents/embedded-agent-runner/run/attempt.llm-boundary.cache-stability.test.ts- Maintainer autoreview found the active-batch regression after several smaller replay-shape edge cases.
|
Closing this rather than landing it. The 24-result policy is not supported by the reported evidence or a provider contract, and the branch can introduce the same class of malformed replay it is meant to prevent. What I verified:
Concrete blocker on this head:
The original Anthropic failure may still be real, but the count-threshold hypothesis is not proven and this patch is not the best fix. A useful follow-up needs the exact sanitized |
Summary
toolResultmessages so histories with 25+ completed tool results do not cross the model boundary intact.Closes #92315.
Duplicate PR check
gh pr list --repo openclaw/openclaw --state open --search "92315" --json number,title,url,headRefName,authorreturned no open PRs.tool-result-truncation.*; this PR is a count-based LLM-boundary replay guard inattempt.llm-boundary.*.Real behavior proof
toolResultmessages through the LLM boundary, because that can produce an invalid provider request schema. The boundary should keep the newest tool-result context and avoid dangling assistant tool calls.a local OpenClaw checkout, branchcodex/92315-tool-result-history, running the actualnormalizeMessagesForLlmBoundaryimplementation withnode --import tsx.node --import tsxprobe that importedsrc/agents/embedded-agent-runner/run/attempt.llm-boundary.ts, built 30 completed assistant tool-call /toolResultpairs with public synthetic output, passed them throughnormalizeMessagesForLlmBoundary, and printed sanitized boundary metrics.{ "status": "ok", "setup": "OpenClaw source LLM boundary normalizer", "inputToolResults": 30, "outputToolResults": 24, "firstOutputToolResult": "call_6", "lastOutputToolResult": "call_29", "assistantToolCalls": 24, "noDanglingAssistantToolCalls": true, "oldestToolResultDropped": true, "newestToolResultKept": true }call_29), dropping the oldest result (call_0), and preserving tool-call/result pairing for all assistant tool calls that remained.Proof
pnpm exec oxfmt --check --threads=1 src/agents/embedded-agent-runner/run/attempt.llm-boundary.ts src/agents/embedded-agent-runner/run/attempt.llm-boundary.test.ts git diff --check pnpm tsgo:test:src node scripts/run-vitest.mjs run --config test/vitest/vitest.unit-fast.config.ts src/agents/embedded-agent-runner/run/attempt.llm-boundary.test.ts src/agents/embedded-agent-runner/run/attempt.llm-boundary.cache-stability.test.ts node scripts/test-projects.mjs src/agents/embedded-agent-runner/run/attempt.llm-boundary.test.ts src/agents/embedded-agent-runner/run/attempt.llm-boundary.cache-stability.test.tsRisk