Skip to content

fix(preemptive-compaction): use MIN_PROMPT_BUDGET_TOKENS as floor, not ceiling - #96759

Closed
krissding wants to merge 1 commit into
openclaw:mainfrom
krissding:fix/issue-96658-lightweight-prompt-budget
Closed

krissding wants to merge 1 commit into
openclaw:mainfrom
krissding:fix/issue-96658-lightweight-prompt-budget

Conversation

@krissding

Copy link
Copy Markdown
Contributor

Summary

  • The minPromptBudget calculation in shouldPreemptivelyCompactBeforePrompt used Math.min, making MIN_PROMPT_BUDGET_TOKENS (8000) the upper bound for the ratio-based prompt budget
  • For small-context models (e.g. phi3:mini at 4096 tokens), the ratio-based value was only 2048, leaving barely any room for the actual prompt after reserve tokens were subtracted — every prompt overflowed and compact_only had nothing to compact with lightweight sessions
  • Fix: switch to Math.max so the constant acts as a true floor, ensuring models under 16k context receive at least half the window for prompt content. Large models are unaffected since their ratio-based value already exceeds 8000

Test plan

  • Verify phi3:mini (4096) no longer gets promptBudgetBeforeReserve=409 with lightweight sessions
  • Verify large-model behavior (200k context) is unchanged
  • Verify medium models (32k) still route correctly

Closes #96658

🤖 Generated with Claude Code

…t ceiling

The minPromptBudget calculation used Math.min, making 8000 the upper bound
for the ratio-based prompt budget. For small-context models (e.g. phi3:mini
at 4096 tokens), the ratio-based value was only 2048, leaving barely any
room for the actual prompt after reserve tokens were subtracted.

Change Math.min to Math.max so MIN_PROMPT_BUDGET_TOKENS acts as a true floor,
ensuring models under 16k context receive at least half the window for prompt
content. Large models are unaffected since the ratio-based value already
exceeds 8000.

Closes openclaw#96658

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 25, 2026
@clawsweeper

clawsweeper Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

This PR should close as superseded: it targets the real lightweight-cron overflow bug, but #96668 is an open, mergeable, proof-positive canonical fix for the same issue with scoped behavior, regression coverage, and real cron/Gateway proof.

Root-cause cluster
Relationship: superseded
Canonical: #96668
Summary: This PR is superseded by an open, proof-positive canonical candidate for the same lightweight cron context-overflow bug.

Members:

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

Canonical path: Close this branch and let maintainers review or land the proof-positive canonical PR for the lightweight cron overflow fix.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this branch and let maintainers review or land the proof-positive canonical PR for the lightweight cron overflow fix.

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

Yes at source level: current main leaves 2,048 prompt tokens for the linked issue's 4,096-token model and 20,000-token reserve, below the reported 3,544-token lightweight prompt. I did not run the live cron setup for this review.

Is this the best way to solve the issue?

No. This branch is a plausible one-line arithmetic change, but the proof-positive sibling PR is the better maintained fix path because it scopes the policy, accounts for tool schemas, adds tests, and includes real cron/Gateway proof.

Security review:

Security review cleared: No security or supply-chain surface is changed; the diff only adjusts local token-budget arithmetic and a code comment.

AGENTS.md: found and applied where relevant.

What I checked:

  • current PR diff: The branch changes only the precheck minPromptBudget calculation from Math.min to Math.max and adds a comment; it adds no tests or real behavior proof. (src/agents/embedded-agent-runner/run/preemptive-compaction.ts:284, 5754597210c7)
  • current-main source behavior: Current main leaves a 2,048-token prompt budget on the linked issue's 4,096-token model, matching the source-level reproduction for the reported overflow. (src/agents/embedded-agent-runner/run/preemptive-compaction.ts:284, 4ecb45bf7729)
  • canonical replacement status: The sibling PR is open, mergeable, clean, labeled proof: sufficient, and reviewed as ready for maintainer look. (26ea90c853a2)
  • canonical replacement proof: The sibling PR body includes after-fix source Gateway cron proof, the new route=fits budget line, focused regression tests, typecheck, formatting, and diff-check evidence. (26ea90c853a2)
  • related issue context: The linked issue is the canonical lightweight isolated cron context-overflow report, and its existing review already identifies this as source-reproducible on current main.
  • history provenance: Local blame attributes the current precheck formula, constants, and embedded attempt precheck call to commit 0cdb050bac194ac2c5356ed7c877acca38ad81ec; GitHub file history also shows recent maintenance by vincentkoc and adjacent runtime refactors by steipete. (src/agents/embedded-agent-runner/run/preemptive-compaction.ts:284, 0cdb050bac19)

Likely related people:

  • Josh Lehman: git blame attributes the current prompt-budget formula, constants, and embedded precheck call in this checkout to commit 0cdb050bac194ac2c5356ed7c877acca38ad81ec. (role: current implementation carrier; confidence: medium; commits: 0cdb050bac19; files: src/agents/embedded-agent-runner/run/preemptive-compaction.ts, src/agents/agent-compaction-constants.ts, src/agents/embedded-agent-runner/run/attempt.ts)
  • vincentkoc: GitHub file history shows repeated recent work on embedded runner and compaction-adjacent agent settings paths. (role: recent area contributor; confidence: high; commits: ff49b7fab106, 18aa3276554c, 4637b65470de; files: src/agents/embedded-agent-runner/run/preemptive-compaction.ts, src/agents/embedded-agent-runner/run/attempt.ts, src/agents/agent-settings.ts)
  • steipete: GitHub history shows broad agent-runtime internalization and model/settings refactors that shaped the surrounding compaction and embedded-runner boundaries. (role: adjacent runtime refactor contributor; confidence: medium; commits: bb46b79d3c14, 8eeaa45729a3, 634174f050b4; files: src/agents/embedded-agent-runner/run/preemptive-compaction.ts, src/agents/agent-settings.ts)

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

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 25, 2026
@clawsweeper

clawsweeper Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context overflow in isolated cron sessions with lightweight bootstrap (lightContext: true)

1 participant