Skip to content

2026.7.1: codex runs persist per-run usage but not the totalTokens aggregate — /status oscillates between ?/N and a number with each compaction (totalTokensFresh stuck false on plain turns) #107324

Closed

Description

@ikenraf

Version: v2026.7.1 (source, branch from tag; also reproduced field-shapes on a clean npm install), Windows 11, codex agent runtime (managed app-server 0.144.3), Telegram channel.

Symptom: /status context shows ?/272k after ordinary turns, then a real number again after an auto-compaction, oscillating. Both of our agents show it since upgrading to 2026.7.1 (from 6.11, where totals displayed continuously).

Mechanism (traced): in src/agents/command/session-store.ts (~232-276), the post-run persist takes one of three branches. Ordinary codex runs arrive with per-run usage populated (inputTokens, outputTokens, cacheRead are all written — e.g. 1029/71/122624 in our store) but the aggregate usage.totalTokens missing/0, so hasUsageTotalTokens is false and the fallback branch writes totalTokensFresh: false — which /status (commands-context-report.ts:290-294) renders as ?. Only the compaction-snapshot branch (compactionTokensAfter) stamps totalTokensFresh: true, which is why the display heals at each compaction and goes stale again on the next plain turn.

Expected: ordinary codex turns should refresh the trusted total (the engine reports total_token_usage per turn — the transcript records carry correct usage.totalTokens on every assistant message, e.g. 81070/81342/85293 in our files — so the data exists at write time; it just doesn't reach the run-summary aggregate the store checks).

Repro sketch:

  1. codex runtime agent on 2026.7.1, any model; send a normal message.
  2. Read the session entry: inputTokens/outputTokens/cacheRead populated, totalTokens carried from before, totalTokensFresh: false.
  3. /status → ?/N. Wait for an auto-compaction → number returns; next turn → ? again.

Happy to test a patch. (Same setup as our #106403 report if environment details help.)

Activity

  1. added
    P2Normal backlog priority with limited blast radius.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    impact:ux-frictionUser-facing flow adds avoidable confusion or support burden without fully blocking progress.
    no-staleExclude from stale automation
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jul 14, 2026
  2. clawsweeper commented on Jul 14, 2026

    @clawsweeper
    Contributor

    Codex review: this still needs some work.

    Summary
    Current main contains ordinary-turn and resumed-turn usage repairs, but the maintainer’s explicit live numeric /status closeout condition remains unverified.

    Reproducibility: The original release report and later repair describe a concrete failure, but no current-main failure was reproduced; inspected source and two-turn harness coverage support the repaired behavior.

    Maintainer decision needed

    • Question: Should this issue retain the explicitly requested live numeric /status closeout check?
    • Recommendation: Complete the live check: Record supported-runtime versions, session freshness, and numeric /status output after two successive ordinary turns before closing.
    • Why: Source and regression coverage support the repaired path, but the recorded maintainer condition requires an observation those artifacts do not provide.

    Next step
    The assignee should capture the requested supported-runtime freshness and numeric /status results, or explicitly accept the existing repair evidence for closeout.

    Review details

    Best possible solution:

    Confirm the shipped producer-backed accounting with a supported-runtime session showing fresh numeric /status usage across successive ordinary turns.

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

    The original release report and later repair describe a concrete failure, but no current-main failure was reproduced; inspected source and two-turn harness coverage support the repaired behavior.

    Is this the best way to solve the issue?

    The existing producer-backed repair respects the distinction between lifetime billing and current prompt usage; verification is the next step rather than another speculative persistence patch.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The available evidence does not show fresh numeric /status context usage after successive ordinary turns on the supported runtime.

    Codex review notes: model internal, reasoning medium; reviewed against a08c6b39287b.

    Label changes

    Label changes:

    No label changes.

    Label justifications:

    • P2: The reported failure affects context visibility without establishing interrupted execution or data loss.
    • impact:session-state: The report concerns persistence and freshness of session context accounting.
    • impact:ux-friction: Unknown context usage makes remaining session capacity harder to judge.
    Evidence reviewed

    What I checked:

    • Explicit maintainer closeout condition: The issue remains assigned to steipete, whose July 16 comment requires a supported Codex runtime and live proof of fresh numeric context usage before closure; no subsequent human comment supplies that result.
    • Current usage producer: Coherent response breakdowns produce available contextUsage; recordThread also accepts the last-response breakdown when exact response usage is absent, while billing totals remain separate. (extensions/codex/src/app-server/event-projector-usage.ts:59, a08c6b39287b)
    • Persistence and freshness boundary: Post-run persistence derives the session total from last-call context usage and marks it fresh when available; deriveSessionTotalTokens defines this as a prompt snapshot excluding completion tokens. (src/agents/command/session-store.ts:160, a08c6b39287b)
    • Two-turn regression coverage: The app-server harness supplies exact response usage on the first turn and thread usage on the second, expecting available context totals of 15,100 and 16,100 respectively; this is inspected test coverage, not an executed live status observation. (extensions/codex/src/app-server/run-attempt.test.ts:4540, a08c6b39287b)
    • Merged resumed-session repair: fix(codex): preserve resumed session usage #124969 merged the resumed-session repair and reports a live before-fix failure plus passing harness checks, but its body and comments do not establish the requested after-fix numeric /status observation. (43f127823a77)
    • Repair release containment: The resumed-session repair is contained in the v2026.10.1 tag; GitHub confirms that release was published, so the repair is not main-only. (43f127823a77)

    Likely related people:

    • Vincent Koc: Raw commit a232970 adds extensions/codex/src/app-server/event-projector-usage.ts:52 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: a2329704f350; files: extensions/codex/src/app-server/event-projector-usage.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed October 16, 2026, 5:49 AM ET / 09:49 UTC.

  3. added a commit that references this issue on Jul 14, 2026
    b3661cc
  4. self-assigned this
    on Jul 16, 2026
  5. removed
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    on Jul 16, 2026
  6. steipete commented on Jul 16, 2026

    @steipete
    Contributor

    Maintainer result: reviewed direct Codex source and all three alternatives. Closed #107622, #107630, and #107813. No OpenClaw patch landed.

    Contract evidence:

    • Codex accumulates every last response into total_token_usage (source).
    • The app-server notification publishes only lifetime total, per-response last, and modelContextWindow (shape). It has no current-window field.
    • Codex already has an internal active-history token calculation (source). Codex is the boundary that can define and publish truthful semantics.

    Best fix: add an explicit current-window value to the Codex producer/protocol, then map that field to OpenClaw contextUsage. Do not infer it from lifetime totals or downstream billing/cache buckets. Until that producer exists, /status remains unknown.

    Current main regression proof passed: status 85 tests, session-store 54 tests, Codex event projector 153 tests (292 total). The existing tests preserve unknown for stale/cumulative-only usage and preserve a fresh compaction snapshot.

    Removed the queueable/fix-shape-clear labels. This is not safely queueable as an OpenClaw-only patch today. Keeping the issue open for the producer contract.

  7. 21 remaining items

  8. added
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    and removed
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    on Aug 23, 2026
  9. added
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    and removed
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    on Sep 6, 2026
  10. added
    clawsweeper:intake:bugPreliminary submission classification; full source review pending.
    and removed
    clawsweeper:intake:bugPreliminary submission classification; full source review pending.
    on Oct 16, 2026
  11. steipete commented on Oct 24, 2026

    @steipete
    Contributor

    Thanks for filing this. We're closing older issues that no longer look actionable on current main.

    #107813 made Codex /status context freshness truthful by using exact per-response usage and otherwise reporting it as unknown, which removes the oscillation described here. If /status still flips on a current release, please open a fresh issue with the version and output.

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

Metadata

Metadata

Assignees

Labels

P2Normal backlog priority with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.impact:ux-frictionUser-facing flow adds avoidable confusion or support burden without fully blocking progress.issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.no-staleExclude from stale automation

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions