Repository navigation
fix(control-ui): measure context usage against the effective token budget - #138666
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be5399ff39
ℹ️ 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".
|
Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 5:19 PM ET / 21:19 UTC. ClawSweeper reviewWhat this changesThe Control UI measures context usage against a validated last-run prompt budget and clears obsolete budget estimates when session selections change. Merge readiness✅ Ready for maintainer review This remains a useful fix for the linked issue. The earlier denominator, stale-budget, and labeling findings are addressed; no blocking defect was found in the current patch. Priority: P2 Review scores
Verification
How this fits togetherThe agent runtime records prompt-budget estimates in session telemetry. Gateway validates that telemetry before sending it to the Control UI, which uses it for context meters, session details, and usage output. flowchart LR
A[Runtime budget estimate] --> C[Gateway session projection]
B[Current model and context cap] --> C
C --> D{Estimate still matches?}
D -->|Yes| E[Last-run prompt budget]
D -->|No| F[Current context capacity]
E --> G[Control UI usage displays]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +85, Tests +320, Docs +8. Total +413 across 22 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep budget validation in Gateway and share its last-run estimate across UI displays, preserving capacity fallback and approximate-usage behavior. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the denominator mismatch: a 160k session with 200k capacity and a 180k prompt budget displays 80% on main instead of 89%; supplied browser observations exercise that case. Is this the best way to solve the issue? Yes. Validating telemetry at its Gateway owner and sharing one UI resolver avoids reconstructing runtime reserve policy in the browser. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9c962dab44a3. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
The last review covered [P1] Measure pressure against the compaction threshold. Done. Label it accurately. The resolver returns [P1] Resolve merge risk. The added surface now carries the reserve-adjusted boundary, which was the condition attached to it. Replace the impossible fixture. Gone. Focused coverage across the affected displays. All four consumers now assert against that one helper: composer ring (including the warning-threshold crossing and the over-boundary case), sessions view meter and token cell, Real behavior proof. Added to the PR body. Captured from the repo's mocked-Gateway Control UI (
Worth being explicit about what that fixture isolates: its catalog window and Not measured, stated as such: |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
The failing shard
94 of 94 green. Happy to rebase or re-run the shard if that helps. |
…dget The context usage meter divided the session total by the model's catalog context window, so a long session could be compacting while the ring still read a comfortable percentage. Measure against contextBudgetStatus.contextTokenBudget instead: that is the ceiling the runtime enforces once reserves are subtracted. The catalog value stays as the fallback for sessions that have not produced a budget snapshot yet. The same denominator drove the sessions-page meter and the /usage slash command, so both move to one shared resolver. Co-Authored-By: Claude Opus 5 <[email protected]>
The shared resolver divided by contextBudgetStatus.contextTokenBudget, but the runtime compacts once the prompt passes promptBudgetBeforeReserve, that budget minus the effective reserve. With the default 20k reserve on a 200k budget the meter still read 80% at the moment compaction started, below the composer's unchanged 85% warning threshold, so the reported "comfortable while compacting" outcome survived in a narrower band. Resolve promptBudgetBeforeReserve first, so 100% is the point where the runtime compacts, and label the composer popover "Context before compaction" while that value is in use. The heading stays "Context window" on the catalog fallback, where it remains true. Replace the impossible fixture, which carried equal contextTokenBudget and promptBudgetBeforeReserve next to a 32,768-token reserve, with a builder that derives every field the way buildPrePromptContextBudgetStatus does, including the reserve cap from resolveEffectiveCompactionReserveTokens. Cover the composer ring, the sessions meter, the sessions detail row and /usage with that one snapshot. Co-Authored-By: Claude Opus 5 <[email protected]>
…ock UI Rendering the popover in a browser showed "Context before compaction" wrapping onto two lines where "Context window" takes one, so the heading becomes "Before compaction". The mock dev server's main session now carries a budget snapshot, so `pnpm dev:ui:mock` reproduces the meter state this PR is about: the same 160,000-token session reads 80% and stays quiet against the window, and 89% with the warning tone against the prompt budget. Co-Authored-By: Claude Opus 5 <[email protected]>
buildGatewaySessionRow() projects the current effective cap into every row's contextTokens but forwards the stored contextBudgetStatus unchanged, so an idle session keeps a budget measured against the previous cap until it runs again. Preferring that snapshot unconditionally reported the old, wider boundary as current: lowering a model from 1,000,000 to 200,000 tokens left 160,000 tokens reading 16% of a retained 980,000-token prompt budget, under the composer's warning threshold, for a session the next run compacts at 89%. Bound every snapshot step by what the current cap allows, re-deriving the prompt budget with the runtime's own reserve rule so 100% stays on the compaction point instead of falling back to a plain window. The clamp is one-directional on purpose. A snapshot narrower than the current cap is kept, because that is also what a legitimately tighter runtime budget looks like from the row and the two are indistinguishable there; the PR's own fixture is that case, with a 262,144-token catalog window over a 200,000-token enforced budget. Preferring the tighter boundary never reads comfortable while the runtime is already compacting.
cb21f30 to
4dce925
Compare
…budget Validate saved budget provenance in Gateway, clear derived telemetry when context-window selection changes, and publish budget tombstones in session events. Share the last-run budget across composer, sessions and usage views. Complete the existing contributor PR while preserving its original history. Related: openclaw#138590 Co-authored-by: Peik S. <[email protected]>
|
I inspected all four complete before/after images before uploading them: synthetic session data only, with the composer and sessions values changing from 160k/200k (80%) to 160k/180k (89%). The PR body embeds the original files. All four attachment URLs also passed fresh bounded GET checks: HTTP 206, image/png, with PNG headers matching the inspected originals. HEAD requests returned 403, so those probes do not establish that the images are unavailable. The reviewer’s retrieval limitation does not leave a product or visual-proof gap here. The supplied Chromium and Gateway regression evidence remains unchanged. The remaining landing blockers are unrelated main CI regressions: the credential QA selector tracked in #141545, and the native-link test already repaired by #141533. Required CI will be rerun with those main repairs before landing. |
|
Merged via squash.
|
…dget (openclaw#138666) Fixes openclaw#138590. Measure composer, sessions, session-detail, and usage context displays against a validated last-run prompt budget. Gateway checks session, model/provider, and effective-cap provenance; context-window changes invalidate derived telemetry and session events clear obsolete budgets. Preserve current-cap fallback and approximate-token warning behavior. Retain the original contributor's implementation history and complete the stale-budget repair at its Gateway owners. Label the estimate as a last-run prompt budget rather than promising a specific compaction threshold. Validation: 584 focused tests and real Chromium/mock-Gateway before/after and live-update proof. Final required CI passed on 47f32b9 after one unchanged-job rerun for a documented unrelated temporary-directory teardown race. Main QA repairs openclaw#141533 and openclaw#141555 are included. Co-authored-by: Peik S. <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: DasX <[email protected]>
Closes #138590
What Problem This Solves
Fixes an issue where the Control UI context meter can show comfortable remaining capacity while a local model is close to its effective prompt budget. The composer, sessions meter, session detail, and
/usageused the context window rather than the reserve-adjusted budget recorded by the last run.Why This Change Was Made
Gateway now publishes a saved prompt budget only when its session, canonical model/provider, and effective context cap still match. Changing a context-window selection clears derived cap and budget telemetry; live session events carry an explicit null when the saved budget is no longer applicable.
The four UI displays share a small resolver that uses the validated last-run prompt budget and otherwise falls back to current context capacity. The label says “Prompt budget (last run)”: exceeding it can trigger tool-result truncation or compaction, so it is not an exact promise of when compaction runs. The browser does not reconstruct runtime reserve policy.
User Impact
All four displays use the same denominator, and changing a model or context limit cannot leave an old prompt budget presented as current. A valid narrower runtime budget remains usable. Approximate token totals retain their existing non-warning presentation. Older or unbound snapshots fall back to context capacity until a matching run refreshes them.
Evidence
sessions.changedclears the old budget and shows the changed cap without a manual refresh.Maintainer completion of @DasX’s existing PR; thanks to Peik S. for the original report-driven implementation and coverage. The contributor history is preserved.
Compatibility
The persisted session schema and context settings are unchanged. Saved diagnostics that lack matching provenance remain stored but are not presented as current; the UI falls back to context capacity until the next run. Context-window changes clear existing derived telemetry through the mutation owner, matching model-switch invalidation. The existing session-event contract permits these fields, and the existing reconciliation path removes explicit null tombstones. No database migration, configuration option, or protocol version change is required.