Skip to content

fix(agents): compact on predicted overflow instead of trimming tool results the provider already cached - #199530

Merged
roboclaw-bot merged 4 commits into
mainfrom
fix/prompt-cache-tool-result-projection
Nov 19, 2026
Merged

roboclaw-bot merged 4 commits into
mainfrom
fix/prompt-cache-tool-result-projection

Conversation

@obviyus

@obviyus obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

On a production gateway over 36 hours, one signature caused 14 warm prompt-cache breaks (about 3.1M cached tokens lost), all on openai-responses:

  • [prompt-cache] message N (toolResult) differs from the previous request; history must be append-only; changed fields: content[0].text, with N an early message (3, 16, 17, 27).
  • cache read dropped ~250k -> ~19-23k (the system prompt only) on request=1 of a new run, systemPromptSeries=pinned, request gap 0.8-5.6 s.
  • Some sessions broke on 3 consecutive runs a few minutes apart.

All 14 breaks follow, within 20 s, a [context-overflow-midturn-precheck] route=truncate_tool_results_only handled=true truncatedCount=N line and a [tool-result-truncation] Truncated N tool result(s) in session (... aggregate=N) line for the same session. The sessions were near their context window (260k on that route) and had no compaction in between.

Root cause

  • When the pre-request pressure check (resolveCompactionPressureDecision, run/preemptive-compaction.ts) predicts an overflow, it chooses truncate_tool_results_only if trimming tool results could recover 1.5x the overflow. It counts every tool result in history, including results that earlier requests already sent in full.
  • handleEmbeddedAttemptMidTurnPrecheck (run/attempt-prompt-preflight.ts) then calls truncateOversizedToolResultsInSessionManager. That rewrites the transcript in recovery mode, which ignores the frozen projection state, and trims the oldest results down to the aggregate tool-result budget.
  • These results are already in the provider's cached prefix. Their text changes, so the cache restarts after the system prompt. This rebuild is not one of the allowed points (/new, /reset, compaction, model or provider switch) in docs/reference/prompt-caching.md.
  • The trim removes only enough to fit. The next run adds new results, crosses the window again, and trims again. One break follows another.
  • Recovery mode was designed for a prompt the provider already rejected. A predicted overflow is not a rejection: the provider accepted every byte so far.
  • The prompt-time projection (truncateOversizedToolResultsInMessages with its frozen projection state) already keeps sent results byte-stable. It is not part of this break. The difference comes from the session rewrite above.

Fix

  • buildToolResultReplacementPlan (tool-result-truncation.ts) gets preserveSentToolResults. Results before the last assistant message are already sent, and the plan does not touch them. Only the unconsumed tail (results the provider has not received) can still be capped.
  • The pressure decision counts only that unsent reduction. When sent history causes the overflow, the route becomes compact_only or compact_then_truncate. Compaction is an allowed rebuild point, and it frees enough space that the following runs append again.
  • The mid-turn handler passes the same option to the session rewrite, so a predicted overflow cannot rewrite sent bytes through that path either.
  • Recovery after a real provider rejection is unchanged. It still truncates all results when compaction cannot help, because the rejected prefix cannot be reused anyway. Sessions with compaction disabled therefore keep their previous fallback.

Proof

Real route (isolated throwaway Gateway, direct OpenAI Responses, openai/gpt-6.1-sol, serviceTier: ultrafast = 260k window, server compaction threshold set to the window). One session: runs of three exec calls (~60k chars each) until the next run starts above the window.

main (d9a5437) this branch
pressure decision at the crossing request route=truncate_tool_results_only toolResultReducibleChars=364430 route=compact_only toolResultReducibleChars=0
what happened session rewrite refused (Pending input relocation does not match its admitted transcript entry), fallback to compaction compaction
provider cache reads, whole session (41-42 requests) 4,671,788 4,707,588
requests with 0 cached tokens 4 4
  • On main, the trim was attempted on already-sent results, as in production. In this local harness the transcript rewrite is refused by the pending-input custody check for the turn's user message, so main also ends in compaction, and cache reads are the same. In production the rewrite succeeds in most cases (12 of 15 attempts in the same logs), and that is the break above.
  • Limit: I could not make main's rewrite succeed on a real route, so this PR does not include a provider-measured before/after cache difference for the break itself. The production numbers above are the evidence for its cost. The PR stays a draft until a real-route before/after exists or a maintainer accepts this evidence.

