Repository navigation
feat(compactionpoint): read the user's own Claude Code auto-compact setting as C (#948) - #955
Conversation
…etting as C (#948) The plugin's session-start hook reads the settings that move Claude Code's compact point and posts them to a new POST /compaction-config route. The proxy keeps them per session (cg:cpt:, metadata) and resolves C from them before the bootstrap table. The replay cap and the compaction-episode panel read the C the request ran under from two new columns on the request row. Verified on claude 2.1.319: CLAUDE_CODE_AUTO_COMPACT_WINDOW, autoCompactWindow, modelSettings.<model>.autoCompactWindow, CLAUDE_AUTOCOMPACT_PCT_OVERRIDE, DISABLE_AUTO_COMPACT, DISABLE_COMPACT, autoCompactEnabled. Codex and Bob are not read. The client-to-billed factor is 1.0 and is not measured. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
|
Owner decisions on this PR (David Amid, 2026-11-08, given in the session that started this PR):
Assisted-By: Claude Opus 5.5 |
…ce at proxy start (#948) The owner chose to read the setting when the local proxy starts, not per session or per request. The proxy reads the env it inherits plus ${CLAUDE_CONFIG_DIR:-~/.claude}/settings.json and .claude.json, holds the result in memory, and resolves C from it before the table. Hosted mode reads nothing. Removed: POST /compaction-config, the signal.sh report, the cg:cpt: store prefix and its purge, the per-session lookup. Kept: the dash columns, the replay-cap and episode use, ClaudeCode.Resolve. New switch: CONTEXT_GURU_CLIENT_COMPACT_CONFIG=off. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| 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.319 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | bbb237786b7f |
blocking |
Verdict: blocking
Findings
-
proxy/proxy.go:864 — the /compact endpoint runs under the configured C but records none on its row
- What fails: a local user with a setting (say
CLAUDE_CODE_AUTO_COMPACT_WINDOW=200k) calls/compact. The pipeline gates on C = 167,000 (apply.Opts.CompactionPoint, proxy/proxy.go:864). But the capture made at proxy/proxy.go:847 never getsnoteCompactionPoint, socapture.finish(proxy/dashcapture.go:514-517) stores nocompaction_point. The dashboards then read the table C for those rows (haiku: 199,200). The episode span and the replay cap use a C the run did not use. That is the exact divergence the newnoteCompactionPointcomment says it exists to prevent./compactis the offline replay/eval endpoint, so measurement is its whole purpose. - Proof:
grep -rn noteCompactionPoint proxy/*.gogives one caller, proxy/proxy.go:1293 (the chat path). The chat path notes it; the compact path (proxy/proxy.go:847-875) does not. - Fix: resolve the point once into a variable in
compact, pass it to bothapply.Optsfields, and callcp.noteCompactionPointwith it. This also removes the doublecompactionPointForcall on lines 864-865.
- What fails: a local user with a setting (say
-
dash/compactepisode.go:1113 — the episode walk's configured-C behavior has no test
- What fails:
episodeConversationPointis new logic (newest configured row wins,Frac = Abs / window,window > 0guard) andwalkCompactEpisodesnow calls it (dash/compactepisode.go:505). Nothing tests it. The replay walk gotTestReplayCapUsesTheUsersOwnCompactionPoint(dash/replaycap_test.go:675); the episode walk got nothing. A regression in the Frac recompute or the row selection would change published savings figures with no test failing. - Proof:
grep -n CPoint dash/compactepisode_test.gogives no matches.dash/compactepisode_test.gohas 38 tests; none setsCPoint/CPointSourceon acompactRow. - Fix: add a walk-level test like the replay one: same rows twice, table C versus configured C, assert the span and the reported ceiling change.
- What fails:
-
dash/replaycap.go:269 — the per-model ceiling maps are overwritten by each conversation, so the ledger can report a C no conversation used
- What fails:
out.CeilingFrac[model] = ceilruns per conversation. Before this PR every conversation of a model gave the same value, so the overwrite was invisible. Now conversations differ (the code itself says the setting can change between sessions). With one configured conversation followed by one table conversation on the same model,CeilingFracends at the table frac whileCeilingConfiguredstill holds the earlier configured limit — a pair that disagrees with itself. The field exists so "the dashboard shows which one it was"; it can show a stale one. The credit math itself is per-conversation and stays correct. The episode panel has the same class:noteCeiling(dash/compactepisode.go:1125) keeps the first conversation's ceiling per model and drops the rest. - Proof: dash/replaycap.go:266-272 —
cptandlimitare per conversation, the map writes are per model.CeilingConfiguredis written only insideif cpt.Source == Configured, never cleared by a later table conversation. - Fix: keep one entry per distinct value (or per model+source), or write only when the key is absent, and say in the field doc that it is the first/last conversation's value.
- What fails:
-
cmd/context-guru-proxy/claudecompact.go:22 — a failed
UserHomeDirmakes the read look in the proxy's working directory- What fails:
home, _ := os.UserHomeDir()drops the error. Withhome == "",filepath.Join(home, ".claude", "settings.json")(proxy/compactioncfg.go:76-79) becomes the relative path.claude/settings.json. A proxy started with HOME unset, from a session hook whose working directory is the project, then reads the project's.claude/settings.json. The design says project settings files are NOT read, and the point's note would misattribute the source. The error path is rare, and the direction is fail-open, but it breaks a stated boundary. - Proof: cmd/context-guru-proxy/claudecompact.go:22 ignores the error; proxy/compactioncfg.go joins on
homewith no empty check. - Fix: in
claudeCompactAtStart, returncompactionpoint.ClaudeCode{}whenhome == "".
- What fails:
Non-blocking
- proxy/proxy.go:864-865 calls
h.compactionPointFor(body, window)twice; each call re-parses the model out of the body and re-runsResolve/For. Resolve once (covered by finding 1's fix). - Stale source lists:
apply/opts.go:56,proxy/modes.go:103and theClientCeilingUsed.Provenancedoc (dash/compactepisode.go:1103) say the source is "measured" | "assumed" | "window_fallback". A fourth value,configured, now exists. readSmallcaps a file at 4 MiB (proxy/compactioncfg.go:117-119). A heavy user's~/.claude.jsoncan exceed that, soautoCompactEnabledis then silently missed and C falls back to the table. Safe direction, but worth a line in the how-to doc.- The behavior change is named at the top of the PR, with the owner's approval and a data-dependence row. That follows the repo rules.
What I checked
- The full diff
f43d9fa5..bbb23778, both commits, and the code around every change:internal/compactionpoint(both files),proxy/compactioncfg.go,proxy/proxy.go(chat, compact, applyMode),proxy/modes.go,proxy/dashcapture.go,cmd/context-guru-proxy, all five dash files, and both docs. - Column/placeholder/argument counts of the new
insertBatchstatement: 91 columns, 91 placeholders, 91 arguments (dash/store.go:573-672). The three positional scans (requestCols,capSelect,compactEpisodeSelectTmpl) match their select lists. Point.Tokenswith the newAbsshort-circuit: only Configured points setAbs; every table path still scales by window. The disable case with an unknown window records 0, and the dash guards (CPoint > 0) fall back to the table — fail open.assumedWindowForalways returns a positive window, so the newlimit / float64(w)inwalkCapConversationcannot divide by zero.- Hosted mode:
claudeCompactAtStart(tenants == nil)andcompactionPointFor's ownTenants == nilcheck agree; a hosted proxy reads nothing. The bifrost adapter leavesOptions.ClaudeCompactzero, so it is unchanged. - Library boundary:
internal/compactionpointimports onlyinternal/modelinfo, neverproxy. - Privacy: only short setting values are read (32-char cap, 16 modelSettings entries, 4 MiB file cap); nothing but a number and a source string reach the database.
- The new tests in
internal/compactionpoint,proxyanddash/replaycap_test.go: logic traced by hand, arithmetic checks out (167,000 = 200,000 - 33,000; 90,000 = floor(180,000 x 50/100)). - Live tests were not run (not approved; no Go on this machine).
amiddavid
left a comment
There was a problem hiding this comment.
| 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.319 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | bbb237786b7f |
blocking |
Verdict: blocking
Findings
- dash/compactepisode.go:1113 — the episode walk's new configured-C path has no test
- What fails:
episodeConversationPointchanges the compaction-episode span and the summarize savings headline for a user who set Claude Code's compaction point. No test covers a row withCPointSource == "configured"flowing throughwalkCompactEpisodes. A wrongFracthere (for exampleAbsdivided by the wrong window, or a missing guard) would skew a published savings figure, and no test would fail. - Proof:
grep -rn "CPoint\|episodeConversationPoint" dash/*_test.goreturns nothing outsidereplaycap_test.go.dash/compactepisode_test.gohas 38 tests; none setCPointorCPointSource. The twin change indash/replaycap.godid get a test (TestReplayCapUsesTheUsersOwnCompactionPoint, replaycap_test.go:254), so the episode side is the one half of the same feature left untested. - Fix: add one test in
compactepisode_test.go, next to the replaycap one: two walks over the same rows, one withCPoint = 0and one withCPoint = 200_000, CPointSource = "configured". Assert the span narrows (NoAttributableSpanor the episode count changes) andAssumptions.ClientCeilingsreports sourceconfiguredwithFrac = Abs / window.
- What fails:
Non-blocking
- proxy/dashcapture.go:515 — a row can store
compaction_point = 0withcompaction_point_source = 'configured'. This happens when the user turned auto-compact off and the model window is unknown:Resolvereturns sourceconfigured,Tokens(0)returns 0. The schema comment (dash/schema.go:293) says "0 and '' otherwise". Every reader guardsCPoint > 0, so no wrong output today. Suggest: also requirec.cpoint > 0infinish, or fix the comment. - proxy/compactioncfg.go:817 —
readSmallskips~/.claude.jsonabove 4 MiB. That file grows past 4 MiB for long-time users. A missedautoCompactEnabled: falsethen falls back to the table. The fail-open direction costs at most 0.4% of the window on haiku and nothing on opus/sonnet, so the impact is small. Worth a note in the doc. - proxy/proxy.go:847 (the
/compactendpoint) — its capture never callsnoteCompactionPoint, so rows written by/compactcarry no configured C, while the gate on that endpoint uses it. Offline replay rows then read the table C in later dashboard walks. Minor inconsistency on an eval endpoint. - internal/compactionpoint/claudecode.go:511 —
modelSettingsmatching is substring, longest first. A settings keyclaude-opus-5also matches a request modelclaude-opus-5-1. This follows the table's own matching style inFor, so it is consistent; but it can apply one model's window to a newer model the user did not configure. - Local mode applies the Claude Code setting to every model, including non-Claude-Code agents that share the local proxy (the test at proxy/compactioncfg_test.go:936 states this is intended). A Codex request on the same local proxy gets a C derived from Claude Code settings. Bounded: it can only lower C, which fires the trigger earlier.
- Stale doc comments:
apply/opts.go:56andcomponents/component.go:674say the source is"measured" | "assumed" | "window_fallback";dash/compactepisode.go:1103says"measured", "assumed" or "default". All three now also carryconfigured.
What I checked
- Read the full diff (18 files, both commits) and the code around each change:
internal/compactionpoint,proxy/compactioncfg.go,proxy/dashcapture.go,proxy/proxy.go(chat, compact),dash/{compactepisode,replaycap,query,store,schema,event}.go,cmd/context-guru-proxy. - Traced
Resolveagainst its own test table and the documented client rules (window clamps,min(model, configured)window, percent can only lower, disable beats window). All 17 test cases arithmetic-check by hand. - Verified the SQL column/placeholder/argument counts in
dash/store.goinsertBatch: 91 columns, 91 placeholders, args appended in the same position. Verified the two new SELECT columns match their Scan order incompactepisode.goandreplaycap.go. - Verified conversation grouping and ordering: both walks see rows ordered by (tenant, session, model, ts, id), so the newest configured row is the last one, as both
*ConversationPointloops assume.conv[0].Modelis the whole conversation's model in both walks. - Checked
Point.TokenswithAbs: all table points haveAbs = 0, so old callers are unchanged (TestForIsUnchangedByTheNewFieldscovers the table). A configured C can never exceed the table value except the disable path, which equals the window. - Checked fail-open:
ReadClaudeCompactnever fails; bad JSON, wrong types, oversize values and the off-switch all give the zero value (tested).compactionPointForcannot panic and falls back toFor(model). - Checked the rules of the repo: data-dependence row added with a decision and date; behavior change named at the top of the PR with the owner's approval and an off-switch; hosted mode reads nothing (
Tenants != nilguards both the start-up read and per-request resolve); no library package importsproxy; the store/migration is additive with defaults that make old rows read as before. - Confirmed the replay-cap test's numbers by hand (counterfactual close on row 3, counted 2, past 2, ceiling 0.2).
- Did not run builds or tests (not approved). Read the PR description; no PR comments or the other review were read.
- /compact resolves C once and records it on its row. - Add a walk-level test for the episode walk; keep one ceiling entry per model and source in both ledgers. - No home directory, or a relative CLAUDE_CONFIG_DIR: read env only, never a project file. - Apply the setting only to requests with a Claude Code User-Agent. - Write compaction_point_source only when the point is above 0. - Fix the stale source lists; document the 4 MiB file cap. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
|
Reply to reviewer 1, round 1. Head
|
|
Reply to reviewer 2, round 1. Head
|
amiddavid
left a comment
There was a problem hiding this comment.
| 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.319 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 102eee6e4670 |
approve |
Verdict: approve
Findings
None. Every round-1 finding is fixed or answered, and the fix commit introduces no new defect I could find.
Round-1 findings, checked one by one
Mine (reviewer 2):
- Episode walk had no test — fixed.
TestEpisodeWalkUsesTheUsersOwnCompactionPoint(dash/compactepisode_test.go:1393) walks the same rows twice: table C gives frac 1.0 and span 0.10; configured C 950,000 gives frac 0.95 (=Abs / window) and span 0.05; a C below the fill givesNoAttributableSpan = 1.TestEpisodeCeilingsAreReportedPerModelAndSourcecovers the mixed-source case. I traced the arithmetic againstrow/fresh/savedandexactWindow(1,000,000): the spans (100,000 and 50,000) and the closes (row 3, and row 2 on the inclusive boundary) check out. compaction_point = 0with sourceconfigured— fixed.finishnow also requiresc.cpoint > 0(proxy/dashcapture.go:515). The stored invariant now matches the schema comment.- 4 MiB cap undocumented — fixed. The how-to doc says a larger file is skipped and C falls back to the table.
/compactrecorded no C — fixed.compactresolves C once intocpoint, passes it to bothapply.Optsfields, and callscp.noteCompactionPoint(proxy/proxy.go:851-853). This also removes the double resolve.TestCompactEndpointRecordsTheConfiguredPointposts a Claude Code and a Codex request and reads both rows back; only the Claude Code row carries a configured C.- Substring
modelSettingsmatch — kept, with a reason. The author says the client itself matches a canonical model name against dated and variant spellings, and the rule now has a comment naming the effect (proxy/compactioncfg.go:140). The style matchescompactionpoint.For's own table. I accept: the effect is documented, bounded, and consistent with the client. - Setting applied to every agent — fixed.
compactionPointFornow takes the request and applies the setting only whendash.AgentForsaysclaude-codeorclaude-cli. Codex, Bob, unknown clients and empty User-Agents get the table (tested for all four). The stated limit — the User-Agent is the client's own claim, and the Claude Agent SDK sends the same one — is honest; I know of no stronger signal either. - Stale source lists — fixed in
apply/opts.go,components/component.go,proxy/modes.goandClientCeilingUsed.Provenance.
Reviewer 1's findings, checked myself:
/compactrecords no C — fixed (same change as my 4; verified above).- Episode walk no test — fixed (same as my 1).
- Ceiling maps overwritten per conversation — fixed.
CeilingFracnow holds only table conversations,CeilingConfiguredonly configured ones, andnoteCeilingkeeps one entry per model and source (dash/replaycap.go:272-277, dash/compactepisode.go:1128).TestReplayCapCeilingMapsAgreeWhenSourcesMixwalks both orders; the two maps agree in both. The field docs state the last-walked rule forCeilingConfigured. - Failed
UserHomeDir— fixed. With no home,ReadClaudeCompactreads env only; a relativeCLAUDE_CONFIG_DIRis not read either (proxy/compactioncfg.go:56-61).TestReadClaudeCompactReadsNoFileWithoutAHomeplants a project.claude/settings.jsonin the working directory and arel/settings.json, and proves neither is read — without the guards both files would be picked up.
Non-blocking
- dash/compactepisode.go:305 — the
ClientCeilingsfield comment still says "one entry per model".noteCeilingnow keeps one entry per model and source, so a model with both a configured and a table conversation has two. ThenoteCeilingcomment says so; this field comment is one round behind. - The User-Agent gate is a real behavior narrowing added after the owner's approval was given. Against the merge base it changes nothing for non-Claude-Code agents (they used the table before this PR too), and it moves only in the safe direction, so I read it as a review fix inside the approved feature, not a new behavior change needing approval. Naming it here so the owner can see it.
What I checked
- Last review: round 1, bbb2377, 2026-11-08T15:39:19Z.
- New commits read: 1 —
102eee6e"fix(compactionpoint): review round 1 on the start-up read (#948)". Full diffbbb23778..102eee6eread, plus the code around each change. - Read in full: 2 reviews, 3 comments, 0 inline comments (from the three files; the inline file is empty).
- New items since my last review: the fix commit; the author's two reply comments (16:06:39Z and 16:06:40Z) answering reviewer 1 and reviewer 2; the earlier owner-decisions comment (15:01:07Z) predates my round-1 post and was already covered by the PR body. Each reply was checked against the code as written above.
- Verified the new tests' helpers exist and their arithmetic:
exactWindow= 1,000,000;rowmodel "m" (unlisted → table frac 1.0); spans 100,000 / 50,000; the inclusive span boundary closes the configured episode on row 2;dash.AgentForclassifies the four test User-Agents as claude-cli / codex / curl / unknown. - Verified all
compactionPointForcallers pass the request and thatr != nilis guarded;proxyimportingdashbreaks no boundary (proxy already imports dash). - Verified the no-home path end to end:
claudeCompactAtStartpasseshome = "",ReadClaudeCompactreturns env-only whendir == "" && home == "", and an absoluteCLAUDE_CONFIG_DIRstill works with no home. - Checked the commit message carries DCO sign-off and
Assisted-By:. - Live tests were not run (not approved). Mutation claims in the author's replies are taken as claims, not verified; the tests themselves were read and their assertions traced by hand.
amiddavid
left a comment
There was a problem hiding this comment.
| 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.319 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 102eee6e4670 |
approve |
Verdict: approve
Findings
None. All four round-1 findings are fixed, and the fix commit adds no new defect I can show.
Round-1 findings, re-checked
- /compact records no C — fixed.
compactnow resolves C once (proxy/proxy.go:851), passes it to bothapply.Optsfields (proxy/proxy.go:867-868) and tocp.noteCompactionPoint(proxy/proxy.go:852). The double resolve is gone too.TestCompactEndpointRecordsTheConfiguredPointposts to/compactwith a Claude Code and a Codex User-Agent and reads both rows back: the claude-cli row carries sourceconfigured, the codex row carries nothing. I checked the test's helpers and API calls against the existing code (anthropicRequest,waitForRows,fixedPricer,DB.Requests) — all exist and match. - Episode walk untested — fixed.
TestEpisodeWalkUsesTheUsersOwnCompactionPointwalks the same rows on the table C and on a configured C. I re-derived its numbers: window 1,000,000, fill 0.90; table (model "m" unlisted) gives frac 1 and span 0.10; configured 950,000 gives frac 0.95 (Abs / window) and span 0.05, and the episode closes one turn earlier; 850,000 givesNoAttributableSpan = 1. All three assertions are arithmetic on the walk's own rules.TestEpisodeCeilingsAreReportedPerModelAndSourcecovers the mixed-source report. - Ceiling maps overwritten — fixed.
CeilingFracis now written only by table conversations andCeilingConfiguredonly by configured ones (dash/replaycap.go:272-277), so the two maps cannot disagree. The "last walked" rule for a changed setting is stated in the field comment.noteCeilingkeeps one entry per model and source (dash/compactepisode.go:1128-1131).TestReplayCapCeilingMapsAgreeWhenSourcesMixruns both walk orders. - Empty HOME reads the CWD — fixed.
claudeCompactAtStartreturns env-only read whenUserHomeDirfails or is empty (cmd/context-guru-proxy/claudecompact.go:16-21).ReadClaudeCompactalso refuses a relativeCLAUDE_CONFIG_DIR(proxy/compactioncfg.go:58-63). I checked the test's mutation sensitivity by hand:TestReadClaudeCompactReadsNoFileWithoutAHomeputs a real.claude/settings.jsonin the working directory undert.Chdir, so removing either guard makes the read find the file and the test fail.
Reviewer 2's findings, re-checked
- Episode walk untested — fixed, same test as my finding 2. Agree.
compaction_point = 0with sourceconfigured— fixed:finishnow also requiresc.cpoint > 0(proxy/dashcapture.go:515).- 4 MiB cap — documented in the how-to (docs/how-to/agent-compaction.md:77-79). Accept.
/compactrecords no C — fixed, same change as my finding 1.- Substring match on
modelSettings— kept by the author, with the effect documented oncompactionPointFor. I accept the reason: it is the same matching style ascompactionpoint.For's own table, and the comment says the client uses the same rule for its canonical model name. - Setting applied to every agent — fixed beyond what was asked:
compactionPointFornow applies the setting only to requests whose User-Agent classifies asclaude-codeorclaude-cli(proxy/compactioncfg.go:146-160). I readdash.AgentFor(dash/event.go:1239-1264): lowercase contains-match, so "claude-cli/2.1.319 (external, cli)" and "codex_cli_rs/0.160.0" classify as the test expects, and no User-Agent gives "unknown" → the table. This narrows the approved behavior change to Claude Code clients only, which is closer to the owner's approval, not further from it.
Non-blocking
Options.ClaudeCompact's comment (proxy/proxy.go:65-68) says only "Ignored when Tenants is set". It is now also ignored for requests without a Claude Code User-Agent. One line in that comment would save the next reader a look atcompactionPointFor.- In
walkCapConversation,ceilis computed for a configured conversation and then discarded (onlylimitis used, dash/replaycap.go:271-277). Harmless.
What I checked
- Last review: round 1, bbb2377, 2026-11-08T15:38:56Z.
- New commits read: 1 —
102eee6e"fix(compactionpoint): review round 1 on the start-up read (#948)". Full diffbbb23778..HEADread line by line. - Read in full: 2 reviews, 3 comments, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt; the inline file is empty). - New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (15:39) — read; its one finding overlaps my finding 2, its non-blocking list overlaps mine plus two new notes (zero-value row, substring match), both addressed above.
- Owner decisions comment (15:01, before my last review but unread then) — read; approves the behavior change, the data-dependence row, the 1.0 factor and the read-at-start design.
- Author's two reply comments (16:06) — read; each fix claim verified in the code as above.
- Commit
102eee6e(15:45 UTC) — fully reviewed, including the new User-Agent gating, which is new behavior in this commit: I checkeddash.AgentFor's classification, both call sites of the newcompactionPointForsignature, the nil-rguard, the how-to doc update, and that the gate and the recorded row use the same resolved point on both/compactand the chat path.
- Test helpers and APIs used by the new tests verified against existing code:
row/fresh/saved/exactWindow/testPrice/offUSD/only(dash/compactepisode_test.go),anthropicRequest/fixedPricer/waitForRows(proxy/dash_test.go),DB.Requests(dash/query.go:258),New/Mux(proxy/proxy.go:404,520). The new tests' expected numbers re-derived by hand. - Mutation sensitivity of the three new fix tests traced by hand; each fails when its guard or call is removed.
- Live tests were not run (not approved; no Go on this machine).
Comment lines only. ClientCeilings is one entry per model and source. Options.ClaudeCompact applies only to Claude Code requests. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
|
This commit fixes the 2 non-blocking notes from round 2. It changes comments only: no code, test or doc file. Head: diff --git a/dash/compactepisode.go b/dash/compactepisode.go
index 3427f782..6e8c9191 100644
--- a/dash/compactepisode.go
+++ b/dash/compactepisode.go
@@ -302,8 +302,9 @@ type CompactionAssumptions struct {
// SpanRule says WHY the span is the width it is: it is an attribution boundary derived from the
// fill threshold, not a tuning knob. See spanFor.
SpanRule string `json:"span_rule"`
- // ClientCeilings is one entry per model this query actually measured, because the ceiling is a
- // fact about the CLIENT's behaviour on that model and a single number would be an average of
+ // ClientCeilings is one entry per model and source this query actually measured (noteCeiling),
+ // because the ceiling is a fact about the CLIENT's behaviour on that model, and a model can have
+ // both a table conversation and a configured one. A single number would be an average of
// things that are not comparable. Each carries its provenance, so a reader can tell which
// published figures rest on a measurement and which on an assumption.
ClientCeilings []ClientCeilingUsed `json:"client_ceilings"`
diff --git a/proxy/proxy.go b/proxy/proxy.go
index 46584c4c..e546eacc 100644
--- a/proxy/proxy.go
+++ b/proxy/proxy.go
@@ -64,7 +64,8 @@ import (
type Options struct {
// ClaudeCompact is the user's own Claude Code auto-compact setting, read ONCE at start-up in
// local mode (ReadClaudeCompact, #948). The zero value changes nothing. Ignored when Tenants
- // is set.
+ // is set. It applies only to requests whose User-Agent is Claude Code (dash.AgentFor gives
+ // "claude-code" or "claude-cli"). All other requests use the table.
ClaudeCompact compactionpoint.ClaudeCode
OpenAIUpstream string // e.g. https://api.openai.com
AnthropicUpstream string |
|
The approvals of Output of Assisted-By: Claude Opus 5.5 |
Resolve the overlap of #955 (the user's own compaction point as C) with the epoch rule of the replay cap (#940). - dash/replaycap.go: keep CeilingConfigured and capConversationPoint from #955 and the epoch state, ReopenedEpochs and the avoided compaction from #940. The counterfactual ceiling and the avoided price now use the user's own C. - dash/store.go: the requests INSERT has 95 columns, 95 placeholders and 95 bound arguments, counted by script. Neither side's placeholder row was right. - dash/query.go: keep the estimate flags and the two compaction_point scans. - dash/replaycap_test.go: keep both sets of tests. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
Behavior change
This PR changes C for users who changed Claude Code's compaction setting.
CLAUDE_CODE_AUTO_COMPACT_WINDOW,CLAUDE_AUTOCOMPACT_PCT_OVERRIDE,DISABLE_AUTO_COMPACT,DISABLE_COMPACT,autoCompactWindow,modelSettings.<model>.autoCompactWindow,autoCompactEnabled. Users who changed nothing see no change. A hosted proxy reads nothing and is unchanged.frac x C).CONTEXT_GURU_CLIENT_COMPACT_CONFIG=offin the proxy's env. C then comes from the table, as before.Approval: approved by the owner (David Amid) on 2026-11-08. See #955 (comment).
Summary
configured).What changed
internal/compactionpoint: new sourceconfigured.ClaudeCode.Resolveturns the raw settings into C.Point.Absholds an absolute C.Recordedrebuilds a point from a request row. No import ofproxy.proxy/compactioncfg.go(host code):ReadClaudeCompactreads the env and the user's files.Options.ClaudeCompactholds the result.compactionPointForresolves C for each request: the user's value first, else the table.cmd/context-guru-proxy: calls the read once at start, in local mode only.dash: two new columns onrequests,compaction_pointandcompaction_point_source, written only when the user's setting set C. The replay cap and the episode walk read them.When and where it reads
claude-cliorclaude-code). Codex, Bob and unknown clients on the same local proxy use the table. The User-Agent is the client's own claim. The Claude Agent SDK sends the same one, and it reads the same settings, so it is covered on purpose.setsidornohupand noenv -i(start-proxy.sh). The proxy therefore inherits the env of the hook, which is the env of the Claude Code session that started it. A later session with other env values does not change a running proxy.settings.jsonin${CLAUDE_CONFIG_DIR:-~/.claude}and.claude.jsonin${CLAUDE_CONFIG_DIR:-~}.settings.jsonwins over.claude.json. A file over 4 MiB is skipped. With no home directory, or a relativeCLAUDE_CONFIG_DIR, no file is read (env only). Project settings files are not read: they depend on the directory the client runs in, which the proxy does not know.CONTEXT_GURU_CLIENT_COMPACT_CONFIG=off. The earlierCONTEXT_GURU_CLIENT_SIGNALSno longer fits: this design sends no signal.Verified settings (claude 2.1.319, from the shipped binary)
CLAUDE_CODE_AUTO_COMPACT_WINDOW(env)200000,200k,1m. Below 100k becomes 100k. Above 1M becomes 1M. Not a number: ignored. Wins over settings.autoCompactWindow(settings.json)"auto"for the client default.modelSettings.<model>.autoCompactWindow/autocompactwrites it.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE(env)DISABLE_AUTO_COMPACT,DISABLE_COMPACT(env),autoCompactEnabled=falseThreshold in the client's count:
(W - 20,000) - 13,000.Wismin(model window, configured window). The percent applies to(W - 20,000)and the smaller value wins.The ruler
ClientToBilledis one constant. Change it when a measurement settles the question.Data dependence
Metadata only. A few short setting values, held in memory, and a number on the request row. No transcript text, no paths, no other settings. Row in
docs/data-dependence.md.How it was tested
Run on the shared box, Go at
/usr/local/go/bin/go,-race, foreground. Head102eee6e.gofmt -l .,go build ./...,go veton the touched packages: clean.go test -race ./proxy/...: pass (485 s).go test -race ./dash/...: pass (585 s).go test -race ./cmd/... ./internal/... ./apply/... ./components/ ./components/all/: pass.settings.json, orCLAUDE_CONFIG_DIR, or the home guard/compactdoes not record its C on the rowLeft out (follow-ups)
model_auto_compact_token_limitexists in codex 0.160.0. I saw the key name only. Unit and default are not verified.model.compressionThreshold(default 0.5, a fraction) is verified in the bundle. Its ruler is not known.autoCompactWindoware not read.ceiling_configured).Technical notes
Point.TokensreturnsAbswhen set.Foris unchanged.CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE(the hard stop) is not read: it is not the compact point.cg:cpt:key and no purge step.🤖 Generated with Claude Code