Repository navigation
fix(agents): apply per-agent contextTokens cap to embedded run context budget - #120343
Conversation
062ce32 to
5790a1d
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 12:40 PM ET / 16:40 UTC. ClawSweeper reviewWhat this changesThe branch makes an agent’s existing per-agent Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep this PR open for maintainer selection: it is a coherent fix with strong owner-boundary evidence, but it overlaps the open PR #119277 with a different request-budget precedence and needs one canonical direction. Priority: P1 Review scores
Verification
How this fits togetherEmbedded runs derive a context budget from agent configuration and model metadata before attempting a model call. The same budget is consumed by prechecks, compaction, session metadata, and safeguard compaction. flowchart LR
A[Agent configuration] --> B[Embedded run setup]
B --> C[Effective context budget]
C --> D[Prompt precheck]
C --> E[Compaction]
C --> F[Safeguard sizing]
D --> G[Model attempt]
Decision needed
Why: Both open PRs repair the same omission but encode different durable/session request precedence; source establishes the alternatives but not the intended permanent contract. Before merge
Agent review detailsSecurityNone. PR surfaceSource +60, Tests +112. Total +172 across 11 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Choose one canonical cap-precedence rule, land only its corresponding PR, and keep the broader durable-session provenance behavior tracked separately. Do we have a high-confidence way to reproduce the issue? Yes: current main visibly omits the selected-agent cap in the embedded model-policy call, and the branch adds an end-to-end regression that distinguishes 200k from the 128k default. Is this the best way to solve the issue? Unclear: the propagation repair is coherent, but the competing PR establishes an unresolved request-budget precedence choice that should be decided once rather than merged twice. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 13e30a9d55e6. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
5790a1d to
73fee5f
Compare
|
I was scanning the open PR queue for changed-file overlap and this branch matched #119277: the two PRs touch the same 10 files, and both are currently labelled Neither PR references the other. Both do carry a ClawSweeper What I compared: added production lines (tests, docs and generated files excluded) at
Two independent implementations rather than a copy, same as the file-set match suggests. Both add Where they diverge is worth one decision rather than two: They rewrite the same two user-facing strings differently.
They resolve the agent id from different sources in They compute the cap differently. #119277 passes Scope of what I checked: file sets, added production lines, and the budget-resolution path on both heads. I did not run either branch's tests, and I have not formed a view on which cap-resolution order is correct. Since both branches edit the same two message strings and the same budget call, the second to merge will conflict there. Which one lands is your call; the thing to avoid is both landing. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Apply the selected agent contextTokens ceiling to embedded-run prechecks, effective model sizing, compaction, safeguard sizing, and result metadata. Prepared attempts now carry one canonical budget into extension setup instead of re-resolving mutable policy. Caller-requested compaction budgets remain bounded by both the selected agent cap and the model window. Native model-owned harnesses continue to own their context and compaction policy. Refs: openclaw#118678 Co-authored-by: harjoth <[email protected]>
73fee5f to
68d6d3c
Compare
|
@clawsweeper re-review Exact head: The maintainer rewrite selects this PR's agent-cap-as-ceiling semantics over #119277, removes duplicate safeguard policy resolution by carrying the prepared attempt budget, and personally verifies the unchanged native Codex ownership boundary against |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
@clawsweeper re-review Exact head: The maintainer rewrite selects this PR's agent-cap-as-ceiling semantics over #119277, removes duplicate safeguard policy resolution by carrying the prepared attempt budget, and personally verifies the unchanged native Codex ownership boundary against |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Maintainer evidence and resolved rank-up movesThe batch's maintainer authority selects #120343 as the canonical fix over #119277. A configured per-agent I personally inspected sibling
That contract proves the unchanged No authenticated-provider run was added. This defect is internal prepared-budget ownership, so a cloud request would not prove it more directly than the deterministic embedded boundary. Exact-head coverage asserts the 200,000-token prepared attempt budget, effective model context window, and Local proof limitations are recorded rather than hidden: the fresh worktree's E2E setup attempted a stale-dist rebuild without the UI ClawSweeper's exact-head immutable artifact for |
|
Merged via squash after the maintainer rewrite and exact-head proof.
GitHub and the local fetch both verify the landed commit is the current |
…t budget (openclaw#120343) * fix(agents): honor per-agent context budgets Apply the selected agent contextTokens ceiling to embedded-run prechecks, effective model sizing, compaction, safeguard sizing, and result metadata. Prepared attempts now carry one canonical budget into extension setup instead of re-resolving mutable policy. Caller-requested compaction budgets remain bounded by both the selected agent cap and the model window. Native model-owned harnesses continue to own their context and compaction policy. Refs: openclaw#118678 Co-authored-by: harjoth <[email protected]> * test(agents): type compaction model fixtures --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Embedded runs ignored the selected agent's
contextTokensceiling. The run instead fell back toagents.defaults.contextTokens, so prompt prechecks, compaction, and session metadata could disagree with the per-agent limit the operator configured.Why This Change Was Made
The selected session agent is now resolved before OpenClaw-owned model policy and its configured ceiling is applied to the prepared attempt budget. That prepared budget is then carried into the effective model, normal and compaction session safeguard extensions, and result metadata instead of re-resolving mutable policy at each consumer.
Standalone queued/direct compaction resolves the canonical session agent when no prepared attempt exists. Caller budgets remain ceilings within the configured agent cap and model window:
Native model-owned harnesses still return before OpenClaw context policy. Codex therefore continues to own its own model context window and automatic/manual compaction.
Best-Fix Decision
This PR is the canonical fix rather than #119277. A per-agent
contextTokensvalue is an operator-configured ceiling, so a larger request must not override it. The broader durable-session and hot-reload provenance question in #118678 remains intentionally out of scope.Production LOC: +47/-12 (net +35) | Tests: +115/-2 (net +113). The production growth establishes one selected-agent ownership boundary and carries the prepared fact to consumers; the rewrite removes the incoming duplicate safeguard-policy resolution.
Evidence
git diff --check: passed.Codex Ownership Audit
Verified against
openai/codexcommitc2bcb9a26b5bdbdc66c48cf3bc3bb382568e800c:codex-rs/protocol/src/openai_models.rs:416-424,463-479owns model context and automatic-compaction thresholds.codex-rs/models-manager/src/model_info.rs:25-37applies context and compaction overrides.codex-rs/core/src/session/context_window.rs:23-79decides native context-window pressure and compaction.codex-rs/core/src/session/handlers.rs:444-448andcodex-rs/core/src/tasks/compact.rs:19-84own manual compaction.codex-rs/app-server-protocol/src/protocol/v2/thread.rs:988-998andcodex-rs/app-server/src/request_processors/thread_processor.rs:1913-1924showthread/compact/startaccepts only the thread id and delegates to nativeOp::Compact.Refs: #118678
Co-authored-by: harjoth [email protected]