Prefix-stability journey (test/prompt-cache-prefix-stability.test-support.ts, both routes): a new step sends 14 large exec results (past the aggregate budget), then 4 parallel results with the provider reporting the session just under the proactive threshold. This puts the next request past the window. The journey now allows breaks only at compactions and requires that this step compacts. A debug probe on main showed that this step reaches route=truncate_tool_results_only. On main the journey still passes, because the trim falls back to compaction as above. The journey makes sure the outcome stays a compaction.

Focused tests:

  • preemptive-compaction.test.ts: sent results over the aggregate budget with a small overflow now route to compact_only (on main: truncate_tool_results_only; the test fails on main).
  • tool-result-truncation.test.ts: a session rewrite with preserveSentToolResults keeps the sent results byte for byte and still caps the unsent oversized tail.
  • Existing route tests (unsent tails still use truncate_tool_results_only / compact_then_truncate) are unchanged and green.

…esults the provider already cached

The pre-request pressure check counted every tool result as reducible and, on the truncate-only route, rewrote the oldest already-sent results down to the aggregate budget. That changed bytes inside the provider's cached prefix and, because it trimmed only enough to fit, recurred on every run near the window.

Predicted pressure now counts and trims only results the provider has not received (after the last assistant message). Overflow from sent history routes to compaction, an allowed rebuild point. Recovery after a real provider rejection is unchanged.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves previously sent tool results during predicted overflow recovery and routes pressure from that history to compaction.

Example: An isolated OpenAI Responses session crosses its 260,000-token window with large tool results already in history.

  • Before: Main reports truncate_tool_results_only with 364,430 reducible characters and attempts a transcript rewrite before falling back to compaction.
  • After: The branch reports compact_only with zero reducible characters from sent results and compacts directly.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with real-route evidence for the changed decision and targeted boundary tests; the new documentation needs a small qualification.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied isolated-Gateway OpenAI Responses output exercises the changed production pressure owner and records compact_only followed by compaction on the branch; this supports the routing repair, while the refused baseline rewrite leaves cache-savings claims unmeasured.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Long tool sessions repeatedly lose a warm provider cache when predicted-pressure recovery changes earlier tool output.
Reason: The maintainer-authored direction restores the documented prefix contract while retaining existing emergency recovery behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a source-supported prompt-cache defect with a focused repair; no blocking correctness defect was found, and the author's draft hold remains.

Priority: P2
Reviewed head: a3a661e5074de0354bbc0d75c9523096521722ea

Before merge

None.

Findings

  • [P3] Document the retained fallback after failed compaction — docs/reference/prompt-caching.md:664-667
Agent review details

How this fits together

The embedded agent runner estimates outgoing request pressure, selects truncation or compaction, and prepares transcript messages for the provider.

flowchart TD
  A[Session history and pending results] --> B[Request pressure decision]
  B --> C[Shared truncation planner]
  C --> D[Cap unsent oversized results]
  C --> E[Compact sent history]
  D --> F[Provider request]
  E --> F
Loading

Technical review

Best possible solution:

Keep prediction and truncation on the existing shared planner, preserve sent results during direct precheck recovery, and describe the retained failure fallback accurately.

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

Current main counts previously sent tool results as reducible and can rewrite them during predicted-pressure recovery; the reported live comparison confirms that routing, although its baseline rewrite was refused.

Is this the best way to solve the issue?

The repair enforces the sent-history boundary in the existing planner and uses it consistently for estimation and execution, without adding another state owner.

