Skip to content

fix(plugin): the band's window saving survives the #989 change - #1035

Merged
amiddavid merged 1 commit into
mainfrom
fix/cg-window-saved
Nov 10, 2026
Merged

amiddavid merged 1 commit into
mainfrom
fix/cg-window-saved

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

Why it happens

What changed

Behavior change: none intended; it restores the band's window saving that #1018 added (the owner approved #1018).
Data dependence: none.

How it was tested

🤖 Generated with Claude Code

cg.py defined tokens_text twice. #1018 added tokens_text(stats, human) for
the band. #989 added tokens_text(st) later in the file. The later one
shadowed the first, so status_extras raised a TypeError, swallowed it, and
left window_saved empty. Rename the band's helper to band_tokens_text.
The Codex copy is the same.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 753bcc4430ed approve

Verdict: approve

Findings

None. The change is correct and complete.

What the PR fixes

The base tree had two module-level functions named tokens_text in scripts/cg.py:

  • cg.py:259 — the band's helper, 2 args (stats, human), added by #1018.
  • cg.py:572 — the status/insights helper, 1 arg (st), added by #989.

Python binds the later def, so the 1-arg function won. The call in status_extras
(cg.py:302) passed 2 args. That raised TypeError. The broad except Exception
in status_extras swallowed it. Result: doc["window_saved"] was never set, and
the band lost its 5-hour window saving figure, in silence.

This PR renames the band's helper to band_tokens_text. The later def no longer
shadows it, so the call works again.

What I checked

  • The full diff: 6 lines, 2 files. Both are the same file kept in two copies.
  • The bug at the base: git show a3495863:.../cg.py confirms both def tokens_text
    lines and the 2-arg call. The trace above follows from Python's def order.
  • Every reference to the old name, repo-wide (Go tests, hooks TypeScript, docs):
    only the three sites this PR updates. The 1-arg tokens_text callers
    (cg.py:602, 605, 677, 678, 730) are unchanged and still correct.
  • The two cg.py copies are byte-identical after the change (diff clean).
  • No other duplicate module-level name remains in cg.py (checked all 95 defs
    and module constants for duplicates: none).
  • The existing Go tests cover the fixed path:
    cg_cachestate_test.go:19 and :42 assert window_saved. Their own comment
    says they exist to catch exactly this silent-blank failure. No new test needed.
  • python3 -m py_compile passes on both files (syntax only; live tests not run,
    as this review does not approve them).

Non-blocking

  • The collision was introduced by #1018 (d058b33), and the tests that cover it
    already existed then. They should have failed on #1018's head. Confirm those
    tests run in CI on PRs that touch cg.py; if they were green on #1018, they are
    not running where they should.
  • The two names stay close (tokens_text vs band_tokens_text), so the same
    collision can recur. A redefinition check (ruff F811) over scripts/*.py would
    catch this class at write time. No lint config covers the plugin scripts today.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 753bcc4430ed approve

Verdict: approve

Findings

None. The fix is correct, complete, and covered by tests that already exist.

Non-blocking

  • Why was #1018 CI green? The tests TestCGCachestateCarriesTheStatusLinesExtras and TestCGCachestateWindowTokensByCase came in with #1018, and they run python3 scripts/cg.py cachestate as a real subprocess. With the shadowing bug, both must fail: window_saved stays empty. Yet #1018 reports "CI green". Something in that CI run did not run these tests, or ran a stale tree. Please open an issue for it. The same blind spot can hide the next bug.

What I checked

  • The defect, proven. At base a3495863, cg.py defines tokens_text twice at module level: line 259 with 2 arguments (from #1018) and line 572 with 1 argument (from #989). I confirmed this with a Python AST scan of git show a3495863:context-guru-plugin/scripts/cg.py. Python binds the later def, so the call tokens_text(mine, sl._human) at line 302 raises TypeError. The except Exception: pass at line 305 swallows it. window_saved is never set, so the band loses its window saving. This matches the commit message.
  • The fix, verified. At HEAD the 2-argument function is band_tokens_text (line 259). It has exactly one caller, line 302, with 2 arguments. The 1-argument tokens_text (line 572) keeps its callers at lines 602, 605, 677, 678, 730 — all pass 1 argument. A repo-wide grep finds no other reference to either name, in Python, TypeScript, docs, or JSON.
  • No other shadowing. An AST scan of cg.py and statusline.py at HEAD finds no other duplicate top-level names.
  • Both copies match. codex-marketplace/plugins/context-guru/scripts/cg.py and context-guru-plugin/scripts/cg.py are byte-identical. TestCGScriptsAreVendoredIntoCodex enforces this.
  • Tests cover the fix. The two cachestate tests run the real script against a stub proxy and assert window_saved by tier, including the pre-#999 fallback. They fail at base and pass with the rename. The PR needs no new test: it restores behavior that #1018's tests already pin.
  • Repo rules. Fail-open is untouched: status_extras still swallows decoration errors by design, and the band still shows the rest of the doc. No data-dependence change: metadata only, same as before. No behavior change beyond restoring what #1018 documented and the owner approved. Commit has the DCO sign-off and Assisted-By: attribution.

@amiddavid
amiddavid merged commit 77a910b into main Nov 10, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 10, 2026
boazdavid added a commit that referenced this pull request Nov 10, 2026
Brings the band window-saving fix (#1035).

Assisted-By: Claude (Anthropic AI) <[email protected]>
amiddavid added a commit that referenced this pull request Nov 11, 2026
…0.2.12, Pi 0.1.1)

Claude Code plugin 0.6.7 -> 0.7.2:
- #981, #989, #1018, #1035: subscription band and savings show saved tokens.
- #1038: insights drop the finding that credits a user's own removal.
- #1039, #1040: dash and keep-alive fixes that touch the plugin files.

Codex plugin 0.2.11 -> 0.2.12:
- #1051: read the cache strategies and presets from the proxy.
- The vendored cg.py gets the same plugin changes.

Pi package 0.1.0 -> 0.1.1:
- #1010: chain the proxy in front of an existing base URL.
- #1011: check the proxy at session start and restart it once.
- #1049, #1058: write the cache strategy by name; review fixes.

OpenCode plugin (#483): new in v0.7.2, no version file, not changed.
Bob plugin 0.1.0: no change since v0.7.1, not changed.

Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 11, 2026
Bump the plugin versions for v0.7.2.

- Claude Code plugin 0.6.7 -> 0.7.2: #981, #989, #1018, #1035 (savings
  in tokens on a subscription), #1038, #1039, #1040, #1055 (cache
  strategies read from the proxy).
- Codex plugin 0.2.11 -> 0.2.12: #1051 (cache strategies and presets
  read from the proxy), plus the vendored cg.py changes.
- Pi package 0.1.0 -> 0.1.1: #1010, #1011, #1049, #1058, and the #1040
  README line.
- OpenCode plugin: new in v0.7.2 (#483), no version file. Its first
  start now downloads proxy v0.7.2 (was v0.7.1). Nothing compares
  against PINNED_VERSION; the floor stays "v0.7.1 or later". The README
  lines, the install guide and 3 tests follow.
- Bob plugin: 0.1.0, no change since v0.7.1.

Behavior change: the OpenCode plugin's first download is proxy v0.7.2,
not v0.7.1. Owner's yes, 2026-11-11, in the integrator session: "option1
it is"; the version bumps: "I approve the version bumps for the
plugins".

Data dependence: none.

Reviews: 3 offload review rounds (GLM; round 3 pre-approved by the
owner). Both reviewers approve at 3cf6176, which is the PR head.

Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant