feat(agents): expose estimated context budget status#84785
feat(agents): expose estimated context budget status#84785giodl73-repo wants to merge 2 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. for the review finding via source inspection: heartbeat runs pass PR rating Rank-up moves:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. Real behavior proof Risk before merge
Maintainer options:
Next step before merge Security Review findings
Review detailsBest possible solution: Persist and expose estimated context budget status only when it belongs to the same session runtime being reported, keep preserved-runtime heartbeat runs from replacing main-session budget status, and then prove the status output in a real run. Do we have a high-confidence way to reproduce the issue? Yes for the review finding via source inspection: heartbeat runs pass Is this the best way to solve the issue? No: the reporting path is plausible, but the PR should not persist or display a budget snapshot that does not match the reported session runtime. The safer fix is to gate or clear the snapshot alongside the existing preserved-runtime model/context behavior. Label changes:
Label justifications:
Full review comments:
Overall correctness: patch is incorrect What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 6745fe8e7046. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
d003bc2 to
fc5969f
Compare
|
Could not reopen this closed PR because GitHub would not allow changing the closed PR's old stack base. I rebased the branch onto |
Summary
Budget 2 in the context-budget stack, based on #84676.
This keeps the first PR's pre-prompt budget observation path and adds the read-only session/status surface for it:
contextBudgetStatussnapshot from the pre-prompt estimate, including route, estimate, budget, reserve, overflow, and message countsSessionEntry, then expose it on gateway session rows/statusshow estimated context usage (~tokens/window (% est)) only when fresh provider context usage is unavailable or absent; positive freshtotalTokensremains authoritativeThis is deliberately reporting-only. It does not introduce new compaction thresholds or policy decisions; that belongs in the next budget-management PR once the data is visible.
Refs #80594, #54996, #77992, #84490, #83177, #43009, #83526, #8635.
Verification
Behavior addressed: Sessions whose model/provider path cannot return fresh context usage can still expose OpenClaw's own pre-prompt estimate instead of showing only unknown/zero context usage.
Real environment tested: Windows worktree
C:\src\claws-hapi-budget2, stacked on #84676 (d003bc28a9). The worktree uses a localnode_modulesjunction to the main checkout's installed dependencies; no lockfile or dependency install changes were made.Exact steps or command run after this patch:
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/budget2.tsbuildinfonode_modules\.bin\oxfmt.CMD --check src/config/sessions/types.ts src/plugins/session-entry-slot-keys.ts src/agents/pi-embedded-runner/run/preemptive-compaction.ts src/agents/pi-embedded-runner/types.ts src/agents/pi-embedded-runner/run/types.ts src/agents/pi-embedded-runner/run/attempt.ts src/agents/pi-embedded-runner/run.ts src/agents/command/session-store.ts src/status/status-message.ts src/gateway/session-utils.types.ts src/gateway/session-utils.ts src/agents/pi-embedded-runner/run/preemptive-compaction.test.ts src/agents/command/session-store.test.ts src/auto-reply/status.test.tsgit diff --checknode scripts/run-vitest.mjs src/agents/pi-embedded-runner/run/preemptive-compaction.test.ts -t "builds a durable estimated context budget status snapshot"node scripts/run-vitest.mjs src/agents/command/session-store.test.ts -t "persists estimated context budget status"node scripts/run-vitest.mjs src/auto-reply/status.test.ts -t "uses estimated context budget status"node scripts/run-vitest.mjs src/auto-reply/status.test.ts -t "prefers fresh totalTokens over estimated context budget status"node scripts/run-vitest.mjs src/auto-reply/status.test.ts -t "uses estimated context budget status when token usage is absent"Evidence after fix: Focused tests prove the snapshot shape, persistence without marking stale totals fresh, estimated status fallback, fresh-token precedence, and absent-usage fallback.
tsgo,oxfmt --check, andgit diff --checkare clean.Observed result after fix: Status can render
Context: ~640k/1.0m (64% est)when storedtotalTokensis stale, continues to renderContext: 36k/1.0m (4%)when fresh usage exists, and avoidsContext: 0/1.0mwhen only the estimate is available.What was not tested: Full Vitest files and broad
pnpm check:changedwere not run locally. The full heavy files timed out in this Codex worktree dependency setup; the new assertions were run by focused filters with unique Vitest cache paths where needed.