Repository navigation
fix: status loses context usage after tool-only turns - #134634
Patrick-Erichsen merged 2 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 10:28 PM ET / September 1, 2026, 02:28 UTC. ClawSweeper reviewWhat this changesPreserves exact current-turn context usage for status output when an agent turn completes through a tool without an assistant transcript message. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessThe focused patch appears to repair the lost status snapshot and remains necessary because current main still omits attempt-level context usage; formal merge review remains pending the required direct inspection of the pinned Codex source and exact-head checks. Priority: P2 Review scores
Verification
How this fits togetherThe embedded agent runner receives provider usage after a turn settles, normalizes it into status metadata, and passes that metadata to Telegram and terminal status views. This change keeps a provider-supplied context snapshot available when no assistant text was emitted. flowchart LR
A[Codex usage event] --> B[Codex usage projector]
B --> C[Settled agent attempt]
C --> D[Usage normalization]
D --> E[Status metadata]
E --> F[Telegram and terminal status]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +4, Tests +19. Total +23 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the owner-boundary fix, then complete the pinned Codex contract check and exact-head validation before merging. Do we have a high-confidence way to reproduce the issue? No independent current-main run was performed in this read-only environment; the source path is clear and the PR body reports a concrete live tool-only reproduction. Is this the best way to solve the issue? Yes for the local owner boundary: selecting exact attempt usage ahead of transcript-derived candidates preserves current-turn provenance while retaining unavailable-context semantics; the required direct Codex contract check remains outstanding. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 765c0cddfd91. LabelsLabel changes:
Label 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
History |
|
Added real after-fix tool-only runtime proof to the PR body: one successful @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
Co-authored-by: Dmitriy <[email protected]>
What Problem This Solves
Fixes an issue where users checking
/statusafter a turn delivered entirely through a messaging tool would seeContext: ?/<window>in Telegram and the TUI even though the Codex runtime supplied exact context usage.Reproduction
Tested live with OpenClaw 2026.8.1 (
ea80657), the OpenAI Codex runtime, and a pinnedgpt-5.6-solsession:messagetool, with no terminal assistant message. In the live reproduction,тут?producedТут. 🐿️through the messaging tool./statusimmediately afterward.Actual result in both Telegram and the TUI:
Expected result:
/statusshould show the current used-token count because the runtime emitted exact context usage for the turn.Why This Change Was Made
Codex app-server token usage is projected into
attemptUsage.contextUsageindependently of assistant messages. A tool-only turn can therefore have exact attempt usage but nocurrentAttemptAssistant. Attempt normalization considered assistant and prompt-cache usage when selecting the latest context snapshot, but omitted the exact attempt usage, solastRunPromptUsagebecameundefinedand downstream status metadata marked the total as not fresh.This change adds
attemptUsageas the newest candidate only when it carries explicitcontextUsage. Aggregate billing-only usage remains excluded, and an explicit unavailable-context sentinel remains authoritative.User Impact
Telegram and TUI
/statusoutput can retain the current context usage after tool-only turns instead of intermittently displaying?. Status still reports unknown when the runtime genuinely has no exact context provenance.Evidence
Real after-fix runtime proof
Full sanitized live trace and reproduction command from this PR head (
8bcea6eacebe). The existing repository live gateway harness launched the plugin-owned Codex app-server and made a real model request; usage was not mocked.The turn completed exactly one
messagetool call and emitted no assistant text. The same session then produced:The live Vitest run passed in 54.07 seconds. Temporary assertion-only instrumentation used to capture the trace was removed and is not part of this PR.
Pinned Codex contract verification
OpenClaw pins
@openai/codexto0.151.0. Its matching upstream tag,rust-v0.151.0, resolves to Codex commit78c290807ce710180111df227df3b7a4fe845452.Direct inspection of that exact source confirms:
ResponseEvent::Completedrecords token usage and requests a token-count event.thread/tokenUsage/updated.ThreadTokenUsagecarries total usage, last-response usage, and the model context window.This matches OpenClaw's projector contract: exact context usage can exist for a tool-only turn with no assistant message.
Regression and repository checks
lastRunPromptUsage: undefined; after the change it passes.scoped-clean, with no accepted or actionable findings.No changelog entry was added, per contributor guidance.