Repository navigation
Align tool-result truncation more closely with PI - #61651
Conversation
Greptile SummaryThis PR removes OpenClaw's live historical rewrite path (aggregate compaction/placeholder replacement) and replaces it with single-pass per-result truncation, adds a PI-style reserve-based precheck before provider submission with three cause-aware routes ( Confidence Score: 5/5Safe to merge — no critical logic errors found; all new paths are bounded and fall back to existing safety nets. All remaining findings are P2 or lower. The routing logic is mutually exclusive and well-tested: No files require special attention; Greploops — Automatically fix all review issues by running Reviews (2): Last reviewed commit: "Add overflow recovery routing regression..." | Re-trigger Greptile |
|
I think Codex found a real regression here, unless I am missing a different overflow-recovery path now. The issue is not the wording cleanup or the reserve-based precheck, it is patch 2 removing the persisted-session repair fallback entirely:
That whole branch is deleted in this PR, and the associated seam tests are deleted too. What remains now is:
But if compaction returns So I do not think this is safe to land yet as-is. I would either:
The deleted tests around aggregate overflow / retry-after-session-rewrite were doing real work here, so I would not treat them as dead code. |
|
My most recent commits address the repair path concerns and also handle the aggregate tool result scenario. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a533a930a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b08a9384ae
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e543f4765a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const promptBudgetBeforeReserve = Math.max( | ||
| 1, | ||
| Math.floor(params.contextTokenBudget) - Math.max(0, Math.floor(params.reserveTokens)), | ||
| ); |
There was a problem hiding this comment.
Clamp reserve subtraction before precheck overflow routing
When reserveTokens is greater than contextTokenBudget, this computes promptBudgetBeforeReserve as 1, so almost any non-empty prompt is treated as overflow before the provider is called. In that case the run enters compaction/truncation recovery even for fresh sessions with no reducible history, which can surface a false context-overflow failure instead of attempting the model call; this is especially likely on lower-window models where configured/default reserve can exceed the model budget. Cap the effective reserve used for this precheck (or skip this precheck branch) when reserve exceeds the context budget.
Useful? React with 👍 / 👎.
| const suffixFactory: (truncatedChars: number) => string = | ||
| typeof options.suffix === "function" | ||
| ? options.suffix | ||
| : () => options.suffix ?? DEFAULT_SUFFIX(1); |
There was a problem hiding this comment.
Use the real truncated count in default truncation suffixes
The default suffix factory ignores its truncatedChars argument and always falls back to DEFAULT_SUFFIX(1), so messages can report "... 1 more characters truncated" even when thousands of characters were removed. This also makes suffix-length budgeting optimistic by assuming a one-digit count. Use the passed count in the fallback (e.g. DEFAULT_SUFFIX(truncatedChars)) so truncation notices and sizing are accurate.
Useful? React with 👍 / 👎.
59f1d18 to
8a05763
Compare
|
Landed. Verification:
Land SHA: Thanks @Takhoffman. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99c66a1e8f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (preflightRecovery?.handled) { | ||
| log.info( | ||
| `[context-overflow-precheck] early recovery route=${preflightRecovery.route} ` + | ||
| `completed for ${provider}/${modelId}; retrying prompt`, | ||
| ); | ||
| continue; |
There was a problem hiding this comment.
Honor abort before retrying handled preflight recovery
This unconditional continue retries the loop whenever preflightRecovery.handled is true, even if the attempt was already canceled (aborted set from abortSignal in runEmbeddedAttempt). In that case the run can ignore a user cancel for another iteration and keep mutating session history (for example, after early tool-result truncation), instead of exiting promptly. Gate this fast-path on a non-aborted/non-timeout attempt so cancellation semantics are preserved.
Useful? React with 👍 / 👎.
Summary
[... N more characters truncated]Original behavior: OpenClaw before this PR
PI behavior (For reference)
New behavior: OpenClaw after this PR
Aggregate tool-result fallback
Aggregate overflow means no single tool result is above the per-result limit, but the recent tool-result tail is still too large as a group.
Example:
Important behavior:
[compacted: ...]style behavior is not reintroducedHow this differs from PI
Why not switch fully to PI in this PR
Verification
pnpm exec vitest run src/agents/pi-embedded-runner/run/preemptive-compaction.test.ts src/agents/pi-embedded-runner/tool-result-truncation.test.ts src/agents/pi-embedded-runner/run.overflow-compaction.loop.test.ts --config vitest.config.ts --reporter verbosepnpm exec oxlint src/agents/pi-embedded-runner/run/preemptive-compaction.ts src/agents/pi-embedded-runner/run/preemptive-compaction.test.ts src/agents/pi-embedded-runner/tool-result-truncation.ts src/agents/pi-embedded-runner/tool-result-truncation.test.ts src/agents/pi-embedded-runner/run/attempt.ts src/agents/pi-embedded-runner/run/types.ts src/agents/pi-embedded-runner/run.ts src/agents/pi-embedded-runner/run.overflow-compaction.loop.test.tsNotes
src/auto-reply/reply/dispatch-from-config.reply-dispatch.test.tsandsrc/cli/update-cli/update-command.ts; this PR’s code changes were validated with the focused commands above