Full review comments:

  • [P3] Document the retained fallback after failed compaction — docs/reference/prompt-caching.md:664-667
    The new statement that sent results are trimmed only after provider rejection is stronger than the implementation. If predicted pressure selects compaction and that compaction fails or is disabled, overflow-context-recovery.ts still reaches truncateToolResults() without preserveSentToolResults and can trim sent history before any rejection. Qualify this paragraph to cover direct precheck truncation and name the retained recovery fallback, which the PR body intentionally preserves.
    Confidence: 0.98

Overall correctness: patch is correct
Overall confidence: 0.89

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b135516219ab.

Provenance checked

  • Cause-aware pressure routing changes intended behavior with a stated reason (66daafc: Choose inexpensive readable tool-result recovery before compaction when estimated recoverable content can cover the overflow.)
  • Shared tool-result replacement planner keeps the original intent (f434873: Plan directly over message positions while retaining truncation budgets, frozen projections, and append-only recovery semantics.)
  • Gateway prefix-stability journey and documentation keeps the original intent (bf0b800: Require provider requests to extend earlier session prefixes except at declared rebuild points.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit bf0b800 adds docs/reference/prompt-caching.md:641 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bf0b8002c2b9; files: docs/reference/prompt-caching.md)
  • Peter Steinberger: Raw commit e0ed68c adds src/agents/embedded-agent-runner/run/preemptive-compaction.ts:329 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e0ed68c7b845; files: src/agents/embedded-agent-runner/run/preemptive-compaction.ts)
  • Tak Hoffman: Raw commit 66daafc adds src/agents/pi-embedded-runner/run/preemptive-compaction.ts:55 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 66daafccae09; files: src/agents/pi-embedded-runner/run/preemptive-compaction.ts)

PR surface

