Skip to content

[skip-cr] fix: hold the last GPT context value during all-zero usage reports - #14

Merged
vtmocanu merged 2 commits into
mainfrom
fix/gpt-context-stale
Oct 4, 2026
Merged

vtmocanu merged 2 commits into
mainfrom
fix/gpt-context-stale

Conversation

@vtmocanu

@vtmocanu vtmocanu commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Summary

GPT sessions no longer flash a false 0% context reading. A live gpt-6.1-sol session was captured sending 21% -> 0% -> 21%, where the middle payload had every current_usage counter and both totals at zero (used 0%, remaining 100%) with the same model and window. For a GPT effective model, exactly that shape now re-shows the last valid percentage in dim gray (bar and number, both layouts). Every other shape, and all Claude renders, are unchanged. The upstream cause of the zero payload is not proven.

How

  • A private per-session snapshot (ctx-last-<session_id>, mode 600, atomic replace) keeps the last native percentage with its keys (raw and effective model, window, transcript path, input/cache counters).
  • A value is stored only when the transcript shows the matching assistant response after the last compact boundary, so a pre-compaction frame read after /compact is never stored. One embedded Perl helper (core JSON::PP, Digest::MD5), no new process, network or credential.
  • A hold needs every key to match, the same transcript file (device, inode, not shorter, last 4 KB before the recorded size unchanged) and an unchanged compact epoch. Null or missing usage, any other shape, a key change, a failed check, /clear, /compact and Claude renders drop the snapshot.
  • Also corrects Formula.rb.tmpl's dev-mode instructions to honor XDG_CONFIG_HOME.

Testing

  • task ci: syntax, shellcheck, 281 tests in UTF-8 and LC_ALL=C, 75 fetcher tests in both locales; ruby -c Formula.rb.tmpl.
  • Replay of the captured payload shapes: native 21%, held 21% in dim gray, normal color on recovery, a corrupt snapshot falls back to the native 0% with empty stderr.
  • Designed and implemented in session cc-statusline-d1 (design reviewed by cc-statusline-70), handed over to cc-statusline-15 for review and landing.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e5405150-b3bf-4fa0-a517-5654578ec9ef
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

A GPT session was observed reporting a context window with every usage
counter at zero (used 0%, remaining 100%) between two normal readings,
so the bar flashed a false 0%. For a GPT effective model, exactly that
shape now re-shows the last valid percentage in dim gray. The value is
a private per-session snapshot, stored only when the transcript proves
the matching assistant response after the last compact boundary, and
dropped on any key change, compaction, /clear or Claude render.

Also corrects the formula's dev-mode instructions to honor
XDG_CONFIG_HOME.
A failed write, chmod or rename left the older snapshot in place, so a
later all-zero frame could re-show a stale value after a newer reading
had been displayed. Publish only when all three succeed; otherwise
delete the old snapshot as well.
@vtmocanu
vtmocanu force-pushed the fix/gpt-context-stale branch from 70322ad to 7013a53 Compare October 4, 2026 19:15
@vtmocanu
vtmocanu merged commit a287027 into main Oct 4, 2026
2 checks passed
vtmocanu added a commit that referenced this pull request Oct 4, 2026
Repo-wide session counts on line 1 (#13) and the GPT context hold for
all-zero usage reports (#14).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant