Skip to content

feat(compactionpoint): read the user's own Claude Code auto-compact setting as C (#948) - #955

Merged
amiddavid merged 4 commits into
mainfrom
feat/harness-compact-point
Nov 8, 2026
Merged

amiddavid merged 4 commits into
mainfrom
feat/harness-compact-point

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior change

This PR changes C for users who changed Claude Code's compaction setting.

  • Who: local-mode Claude Code users who set one of: 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.
  • Old: C came from a fixed table (0.996 of the window on haiku, 1.00 elsewhere).
  • New: C is the user's own threshold. With auto-compact off, C is the model window.
  • What moves: the replay cap, the compaction-episode span, and the summarize trigger (frac x C).
  • Turn off: set CONTEXT_GURU_CLIENT_COMPACT_CONFIG=off in 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

What changed

  • internal/compactionpoint: new source configured. ClaudeCode.Resolve turns the raw settings into C. Point.Abs holds an absolute C. Recorded rebuilds a point from a request row. No import of proxy.
  • proxy/compactioncfg.go (host code): ReadClaudeCompact reads the env and the user's files. Options.ClaudeCompact holds the result. compactionPointFor resolves 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 on requests, compaction_point and compaction_point_source, written only when the user's setting set C. The replay cap and the episode walk read them.
  • No plugin change. No new route. No stored per-session copy.

When and where it reads

  • When: once, at proxy start. A setting changed while the proxy runs takes effect at the next proxy restart.
  • Which requests: only requests with a Claude Code User-Agent (claude-cli or claude-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.
  • Env: the plugin starts the proxy from the SessionStart hook with setsid or nohup and no env -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.
  • Files: settings.json in ${CLAUDE_CONFIG_DIR:-~/.claude} and .claude.json in ${CLAUDE_CONFIG_DIR:-~}. settings.json wins over .claude.json. A file over 4 MiB is skipped. With no home directory, or a relative CLAUDE_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.
  • Hosted proxy: reads nothing (compactionpoint: in proxy mode, detect a changed compaction point from the traffic #949 covers detection there).
  • Fail open: a missing file, bad JSON, a wrong type, an oversize value, or an odd number gives the table value.
  • Switch: CONTEXT_GURU_CLIENT_COMPACT_CONFIG=off. The earlier CONTEXT_GURU_CLIENT_SIGNALS no longer fits: this design sends no signal.

Verified settings (claude 2.1.319, from the shipped binary)

Setting Meaning
CLAUDE_CODE_AUTO_COMPACT_WINDOW (env) Window in tokens. 200000, 200k, 1m. Below 100k becomes 100k. Above 1M becomes 1M. Not a number: ignored. Wins over settings.
autoCompactWindow (settings.json) Same, or "auto" for the client default.
modelSettings.<model>.autoCompactWindow Same, per model. Wins over the top-level key. /autocompact writes it.
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE (env) Percent, 0 to 100, of (window - 20,000). It can only lower the threshold.
DISABLE_AUTO_COMPACT, DISABLE_COMPACT (env), autoCompactEnabled=false Auto-compact off.

Threshold in the client's count: (W - 20,000) - 13,000. W is min(model window, configured window). The percent applies to (W - 20,000) and the smaller value wins.

The ruler

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.

Storage level Behavior
Off Works. Nothing is kept.
Metadata only Works.
Everything Works.

How it was tested

Run on the shared box, Go at /usr/local/go/bin/go, -race, foreground. Head 102eee6e.

  • gofmt -l ., go build ./..., go vet on 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.
  • Mutation checks. Each made a test fail and was restored:
    • the read ignores settings.json, or CLAUDE_CONFIG_DIR, or the home guard
    • a hosted proxy uses the setting
    • any agent, not only Claude Code, uses the setting
    • /compact does not record its C on the row
    • the episode walk ignores the configured C
    • (earlier) the percent override raises the threshold; the replay cap ignores the configured C
  • No plugin change in this PR, so the plugin tests do not apply.
  • No live run. The release integration does those.

Left out (follow-ups)

  • Codex. Key model_auto_compact_token_limit exists in codex 0.160.0. I saw the key name only. Unit and default are not verified.
  • Bob. model.compressionThreshold (default 0.5, a fraction) is verified in the bundle. Its ruler is not known.
  • Project settings files and subagent autoCompactWindow are not read.
  • A setting changed during a proxy run needs a proxy restart.
  • A dashboard screen. The C and its source are on the request rows and in the replay ledger (ceiling_configured).

Technical notes

  • Point.Tokens returns Abs when set. For is unchanged.
  • CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE (the hard stop) is not read: it is not the compact point.
  • An earlier version of this PR used a per-session report from the plugin hook. The owner replaced it with the start-up read, so there is no route, no cg:cpt: key and no purge step.

🤖 Generated with Claude Code

…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]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Owner decisions on this PR (David Amid, 2026-11-08, given in the session that started this PR):

  1. Behavior change: approved. A user's own Claude Code auto-compact setting may set C.
  2. docs/data-dependence.md, "Decided by": confirmed.
  3. Factor 1.0 from client tokens to billed tokens: keep it until it is measured.
  4. When the setting is read: at proxy start only. Not on each request and not at each session start. This avoids a check on each session. The PR changes to that design.

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 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.319 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 bbb237786b7f blocking

Verdict: blocking

Findings

  1. 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 gets noteCompactionPoint, so capture.finish (proxy/dashcapture.go:514-517) stores no compaction_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 new noteCompactionPoint comment says it exists to prevent. /compact is the offline replay/eval endpoint, so measurement is its whole purpose.
    • Proof: grep -rn noteCompactionPoint proxy/*.go gives 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 both apply.Opts fields, and call cp.noteCompactionPoint with it. This also removes the double compactionPointFor call on lines 864-865.
  2. dash/compactepisode.go:1113 — the episode walk's configured-C behavior has no test

    • What fails: episodeConversationPoint is new logic (newest configured row wins, Frac = Abs / window, window > 0 guard) and walkCompactEpisodes now calls it (dash/compactepisode.go:505). Nothing tests it. The replay walk got TestReplayCapUsesTheUsersOwnCompactionPoint (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.go gives no matches. dash/compactepisode_test.go has 38 tests; none sets CPoint/CPointSource on a compactRow.
    • 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.
  3. 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] = ceil runs 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, CeilingFrac ends at the table frac while CeilingConfigured still 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 — cpt and limit are per conversation, the map writes are per model. CeilingConfigured is written only inside if 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.
  4. cmd/context-guru-proxy/claudecompact.go:22 — a failed UserHomeDir makes the read look in the proxy's working directory

    • What fails: home, _ := os.UserHomeDir() drops the error. With home == "", 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 home with no empty check.
    • Fix: in claudeCompactAtStart, return compactionpoint.ClaudeCode{} when home == "".

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-runs Resolve/For. Resolve once (covered by finding 1's fix).
  • Stale source lists: apply/opts.go:56, proxy/modes.go:103 and the ClientCeilingUsed.Provenance doc (dash/compactepisode.go:1103) say the source is "measured" | "assumed" | "window_fallback". A fourth value, configured, now exists.
  • readSmall caps a file at 4 MiB (proxy/compactioncfg.go:117-119). A heavy user's ~/.claude.json can exceed that, so autoCompactEnabled is 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 insertBatch statement: 91 columns, 91 placeholders, 91 arguments (dash/store.go:573-672). The three positional scans (requestCols, capSelect, compactEpisodeSelectTmpl) match their select lists.
  • Point.Tokens with the new Abs short-circuit: only Configured points set Abs; 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.
  • assumedWindowFor always returns a positive window, so the new limit / float64(w) in walkCapConversation cannot divide by zero.
  • Hosted mode: claudeCompactAtStart(tenants == nil) and compactionPointFor's own Tenants == nil check agree; a hosted proxy reads nothing. The bifrost adapter leaves Options.ClaudeCompact zero, so it is unchanged.
  • Library boundary: internal/compactionpoint imports only internal/modelinfo, never proxy.
  • 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, proxy and dash/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 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.319 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 bbb237786b7f blocking

Verdict: blocking

Findings

  1. dash/compactepisode.go:1113 — the episode walk's new configured-C path has no test
    • What fails: episodeConversationPoint changes the compaction-episode span and the summarize savings headline for a user who set Claude Code's compaction point. No test covers a row with CPointSource == "configured" flowing through walkCompactEpisodes. A wrong Frac there (for example Abs divided 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.go returns nothing outside replaycap_test.go. dash/compactepisode_test.go has 38 tests; none set CPoint or CPointSource. The twin change in dash/replaycap.go did 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 with CPoint = 0 and one with CPoint = 200_000, CPointSource = "configured". Assert the span narrows (NoAttributableSpan or the episode count changes) and Assumptions.ClientCeilings reports source configured with Frac = Abs / window.

Non-blocking

  • proxy/dashcapture.go:515 — a row can store compaction_point = 0 with compaction_point_source = 'configured'. This happens when the user turned auto-compact off and the model window is unknown: Resolve returns source configured, Tokens(0) returns 0. The schema comment (dash/schema.go:293) says "0 and '' otherwise". Every reader guards CPoint > 0, so no wrong output today. Suggest: also require c.cpoint > 0 in finish, or fix the comment.
  • proxy/compactioncfg.go:817 — readSmall skips ~/.claude.json above 4 MiB. That file grows past 4 MiB for long-time users. A missed autoCompactEnabled: false then 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 /compact endpoint) — its capture never calls noteCompactionPoint, so rows written by /compact carry 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 — modelSettings matching is substring, longest first. A settings key claude-opus-5 also matches a request model claude-opus-5-1. This follows the table's own matching style in For, 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:56 and components/component.go:674 say the source is "measured" | "assumed" | "window_fallback"; dash/compactepisode.go:1103 says "measured", "assumed" or "default". All three now also carry configured.

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 Resolve against 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.go insertBatch: 91 columns, 91 placeholders, args appended in the same position. Verified the two new SELECT columns match their Scan order in compactepisode.go and replaycap.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 *ConversationPoint loops assume. conv[0].Model is the whole conversation's model in both walks.
  • Checked Point.Tokens with Abs: all table points have Abs = 0, so old callers are unchanged (TestForIsUnchangedByTheNewFields covers the table). A configured C can never exceed the table value except the disable path, which equals the window.
  • Checked fail-open: ReadClaudeCompact never fails; bad JSON, wrong types, oversize values and the off-switch all give the zero value (tested). compactionPointFor cannot panic and falls back to For(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 != nil guards both the start-up read and per-request resolve); no library package imports proxy; 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]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to reviewer 1, round 1. Head 102eee6e.

  1. /compact records no C: fixed in 102eee6. compact resolves C once. It passes the value to both apply.Opts fields and to cp.noteCompactionPoint. Test: TestCompactEndpointRecordsTheConfiguredPoint posts to /compact and reads the row back. Mutation (drop the noteCompactionPoint call): the test fails.
  2. Episode walk has no test: fixed in 102eee6. TestEpisodeWalkUsesTheUsersOwnCompactionPoint walks the same rows twice. Table C gives frac 1 and span 0.10. Configured C 950,000 gives frac 0.95 (Abs / window) and span 0.05, source configured. A C below the fill gives NoAttributableSpan = 1. Mutation (use the table in the walk): the test fails.
  3. Ceiling maps overwritten: fixed in 102eee6. CeilingFrac now holds table conversations only. CeilingConfigured holds configured ones (the last walked, if the setting changed). noteCeiling keeps one entry per model and source. The field docs say so. Tests: TestReplayCapCeilingMapsAgreeWhenSourcesMix (both walk orders) and TestEpisodeCeilingsAreReportedPerModelAndSource.
  4. Failed UserHomeDir: fixed in 102eee6. With no home, ReadClaudeCompact reads env only. A relative CLAUDE_CONFIG_DIR is not read either. Test: TestReadClaudeCompactReadsNoFileWithoutAHome puts a project .claude/settings.json in the working directory and checks it is not read. Mutation (remove the guard): the test fails.
  5. Double call in /compact: fixed in 102eee6 (same change as 1).
  6. Stale source lists: fixed in 102eee6 in apply/opts.go, proxy/modes.go, components/component.go and ClientCeilingUsed.Provenance.
  7. 4 MiB cap: fixed in 102eee6. The how-to doc now says a larger file is skipped and C falls back to the table.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to reviewer 2, round 1. Head 102eee6e.

  1. Episode walk has no test: fixed in 102eee6. See TestEpisodeWalkUsesTheUsersOwnCompactionPoint. It checks the span, the source configured and Frac = Abs / window. Mutation: fails.
  2. compaction_point = 0 with source configured: fixed in 102eee6. finish now requires c.cpoint > 0.
  3. 4 MiB cap: fixed in 102eee6. The how-to doc names it.
  4. /compact does not record C: fixed in 102eee6. Test: TestCompactEndpointRecordsTheConfiguredPoint.
  5. Substring match on modelSettings: kept, documented. It matches the table's style in compactionpoint.For. A comment on compactionPointFor names the effect: a key for claude-opus-5 also applies to claude-opus-5-1. The client uses the same rule for its canonical model name, so this follows the client.
  6. Setting applies to every agent: fixed in 102eee6. Checked what exists. The request carries the client's User-Agent, which dash.AgentFor already classifies. compactionPointFor now applies the setting only to claude-cli and claude-code. Codex, Bob, unknown clients and requests with no User-Agent use the table. The limit, stated in the PR body: the User-Agent is the client's own claim, and the Claude Agent SDK sends the same one. I found no stronger signal. metadata.user_id is also sent by other Anthropic-dialect clients. Tests: TestCompactionPointForUsesTheStartupReadInLocalClaudeCodeOnly. Mutation (any agent): fails.
  7. Stale source lists: fixed in 102eee6.

@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.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):

  1. 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 gives NoAttributableSpan = 1. TestEpisodeCeilingsAreReportedPerModelAndSource covers the mixed-source case. I traced the arithmetic against row/fresh/saved and exactWindow (1,000,000): the spans (100,000 and 50,000) and the closes (row 3, and row 2 on the inclusive boundary) check out.
  2. compaction_point = 0 with source configured — fixed. finish now also requires c.cpoint > 0 (proxy/dashcapture.go:515). The stored invariant now matches the schema comment.
  3. 4 MiB cap undocumented — fixed. The how-to doc says a larger file is skipped and C falls back to the table.
  4. /compact recorded no C — fixed. compact resolves C once into cpoint, passes it to both apply.Opts fields, and calls cp.noteCompactionPoint (proxy/proxy.go:851-853). This also removes the double resolve. TestCompactEndpointRecordsTheConfiguredPoint posts a Claude Code and a Codex request and reads both rows back; only the Claude Code row carries a configured C.
  5. Substring modelSettings match — 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 matches compactionpoint.For's own table. I accept: the effect is documented, bounded, and consistent with the client.
  6. Setting applied to every agent — fixed. compactionPointFor now takes the request and applies the setting only when dash.AgentFor says claude-code or claude-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.
  7. Stale source lists — fixed in apply/opts.go, components/component.go, proxy/modes.go and ClientCeilingUsed.Provenance.

Reviewer 1's findings, checked myself:

  1. /compact records no C — fixed (same change as my 4; verified above).
  2. Episode walk no test — fixed (same as my 1).
  3. Ceiling maps overwritten per conversation — fixed. CeilingFrac now holds only table conversations, CeilingConfigured only configured ones, and noteCeiling keeps one entry per model and source (dash/replaycap.go:272-277, dash/compactepisode.go:1128). TestReplayCapCeilingMapsAgreeWhenSourcesMix walks both orders; the two maps agree in both. The field docs state the last-walked rule for CeilingConfigured.
  4. Failed UserHomeDir — fixed. With no home, ReadClaudeCompact reads env only; a relative CLAUDE_CONFIG_DIR is not read either (proxy/compactioncfg.go:56-61). TestReadClaudeCompactReadsNoFileWithoutAHome plants a project .claude/settings.json in the working directory and a rel/settings.json, and proves neither is read — without the guards both files would be picked up.

Non-blocking

  • dash/compactepisode.go:305 — the ClientCeilings field comment still says "one entry per model". noteCeiling now keeps one entry per model and source, so a model with both a configured and a table conversation has two. The noteCeiling comment 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 diff bbb23778..102eee6e read, 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; row model "m" (unlisted → table frac 1.0); spans 100,000 / 50,000; the inclusive span boundary closes the configured episode on row 2; dash.AgentFor classifies the four test User-Agents as claude-cli / codex / curl / unknown.
  • Verified all compactionPointFor callers pass the request and that r != nil is guarded; proxy importing dash breaks no boundary (proxy already imports dash).
  • Verified the no-home path end to end: claudeCompactAtStart passes home = "", ReadClaudeCompact returns env-only when dir == "" && home == "", and an absolute CLAUDE_CONFIG_DIR still 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 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.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

  1. /compact records no C — fixed. compact now resolves C once (proxy/proxy.go:851), passes it to both apply.Opts fields (proxy/proxy.go:867-868) and to cp.noteCompactionPoint (proxy/proxy.go:852). The double resolve is gone too. TestCompactEndpointRecordsTheConfiguredPoint posts to /compact with a Claude Code and a Codex User-Agent and reads both rows back: the claude-cli row carries source configured, 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.
  2. Episode walk untested — fixed. TestEpisodeWalkUsesTheUsersOwnCompactionPoint walks 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 gives NoAttributableSpan = 1. All three assertions are arithmetic on the walk's own rules. TestEpisodeCeilingsAreReportedPerModelAndSource covers the mixed-source report.
  3. Ceiling maps overwritten — fixed. CeilingFrac is now written only by table conversations and CeilingConfigured only 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. noteCeiling keeps one entry per model and source (dash/compactepisode.go:1128-1131). TestReplayCapCeilingMapsAgreeWhenSourcesMix runs both walk orders.
  4. Empty HOME reads the CWD — fixed. claudeCompactAtStart returns env-only read when UserHomeDir fails or is empty (cmd/context-guru-proxy/claudecompact.go:16-21). ReadClaudeCompact also refuses a relative CLAUDE_CONFIG_DIR (proxy/compactioncfg.go:58-63). I checked the test's mutation sensitivity by hand: TestReadClaudeCompactReadsNoFileWithoutAHome puts a real .claude/settings.json in the working directory under t.Chdir, so removing either guard makes the read find the file and the test fail.

Reviewer 2's findings, re-checked

  1. Episode walk untested — fixed, same test as my finding 2. Agree.
  2. compaction_point = 0 with source configured — fixed: finish now also requires c.cpoint > 0 (proxy/dashcapture.go:515).
  3. 4 MiB cap — documented in the how-to (docs/how-to/agent-compaction.md:77-79). Accept.
  4. /compact records no C — fixed, same change as my finding 1.
  5. Substring match on modelSettings — kept by the author, with the effect documented on compactionPointFor. I accept the reason: it is the same matching style as compactionpoint.For's own table, and the comment says the client uses the same rule for its canonical model name.
  6. Setting applied to every agent — fixed beyond what was asked: compactionPointFor now applies the setting only to requests whose User-Agent classifies as claude-code or claude-cli (proxy/compactioncfg.go:146-160). I read dash.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 at compactionPointFor.
  • In walkCapConversation, ceil is computed for a configured conversation and then discarded (only limit is 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 diff bbb23778..HEAD read 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 checked dash.AgentFor's classification, both call sites of the new compactionPointFor signature, the nil-r guard, the how-to doc update, and that the gate and the recorded row use the same resolved point on both /compact and 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]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

This commit fixes the 2 non-blocking notes from round 2. It changes comments only: no code, test or doc file.

Head: a8ae9d9246952d900fefc0358b246b617671dc3c. Checked: every changed line in git diff 102eee6e a8ae9d9246952d900fefc0358b246b617671dc3c starts with //. gofmt -l on the box is clean for both files.

 dash/compactepisode.go | 5 +++--
 proxy/proxy.go         | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)
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

@amiddavid

Copy link
Copy Markdown
Collaborator Author

The approvals of 102eee6e still count at a8ae9d92. The new commit changes only comment lines. The owner ruled on 2026-11-08 that a change to comments only keeps the approvals valid. PR #962 writes this rule into the release docs.

Output of scripts/release/approval-still-valid.sh 955 102eee6e (from #962):

approved: 102eee6e4670 (base f43d9fa5d031) patch-id 5499ae2c41d5
head:     a8ae9d924695 (base f43d9fa5d031) patch-id 07615ac33a94
--- git range-diff
1:  8664aa19 = 1:  8664aa19 feat(compactionpoint): read the user's own Claude Code auto-compact setting as C (#948)
2:  bbb23778 = 2:  bbb23778 refactor(compactionpoint): read the Claude Code compaction setting once at proxy start (#948)
3:  102eee6e = 3:  102eee6e fix(compactionpoint): review round 1 on the start-up read (#948)
-:  -------- > 4:  a8ae9d92 docs(compactionpoint): two comments from review round 2 (#948)
COMMENTS ONLY: 102eee6e4670..a8ae9d924695 changes only comment lines in .go and .sh files. The approval of 102eee6e4670 still counts. Say so on the PR.

Assisted-By: Claude Opus 5.5

@amiddavid
amiddavid merged commit 48606a9 into main Nov 8, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 8, 2026
boazdavid added a commit that referenced this pull request Nov 8, 2026
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]>
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.

compactionpoint: read the user's own compaction setting for each harness (Claude Code, Codex, Bob)

1 participant