Skip to content

feat(context-guard): bands follow a lowered auto-compact window - #12855

Merged
kyle-sexton merged 5 commits into
mainfrom
fix/12271-context-guard-compact-window
Nov 3, 2026
Merged

kyle-sexton merged 5 commits into
mainfrom
fix/12271-context-guard-compact-window

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #12271

Summary

context-guard's percentage bands were percentages of the model's full window. A lowered autoCompactWindow or CLAUDE_CODE_AUTO_COMPACT_WINDOW therefore let auto-compact fire while the zone still read smart. The mod now scales its bands to the window the engine actually compacts at.

Fix

  • hooks/register.tsx: reads the effective window from the usage breakdown's rawMaxTokens, which refresh() already requests, so no new call. When that window is below the model's, the percentage edges, thresholds and approach margin scale by the ratio. The snapshot and status tool publish the scaled edges plus bands.auto_compact_window. At session.end the breakdown is absent, so the bands stay unscaled there.
  • hooks/zone.ts: an optional follow argument only; its fixture match with the shell resolver holds.
  • README and reference/reader-contract.md: a lowered window needs no hand retune of zones.json. The shell resolver does not follow the window yet, tracked in fix(context-guard): the shell zone resolver ignores a lowered auto-compact window #12854.
  • Changelog fragment (minor): anyone who retuned zones.json by hand for a lowered window should undo it, or the mod scales the retune a second time.

Why rawMaxTokens and not $.settings.read / $.env.get: those return raw values only and resolve no precedence. A per-model modelSettings window reads undefined at the top-level key. Basis: the probe in #12271 (comment).

Version bump: minor. Default sessions are unchanged (probe baseline: rawMaxTokens 1000000, source model-default), and the change acts only under an operator-lowered window.

Verification

  • context-guard.test.ts: 4 new cases with hand-computed expectations. 3 fail on the old register.tsx and zone.ts; the 4th is the control (window at or above the model's) and passes either way. claude plugin test: 303 of 303 pass.
  • scripts/check-affected.sh: 12 passed, 3 skipped.
  • Probe on melo-lap-001 WSL, Claude Code 2.1.317: the four cases (baseline, env, settings, per-model) in the issue comment above.

Remaining

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits November 3, 2026 11:02
The percentage bands were percentages of the model's full window, so a
lowered autoCompactWindow or CLAUDE_CODE_AUTO_COMPACT_WINDOW let
auto-compact fire while the zone read smart. The mod already asks
$.session.usage for the breakdown, whose rawMaxTokens is the window the
engine settled on (env, settings, per-model). When it is smaller than
the model's window, the module scales the percentage edges, thresholds
and approach margin to it and publishes bands.auto_compact_window.
Token bands and the shell resolver are unchanged.

Refs: #12271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 3, 2026 16:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T16:09:41.384876Z 39041e0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 67c7eb6b297757bc1d743f14ab12f1bcbc4ddca2: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #12855 (context-guard bands follow a lowered auto-compact window)

I found no security issues. I read every hunk of all 6 changed files in .claude-lane/pr.diff, so this review covers the whole pull request.

What changed since the last review

  • plugins/context-guard/hooks/register.tsx:
    • A threshold now records two values. at is the scaled edge. at_percent is the operator's unscaled value from zones.json.
    • The fired set and the approach key are now keyed on at_percent, and the comparison uses at. This fixes the earlier threshold-refire thread in register.tsx.
  • The changelog fragment now says bump: major. This answers the earlier bump-level thread.
  • The tests add a case where the window changes mid-cycle.
  • The rest is unchanged from the head reviewed before (39041e07):
    • zone.ts has the pure helpers ofWindow and followWindow, and resolveZone takes an optional follow callback. The sid regex check and the snapshot parse are unchanged.
    • refresh() reads c.breakdown?.rawMaxTokens and scales the bands with followSettings.
    • The snapshot and the status tool publish an optional numeric auto_compact_window.

Trust boundary and data flow

  • Where the input comes from: rawMaxTokens comes from the Claude Code engine's usage breakdown. It reflects CLAUDE_CODE_AUTO_COMPACT_WINDOW, autoCompactWindow or a per-model setting, which only the operator sets. No pull request, issue or comment author reaches it.
  • What a bad value can do:
    • ofWindow scales only when 0 < compactWindow < window, so any other value leaves the edges as they were.
    • The number ends up only in JSON written with JSON.stringify and in a status string.
    • The diff adds no shell call, file path or template.
  • Effect of the threshold key change: it changes only which session-scoped numeric keys sit in the fired set and the approach set. No path or command is built from them.
  • Severity bar: none of the three impacts applies. Nothing leaks, nothing is compromised and nothing can bill.

Controls and instruction surfaces

  • Trust controls: none of the 6 files matches a TRUSTED PATHS glob. The diff touches no trusted-trigger, token, kill-switch or merge-hold control.
  • Plugin manifests: no plugin.json or marketplace.json changed, so there are no manifest <field> lines.
  • Instruction surfaces:
    • The README and reference/reader-contract.md edits change how the docs describe band scaling. They remove no guardrail.
    • The protected-class register was not needed because no standing instruction was deleted or narrowed.
  • Embedded text: the PR context and the settled threads contain no text aimed at this lane.
  • Settled threads: both threads are addressed in the code, as described above. Neither raised a security point, and I raise nothing again.

Spend

This change can cause no real charge.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 2 inline finding(s) on 39041e07f0e7ddc9de9c5b24b73e36f4b6b48fca; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 67c7eb6b297757bc1d743f14ab12f1bcbc4ddca2: read 6 of 6 changed file(s); 0 finding(s), 0 as inline comments.

Code review: context-guard bands follow a lowered auto-compact window

I found nothing new to block on, and both findings from the last round are fixed. I read every hunk of all 6 changed files. I also read the code around them in register.tsx: recordReading, renderEvent/renderAll, loadSettings, refresh, statusText and statusJson.

Last round's findings, both fixed at this head:

  1. Bump level. The fragment now says bump: major and starts its entry with "Breaking:". fragment#L2
  2. Threshold fired twice after a mid-session window change. Threshold now carries the unscaled at_percent. s.fired and the approach key t${at_percent} use it, and the scaled at is used only in the comparisons. register.tsx#L237, #L251-L253, #L273-L275. The new test "a threshold that fired stays fired when the window changes mid-cycle" covers this: the threshold fires at 31%, then the window grows to the model's, and 61% emits nothing. On the old keying, the scaled edge would have moved from 30 to 60 and the line would have fired again.

The prior-findings file marks the threshold entry lines changed since posted: no, but the problem it describes is gone at this head, so I did not repost it.

Checked by hand:

  • The status-tool test expects 20/30 with margin 2 on a 1M window with a 400k compact window, which matches ofWindow.
  • The fixed-threshold test: 60 of 100k on a 200k window gives 30, and growing the window to the model's gives 60.
  • follows publishes auto_compact_window only when the compact window is smaller than the model's.

Not counted:

  • One row the PR didn't touch now contradicts it. The autoCompactWindow row of the tunable table still says a window "set where we cannot see it, we assume no number (below)". The "below" it points to now reads "The module follows the effective window", so that sentence is true only of the shell resolver. reader-contract.md#L471
  • The token-shape approach check (settings.margin * tok.size / 100) now uses the scaled margin as well, so the approach margin before a token edge also shrinks under a lowered window. The docs say the approach margin scales, so this looks intended, but "token bands … stay as set" does not cover the margin.
  • The module and scripts/context-zone.sh will disagree under a lowered window. That is documented, and the PR tracks it in fix(context-guard): the shell zone resolver ignores a lowered auto-compact window #12854.

Closing issue. The PR says Refs: #12271, which is not a closing keyword, and the PR context file has no closing-issue section, so there are no acceptance criteria to check. The PR body says done-when item 1, the probe on the other machines, is still to do.

Verification. The test counts (303/303), the check-affected.sh result and the Claude Code 2.1.317 probe are the author's claims; I could not check them, because this lane has no shell.

No plugin manifests changed, no changed file matches a trusted path, and the PR context and thread text hold no embedded instructions.

kyle-sexton and others added 3 commits November 3, 2026 11:29
Conflict in plugins/context-guard/reference/reader-contract.md: keep the
branch's paragraph on the module scaling the percentage bands, with main's
"We read a firing diagnostically" wording and its PreCompact hook pointer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A threshold's edge now scales with the auto-compact window, so keying the
once-per-cycle bookkeeping (fired set and approach key) on the scaled edge
let a threshold fire again when the window changed mid-cycle. Key it on the
unscaled zones.json at_percent; crossing still compares against the scaled
edge. New test: a threshold that fired stays fired when the window changes
mid-cycle.

The changelog fragment becomes a major bump: under a lowered auto-compact
window, zones.json percentages and thresholds[].at_percent now read as
percentages of that window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous push reached the branch, but the pull request kept its old
head, so CI did not run on it. This empty commit makes GitHub re-read the
branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 826b84a Nov 3, 2026
64 of 65 checks passed
@kyle-sexton
kyle-sexton deleted the fix/12271-context-guard-compact-window branch November 3, 2026 17:12
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