Source +8, Tests +106, Docs +5. Total +119 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 20 12 +8
Tests 3 142 36 +106
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 167 48 +119

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Repeated prompt-cache invalidation near the context window increases processing cost for long tool sessions without establishing an urgent availability regression.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 15, 2026, 3:55 AM ET / 08:55 UTC.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 18, 2026 23:44
@roboclaw-bot
roboclaw-bot enabled auto-merge (squash) November 18, 2026 23:45
@roboclaw-bot
roboclaw-bot merged commit 535f3ea into main Nov 19, 2026
254 of 256 checks passed
@roboclaw-bot
roboclaw-bot deleted the fix/prompt-cache-tool-result-projection branch November 19, 2026 00:01
roboclaw-bot pushed a commit that referenced this pull request Nov 19, 2026
…esults the provider already cached (#199530)

* fix(agents): compact on predicted overflow instead of trimming tool results the provider already cached

The pre-request pressure check counted every tool result as reducible and, on the truncate-only route, rewrote the oldest already-sent results down to the aggregate budget. That changed bytes inside the provider's cached prefix and, because it trimmed only enough to fit, recurred on every run near the window.

Predicted pressure now counts and trims only results the provider has not received (after the last assistant message). Overflow from sent history routes to compaction, an allowed rebuild point. Recovery after a real provider rejection is unchanged.

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

* fix(agents): preserve sent output in all predicted-overflow paths

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

* test(agents): model unsent tool results at the request boundary

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

---------

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>
(cherry picked from commit 535f3ea)
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
…esults the provider already cached (openclaw#199530)

* fix(agents): compact on predicted overflow instead of trimming tool results the provider already cached

The pre-request pressure check counted every tool result as reducible and, on the truncate-only route, rewrote the oldest already-sent results down to the aggregate budget. That changed bytes inside the provider's cached prefix and, because it trimmed only enough to fit, recurred on every run near the window.

Predicted pressure now counts and trims only results the provider has not received (after the last assistant message). Overflow from sent history routes to compaction, an allowed rebuild point. Recovery after a real provider rejection is unchanged.

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

* fix(agents): preserve sent output in all predicted-overflow paths

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

* test(agents): model unsent tool results at the request boundary

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

---------

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>
obviyus added a commit that referenced this pull request Nov 20, 2026
…low and a concurrent chat on five transports (#201723)

## What was wrong

The prompt-cache journey is the CI check that each provider request in a chat extends the previous request byte for byte, except where a rebuild is expected. It skipped four triggers that real chats hit: a scheduled job that comes due in the chat, a user message steered into a running tool call, tool results that fill the context window, and an unrelated chat that compacts while this one runs. It also covered only three transports. A break in any of those paths could land without CI noticing.

**Example:** a scheduled job sent its reply to the model twice on every route. On Chat Completions and Gemini the copy merged into the next tool-call message, which rewrote history and lost the cache from that point on. Fixed in #201838. This journey would have caught it.

## Fix

- Adds the cron, steer, tool-result overflow and concurrent-compaction steps to the stability journey. It now runs on five transports: Anthropic, Responses, Chat Completions, Gemini and Bedrock.
- Adds a seeded randomized journey: 15 turn kinds on five transports, plus a variant with Tool Search turned off.
- Lists the breaks main still has, each with its owner. Entries expire: when a fix lands, the journey fails until its entry is removed. Each entry checks the whole request, so a known change cannot hide a second one.
- Rebuild steps are excused only when the rebuild actually happened. A compaction must put its new summary into the next request, and a model switch must make the next request come from the selected model.
- The steer step holds the tool open until the Gateway reports that the run has taken the steer. Before, it slept for a fixed 3 s.

## Numbers

| | main (before this PR) | this PR |
|---|---|---|
| Triggers covered | ordinary turns, tools, compaction | + cron, steer, tool-result overflow, concurrent compaction, cron-first chat, 15-kind randomized journey |
| Transports | 3 | 5 |
| Stability journey | n/a | 5/5 |
| Randomized journey (default seeds, 6 files) + negative controls | n/a | 12/12 + 5/5 |
| Anthropic and Tool Search off, seeds 1 and 6 | n/a | 2/2 and 2/2 |

<details><summary>Breaks still on main (accepted entries)</summary>

| Where | Change | Owner |
|---|---|---|
| Gemini, tool-result overflow (other chat) | the pre-request pressure check trims tool results that were already sent | #199530 |
| Bedrock, randomized | a dropped silent reply merges the user turns around it | accepted gap (#201654 closed) |
| Tool Search off, randomized | a provider switch adds `skills_read`/`skills_search` on turns started by a subagent completion or inter-session message | #201710 / documented exception of the opt-out surface |

Removed because their owners landed: the cron reply twice (#201838), the Chat Completions silent-turn merge (#201843), the cron-first `message` growth (#201710), and the skills rebuild after `config.patch` (issue #202150, which no longer reproduces on Anthropic seeds 1 and 6).
Bedrock refuses `cron.add` for AWS-SDK auth by design, and the journey expects that refusal.
</details>

<details><summary>Steer signal</summary>

- The steer is sent with `queueMode: "steer"`, as the chat composer sends it. The test waits for `sessions.changed` with reason `agent.input.steering`, which the Gateway emits when the active run accepts the steer into its queue. The tool is released only after that event.
- On all five transports the event arrives about 200-260 ms after the send is acknowledged, while the tool is still held.
- Negative control: releasing right after the acknowledgment lost the race on Gemini (1/5). The steered input became a separate turn.
- A default `chat.send` steer exposes nothing before release. Its pending input stays `queued` with no `steerNow`, and `agent.input.steering` only fires when the tool ends. So the step uses the composer's steer path.
</details>

<details><summary>Rebuild evidence checks</summary>

- Compaction: the fake numbers each compaction summary. The step needs a new summary, and the turn after it must contain that summary.
- Model switch: the alternate provider has its own model id. Every request after the switch must name exactly the selected model, read from the request body or the URL (Gemini, Bedrock), and at least one request must arrive.
- Teeth: with `sessions.compact` turned into a no-op, all 10 randomized seeds failed. With `sessions.patch` pinned to the first model, all 10 failed too.
</details>

<details><summary>Cron-first red on base</summary>

On the parent of #201710 with this PR's test files (no entry), the cron-first step fails on Anthropic and Responses at the owner turn's tool list (`at: 1, change: tools`). On main the step passes.
</details>

<details><summary>Harness fixes</summary>

- Each seed uses its own session keys. A retained subagent from the previous seed made every turn fail with `Retained subagent payload is unavailable`.
- After a silent reply, the fake acts only on the newest step marker, because main drops silent replies from replay.
- Every request is assigned to its session by its runtime line. A request from an unexpected session fails the journey.
- The Advisor fork check is dropped. Forks never arrived in earlier runs. When they did arrive, their requests differed from the parent's on all transports, which needs its own investigation.
</details>

<details><summary>Gates</summary>

- `ocx test` from source with an in-process Gateway and fake provider endpoints: 5 stability files, 6 randomized files and the known-breaks unit, 17/17. Anthropic and Tool Search off at seeds 1 and 6, 2/2 each. A second stability pass, 5/5.
- `pnpm tsgo:test:root`, oxfmt and oxlint on the changed files, and the test-lines ratchet all pass.
- Local review on this head: patch is correct, no findings.
</details>

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…low and a concurrent chat on five transports (openclaw#201723)

## What was wrong

The prompt-cache journey is the CI check that each provider request in a chat extends the previous request byte for byte, except where a rebuild is expected. It skipped four triggers that real chats hit: a scheduled job that comes due in the chat, a user message steered into a running tool call, tool results that fill the context window, and an unrelated chat that compacts while this one runs. It also covered only three transports. A break in any of those paths could land without CI noticing.

**Example:** a scheduled job sent its reply to the model twice on every route. On Chat Completions and Gemini the copy merged into the next tool-call message, which rewrote history and lost the cache from that point on. Fixed in openclaw#201838. This journey would have caught it.

## Fix

- Adds the cron, steer, tool-result overflow and concurrent-compaction steps to the stability journey. It now runs on five transports: Anthropic, Responses, Chat Completions, Gemini and Bedrock.
- Adds a seeded randomized journey: 15 turn kinds on five transports, plus a variant with Tool Search turned off.
- Lists the breaks main still has, each with its owner. Entries expire: when a fix lands, the journey fails until its entry is removed. Each entry checks the whole request, so a known change cannot hide a second one.
- Rebuild steps are excused only when the rebuild actually happened. A compaction must put its new summary into the next request, and a model switch must make the next request come from the selected model.
- The steer step holds the tool open until the Gateway reports that the run has taken the steer. Before, it slept for a fixed 3 s.

## Numbers

| | main (before this PR) | this PR |
|---|---|---|
| Triggers covered | ordinary turns, tools, compaction | + cron, steer, tool-result overflow, concurrent compaction, cron-first chat, 15-kind randomized journey |
| Transports | 3 | 5 |
| Stability journey | n/a | 5/5 |
| Randomized journey (default seeds, 6 files) + negative controls | n/a | 12/12 + 5/5 |
| Anthropic and Tool Search off, seeds 1 and 6 | n/a | 2/2 and 2/2 |

<details><summary>Breaks still on main (accepted entries)</summary>

| Where | Change | Owner |
|---|---|---|
| Gemini, tool-result overflow (other chat) | the pre-request pressure check trims tool results that were already sent | openclaw#199530 |
| Bedrock, randomized | a dropped silent reply merges the user turns around it | accepted gap (openclaw#201654 closed) |
| Tool Search off, randomized | a provider switch adds `skills_read`/`skills_search` on turns started by a subagent completion or inter-session message | openclaw#201710 / documented exception of the opt-out surface |

Removed because their owners landed: the cron reply twice (openclaw#201838), the Chat Completions silent-turn merge (openclaw#201843), the cron-first `message` growth (openclaw#201710), and the skills rebuild after `config.patch` (issue openclaw#202150, which no longer reproduces on Anthropic seeds 1 and 6).
Bedrock refuses `cron.add` for AWS-SDK auth by design, and the journey expects that refusal.
</details>

<details><summary>Steer signal</summary>

- The steer is sent with `queueMode: "steer"`, as the chat composer sends it. The test waits for `sessions.changed` with reason `agent.input.steering`, which the Gateway emits when the active run accepts the steer into its queue. The tool is released only after that event.
- On all five transports the event arrives about 200-260 ms after the send is acknowledged, while the tool is still held.
- Negative control: releasing right after the acknowledgment lost the race on Gemini (1/5). The steered input became a separate turn.
- A default `chat.send` steer exposes nothing before release. Its pending input stays `queued` with no `steerNow`, and `agent.input.steering` only fires when the tool ends. So the step uses the composer's steer path.
</details>

<details><summary>Rebuild evidence checks</summary>

- Compaction: the fake numbers each compaction summary. The step needs a new summary, and the turn after it must contain that summary.
- Model switch: the alternate provider has its own model id. Every request after the switch must name exactly the selected model, read from the request body or the URL (Gemini, Bedrock), and at least one request must arrive.
- Teeth: with `sessions.compact` turned into a no-op, all 10 randomized seeds failed. With `sessions.patch` pinned to the first model, all 10 failed too.
</details>

<details><summary>Cron-first red on base</summary>

On the parent of openclaw#201710 with this PR's test files (no entry), the cron-first step fails on Anthropic and Responses at the owner turn's tool list (`at: 1, change: tools`). On main the step passes.
</details>

<details><summary>Harness fixes</summary>

- Each seed uses its own session keys. A retained subagent from the previous seed made every turn fail with `Retained subagent payload is unavailable`.
- After a silent reply, the fake acts only on the newest step marker, because main drops silent replies from replay.
- Every request is assigned to its session by its runtime line. A request from an unexpected session fails the journey.
- The Advisor fork check is dropped. Forks never arrived in earlier runs. When they did arrive, their requests differed from the parent's on all transports, which needs its own investigation.
</details>

<details><summary>Gates</summary>

- `ocx test` from source with an in-process Gateway and fake provider endpoints: 5 stability files, 6 randomized files and the known-breaks unit, 17/17. Anthropic and Tool Search off at seeds 1 and 6, 2/2 each. A second stability pass, 5/5.
- `pnpm tsgo:test:root`, oxfmt and oxlint on the changed files, and the test-lines ratchet all pass.
- Local review on this head: patch is correct, no findings.
</details>

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…esults the provider already cached (openclaw#199530)

* fix(agents): compact on predicted overflow instead of trimming tool results the provider already cached

The pre-request pressure check counted every tool result as reducible and, on the truncate-only route, rewrote the oldest already-sent results down to the aggregate budget. That changed bytes inside the provider's cached prefix and, because it trimmed only enough to fit, recurred on every run near the window.

Predicted pressure now counts and trims only results the provider has not received (after the last assistant message). Overflow from sent history routes to compaction, an allowed rebuild point. Recovery after a real provider rejection is unchanged.

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

* fix(agents): preserve sent output in all predicted-overflow paths

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

* test(agents): model unsent tool results at the request boundary

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

---------

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>

Release adaptation: Preserve reviewed individual adaptation; source bytes unchanged. Parent-inspected framing fixture correction: unchanged baseline ceil(12*1.2)=15, expected41015/1015; exact assertions retained.

(cherry picked from commit 535f3ea)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…esults the provider already cached (#199530)

Baseline adaptation: filter reducible results at the last assistant in the existing measured branch planner, and persist only actual planner edits during predicted overflow. Use the release request guard and frozen projection/rewrite owners; leave actual provider rejection recovery unchanged.

(cherry picked from commit 535f3ea)

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit c243246e52dc550f77115c04540d13725f13b482)
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: 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.

2 participants