Skip to content

feat(compactionpoint): Bob default and Bob/Codex user settings as C (#963) - #964

Merged
amiddavid merged 4 commits into
mainfrom
feat/client-compact-defaults
Nov 8, 2026
Merged

amiddavid merged 4 commits into
mainfrom
feat/client-compact-defaults

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior change

This PR changes C for Bob users who changed nothing, and for Codex users who set a limit.

  • Who: local-mode Bob Shell users (all of them, with or without a setting). Local-mode Codex users who set model_auto_compact_token_limit. A hosted proxy reads nothing and is unchanged. Claude Code is unchanged.
  • Old: C came from the table. For a Bob request on a model not in the table, C was the whole window.
  • New (Bob): C is compressionThreshold x window. The default is 0.5.
    • 200,000 window (for example haiku): old 199,200, new 100,000.
    • 1,000,000 window in our table, Bob list not seen (for example opus-5): old 1,000,000, new 100,000 (0.5 x 200,000). If Bob's list says 1,000,000, new is 500,000.
    • A Bob user with model.compressionThreshold = 0.8 on 200,000: old 199,200, new 160,000.
  • New (Codex): only with the user's model_auto_compact_token_limit. With 180,000 on a 400,000 window: old 400,000, new 180,000. No Codex default is used (see below).
  • What moves: the replay cap, the compaction-episode span, and the summarize trigger (frac x C). Bob savings figures drop, because C is smaller.
  • 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 #964 (comment).

Summary

  • Bob: the local proxy reads model.compressionThreshold once at start. It uses the user's value, else Bob's own default 0.5.
  • Codex: the local proxy reads model_auto_compact_token_limit once at start. It uses the user's value. With no value, Codex stays on the table.
  • Request rows show the source: configured (user setting) or client_default (new, Bob only).
  • Part of compactionpoint: read the Codex and Bob auto-compact settings as C (follow-up to #955) #963. Codex's default is left out on purpose.

What changed

  • internal/compactionpoint/bobcodex.go: Bob.Resolve and Codex.Resolve. New source ClientDefault. Point.FromClient and Recorded handle both sources. No import of proxy.
  • proxy/compactioncfg.go: ReadBobCompact, ReadCodexCompact. compactionPointFor picks the rule by clientOf (User-Agent prefix bobshell/, codex; Claude Code as before).
  • cmd/context-guru-proxy: reads both once at start, local mode only.
  • Source lists updated: apply/opts.go, proxy/modes.go, components/component.go, dash/compactepisode.go, dash/event.go, dash/replaycap.go. Dash code that tested for configured now also accepts client_default (isClientSource).
  • Docs: docs/how-to/agent-compaction.md, docs/data-dependence.md.

What we verified in each client

Bob Shell 1.0.3 (bundle/bob.js, read only)

  • Key: model.compressionThreshold, schema default .5, "restart required".
  • Files: ~/.bob/settings.json (user), .bob/settings.json (project), system file (BOB_SHELL_CLI_SYSTEM_SETTINGS_PATH, else /Library/Application Support/Bob-Shell/settings.json on macOS, /etc/bob-shell/settings.json). Merge order: system defaults, user, project (trusted folder), system. Last wins. No env override.
  • Formula (class Eue, method compress): compact when getLastPromptTokenCount() >= T x ex(model). T = config.getCompressionThreshold() ?? 0.5 (fla = .5).
  • Ruler: lastPromptTokenCount is usageMetadata.promptTokenCount of the last response. That is the provider-reported prompt size, the same ruler as billed input. ex(model) is the whole window from Bob's own catalog: GET /inference/v1/model/info, field data[].model_info.max_input_tokens, 200,000 if missing. No reserve.
  • Which window we use (round 1 fix): min(our window, Bob's window). The proxy reads Bob's max_input_tokens from the model/info response that passes through it, and keeps one number for each model id in memory (at most 512). If it has not seen that response, it uses min(our window, 200,000), which is Bob's own fallback. A lower C is the safe side. The same rule applies to the user's fraction.
  • Bad value: a bad compressionThreshold gives Bob's default 0.5. A bad Codex value gives the table.
  • Which requests: User-Agent starts with bobshell/ (Bob Shell sends bobshell/<version>) or codex (Codex sends codex_cli_rs/...). This is narrower than the dashboard's AgentFor, which stays as it is. So ClientToBilled = 1.0 is right for Bob, not a guess. After a compaction Bob seeds the count with JSON length / 4 until the next response.
  • Not read: the project file (the proxy does not know the directory). A server-side experiment flag (CONTEXT_COMPRESSION_THRESHOLD) that Bob uses when the user set nothing. If that flag is set for a user, the real default is not 0.5 and C is off. Bob's own docs show a different key (chatCompression.contextPercentageThreshold, 0.7); the code does not use it.

Codex CLI 0.160.0 (source at tag rust-v0.160.0, read only)

  • Key: model_auto_compact_token_limit (tokens), top level of $CODEX_HOME/config.toml (default ~/.codex; codex-rs/utils/home-dir/src/lib.rs, config/src/config_toml.rs). No env override.
  • Formula (protocol/src/openai_models.rs ModelInfo::auto_compact_token_limit, core/src/session/context_window.rs): limit = min(configured or catalog limit, 0.9 x context_window). Compact when active_context_tokens >= limit.
  • Ruler: active_context_tokens is the last response's total_tokens (input plus output) plus estimates for later items. It is close to the next request's billed input. Factor taken as 1.0, not measured.
  • Default: the bundled catalog (models-manager/models.json) has auto_compact_token_limit: null for every model. So the default is 0.9 x Codex's own catalog window (272,000 gives 244,800). The user can replace the catalog (model_catalog_json; this machine does). Our window for the same model differs (872,000 for gpt-6-sol in the catalog). This is not a stable value, so I did not use a default. Codex stays on the table when no key is set.
  • Settings that change the meaning: model_auto_compact_token_limit_scope = "body_after_prefix" and model_post_turn_compact_threshold_percent > 0. With either set, no C is derived (fail open).

Data dependence

Metadata only. The proxy reads three short values from two config files, holds them in memory, and writes a number and a source on each row. Off, metadata only, everything: same behavior. The docs/data-dependence.md row is updated. "Decided by" keeps David Amid.

For Bob, the local proxy also reads the model list that passes through it (/inference/v1/model/info). It keeps one window number for each model id, in memory only, at most 512 entries, replaced on each fetch, and never written anywhere. A hosted proxy captures nothing.

How it was tested

On the box (~/cgssh2), -race, head c10301e:

  • go test -race ./proxy/..., ./dash/..., ./internal/compactionpoint/, ./apply/..., ./components/..., ./cmd/...: all ok.
  • gofmt -l clean, go vet clean.
  • New tests: our window larger than Bob's, Bob's window seen, not seen, model absent from the info response; the model/info pass-through (body unchanged, window kept, map bounded); the bobshell/ and codex User-Agent match (bobcat/1.0, my-bob-tool/2, xcodex/1 use the table); the /compact row for a bobshell/ request has client_default and 100,000; the replay-cap and episode walks with a client_default row.
  • Mutation checks, each made tests fail, then restored: the min-window rule removed; the 200,000 fallback changed; Bob's window ignored; the User-Agent match widened to bob; IsClientSource without client_default.
  • No live test with bob or codex.

Open questions

None. The owner answered all three on the PR (comment 6725469580).

Technical notes

  • Codex file read is a line scanner for three top-level keys, not a TOML parser (no TOML dependency in go.mod). It stops at the first [table]. A key set inside a [profiles.x] table is not read.
  • A Codex limit above 0.9 x our window is capped to 0.9 x our window.
  • Bob threshold above 1 is capped to 1. A bad value gives Bob's default, not the table.

🤖 Generated with Claude Code

…as C (#963)

Local mode only, read once at start, fail open, same off switch as #955.
Bob: model.compressionThreshold (default 0.5 of the window), source
client_default when unset. Codex: model_auto_compact_token_limit, no
default (the client default depends on a per-model catalog).

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. Bob uses its own verified default, 0.5 of the window, when the user set nothing. On a 200k model, C goes from 199,200 to 100,000.
  2. Codex with no key set: keep the table. Only a user-set model_auto_compact_token_limit changes C. The PR does not read the Codex model catalog.
  3. Bob's server-side experiment flag (CONTEXT_COMPRESSION_THRESHOLD): accepted as a stated limit. The proxy cannot read it.

Assisted-By: Claude Opus 5.5

@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 46b88b0adce7 blocking

Verdict: blocking

Findings

  1. internal/compactionpoint/bobcodex.go:47 — Bob's threshold is multiplied by OUR window, but the client multiplies by its own catalog window

    • What fails: a Bob request for a model where our window differs from Bob's ex(model) gets a wrong C. Bob compacts at T x ex(model), and ex(model) comes from Bob's gateway catalog, 200,000 when the model is missing (your own verification note, bobcodex.go:29-31). Bob.Resolve computes T x our window. Our window for claude-opus-5 and claude-sonnet-5 is 1,000,000 (internal/modelinfo/builtin.go:27-28). If Bob's catalog says 200,000 for that model (or lacks it), the real C is 100,000 but we report 500,000 — too high, the direction this package itself calls dangerous: the summarize trigger fires at 0.9 x 500,000 = 450,000 and never fires, and the episode span over-reports savings.
    • Proof: proxy.go:856 resolves window from our modelinfo and passes it to compactionPointFor, which calls h.opts.BobCompact.Resolve(window) (proxy/compactioncfg.go:158). Nothing checks that our window equals Bob's catalog value, and no doc states that assumption. The PR refuses a Codex default for exactly this divergence ("Our window for the same model differs, 872,000 vs 272,000 for gpt-6-sol"), so the same class of error is accepted for Bob without a guard.
    • Fix: state and bound the assumption. Either document in agent-compaction.md and the Bob comment that C assumes Bob's catalog window equals ours and is wrong (too high) when it does not, or apply the default only when the window is provider-exact and cap Bob's C at the table value for the model. The user-set fraction case has the same exposure.
  2. docs/how-to/agent-compaction.md:90 — "a bad value gives the table" is false for Bob

    • What fails: a reader who sets model.compressionThreshold to a non-number (say "high") reads that C falls back to the table. The code gives the client default instead: C = 0.5 x window, source client_default (internal/compactionpoint/bobcodex.go:51-66 — a parse failure leaves t at BobDefaultThreshold). The PR's own technical notes say "A bad value gives Bob's default, not the table."
    • Proof: TestBobFailsOpen (internal/compactionpoint/bobcodex_test.go:366-379) asserts a bad value gives ClientDefault, not the table. The doc line contradicts the code and the test.
    • Fix: in the "Bob and Codex" intro, split the claim: Codex fails open to the table; Bob fails open to its own 0.5 default.

Non-blocking

  • isClaudeCodeAgent (proxy/compactioncfg.go:170) has no caller left. compactionPointFor now switches on dash.AgentFor directly. Delete it or keep a test on it.
  • Point.FromClient (internal/compactionpoint/compactionpoint.go:153) has no production caller. proxy/dashcapture.go:515 and dash/replaycap.go:216 hand-roll the same test on source strings. Use it or drop it.
  • Codex Resolve treats model_post_turn_compact_threshold_percent = 0.0 (a TOML float) as "set" and gives the table, while the client treats 0 as off. Safe direction, rare input. A numeric compare instead of != "0" would fix it.
  • The Codex 0.9 clamp (bobcodex.go:325-327) uses our window, not the client's catalog window — the same exposure as finding 1, but only for a user-set limit, and the code comment says it is a sanity bound only.

What I checked

  • The full diff (17 files) and the code around each change: internal/compactionpoint (compactionpoint.go, bobcodex.go, both test files), proxy/compactioncfg.go with readSmall/short, cmd/context-guru-proxy start-up reads, proxy/dashcapture.go row storage, dash/replaycap.go and dash/compactepisode.go consumers.
  • The client_default source against every consumer of configured: dashcapture.go:515, replaycap.go:216 and 279, compactepisode.go:1117, Recorded, apply/opts.go, proxy/modes.go, components/component.go. All accept both sources; old rows with configured read as before.
  • dash.AgentFor (dash/event.go:1239-1263): "bob-shell/1.0.3" maps to "bob", "codex_cli_rs/0.160.0" to "codex". The hosted-proxy guard (Tenants != nil) holds for all three clients.
  • Fail-open paths: unreadable or >4 MiB files, missing home, relative CODEX_HOME, the off switch, bad numeric values, scope and post-turn guards. All give the table (Bob: the default) — no panic, no request blocked.
  • Behavior-change rule: the PR names the change at the top (Bob C drops to 0.5 x window, Codex only with a user limit), gives the off switch, and records the owner's approval on 2026-11-08. The data-dependence row is updated with #963.
  • Tests: the new tests cover the default, the user value, the caps, fail-open, the UA dispatch and the hosted guard. No live tests were run (not approved); Go is not on this machine.
  • The PR body (description only; no reviews or comments read before this post).

@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 46b88b0adce7 blocking

Verdict: blocking

Findings

  1. internal/compactionpoint/bobcodex.go:47 — Bob's default C uses our window, but Bob acts on its own catalog window, and nothing guards or states the difference.

    • What fails: a Bob request for a model where our modelinfo window differs from Bob's ex(model) gets a wrong C. When our window is larger, C is too high — the dangerous direction by this package's own rule: the summarize trigger (frac x C) fires only after Bob already compacted, and the replay cap and the episode span over-report savings.
    • Proof: Bob.Resolve computes abs = int(math.Floor(t * float64(window))) from the window h.resolveWindow gives (proxy.go:1257, our modelinfo). The verified client rule (comment at bobcodex.go:226-231) is promptTokenCount >= T x ex(model), where ex(model) is "the model's context window from the gateway catalog (max_input_tokens, 200,000 when missing)" — Bob's own backend, reached through the /inference/v1/model/info passthrough (proxy.go:611-619), not our modelinfo. The PR itself records this exact class of divergence and refuses a Codex default for it: "Our window for the same model differs (872,000 vs 272,000 for gpt-6-sol)". The Bob path has no guard, and the Note sent to the dashboard says "0.5 of the model window" without saying which window or that the two must agree.
    • Fix: bound the assumption. Either use the client default only when our window is exact, or read ex(model) from the model/info responses that already pass through the Bob gateway, or at least write the assumption into Point.Note and docs/how-to/agent-compaction.md so a reader can tell whether it holds.
  2. proxy/dashcapture.go:515 — the new client_default row behavior has no test.

    • What fails: a regression that stops storing a client_default C on the request row, or stops reading it back in the dash walks, passes every test.
    • Proof: the #948 equivalent is tested end to end — TestCompactEndpointRecordsTheConfiguredPoint (proxy/compactioncfg_test.go:126) asserts the configured row, and the dash walks are tested with CPointSource = "configured" (dash/replaycap_test.go:679, 717). No test anywhere sets client_default on a row: grep finds it only in internal/compactionpoint tests and the compactionPointFor dispatch test. The new arms — dashcapture.go:515, isClientSource (dash/replaycap.go:215), episodeConversationPoint (dash/compactepisode.go:1117) — are untested.
    • Fix: extend the endpoint test with a bob-shell User-Agent row and assert CompactionPointSource == "client_default"; add one dash walk test with a client_default row.

Non-blocking

  • isClaudeCodeAgent (proxy/compactioncfg.go:170) has no non-test caller after this PR. Dead code; delete it.
  • agentFromUserAgent matches "bob" by substring (dash/event.go:1246). Any User-Agent containing "bob" (for example bobcat/1.0) now gets Bob's default C instead of the table. The Claude Code strings are specific; "bob" and "codex" are short. Consider matching bob-shell.
  • Point.FromClient (internal/compactionpoint/compactionpoint.go:153) is exported as the one rule for "a row must store this", but the row gate (dashcapture.go:515) and dash's isClientSource re-implement it with string comparisons. One rule in three places; a fourth source value needs three edits.

What I checked

  • The full diff (17 files) and the code around each change.
  • internal/compactionpoint: Bob.Resolve, Codex.Resolve, ClientDefault, FromClient, Recorded, Point.Tokens, and the new tests.
  • proxy/compactioncfg.go: ReadBobCompact, ReadCodexCompact, bobSystemSettingsPath, the TOML line scanner, and compactionPointFor's User-Agent dispatch. Both call sites (proxy.go:856 /compact, proxy.go:1259 chat) and the threading through reqInfo (proxy/modes.go:60, 165) and apply.Opts.
  • The dash readers of the source string: replaycap.go (isClientSource, capConversationPoint, walkCapConversation), compactepisode.go (episodeConversationPoint, noteCeiling), event.go, query.go, store.go, and the UI (no consumer keys on the provenance strings; client_default renders raw, like the others).
  • Fail-open paths: unreadable or odd files, the off switch, hosted mode (Tenants != nil), unknown window, Scope/PostTurn guards, values above 1 and above 0.9 x window.
  • Data dependence: the docs/data-dependence.md row is updated, metadata only, decided by David Amid.
  • The PR description: the behavior change is named at the top, with the owner's approval and the turn-off switch, as CLAUDE.md requires.
  • Live tests were not run (not approved). Test claims in the PR body are the author's.

…lient_default (#963)

Bob compacts against its own catalog window. Use min(our window, Bob's
max_input_tokens from the model/info response), or min(our, 200,000)
when not seen. Match Bob by "bobshell/" and Codex by "codex" prefix for
the compaction point only. One IsClientSource rule. Codex post-turn 0.0
reads as off. Tests for client_default end to end and in both dash walks.

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). Fixed in c10301e.

  1. Bob's window (blocking): fixed.
    • C now uses min(our window, Bob's window).
    • Bob's window comes from the model/info response. Bob fetches GET /inference/v1/model/info and reads data[].model_info.max_input_tokens (200,000 if missing). The proxy already passes this route through. It now keeps one number for each model id in memory (at most 512, replaced on each fetch). The body goes to Bob unchanged.
    • If the proxy has not seen the response, it uses min(our window, 200,000). This is Bob's own fallback.
    • The same rule covers the user's fraction.
    • Point.Note, the Bob comment and docs/how-to/agent-compaction.md say so.
    • Tests: our window larger than Bob's, seen, not seen, model not in the response, pass-through.
  2. client_default end to end (blocking): fixed. The /compact endpoint test now sends bobshell/1.0.3 and asserts client_default and 100,000. New tests: replay cap and episode walk with a client_default row. Mutation: removing client_default from the rule fails them.
  3. isClaudeCodeAgent dead code: fixed. Deleted.
  4. bob substring: fixed. New clientOf in the compaction dispatch matches the prefix bobshell/ (the User-Agent in the Bob bundle) and codex. dash.AgentFor is unchanged. bobcat/1.0, my-bob-tool/2 and xcodex/1 use the table (tested).
  5. Three copies of the rule: fixed. One function, compactionpoint.IsClientSource. FromClient, the row writer and both dash walks use it.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to reviewer 2 (round 1). Fixed in c10301e.

  1. Bob's threshold times our window (blocking): fixed. Same fix as reviewer 1, finding 1. C is T x min(our window, Bob's window). Bob's window comes from the model/info response, else 200,000. I did not use "cap at the table value", because the table gives 1.0 for opus, which is the wrong direction. The user's fraction follows the same rule.
  2. Docs said a bad value gives the table (blocking): fixed. The docs now split the claim. Bob: a bad value gives Bob's own default 0.5. Codex: a bad value gives the table.
  3. isClaudeCodeAgent unused: fixed. Deleted.
  4. FromClient unused: fixed. It now calls IsClientSource, and the row writer and dash use IsClientSource.
  5. Codex post-turn 0.0: fixed. The value is compared as a number. "", 0 and 0.0 read as off. 0.5, 80 and abc give the table. Tested.
  6. Codex 0.9 clamp uses our window: left as is, comment added. The comment says the clamp is a sanity bound, and the user's limit is the value used.

@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 c10301ed3d79 blocking

Verdict: blocking

Round-1 findings

  • My finding 1 (Bob's threshold times our window): fixed. Bob.Resolve(window, bobWindow) now uses min(our window, Bob's window); Bob's window comes from the model/info response the proxy passes through (noteBobModelInfo, forwardBobModelInfo), else Bob's own fallback 200,000. The min rule is right in both directions: a conversation cannot pass the smaller window, so the smaller threshold is the one that acts. A window not seen gives a lower C, the safe side, and the docs say so. The user's fraction follows the same rule. The author's reason for not capping at the table value is right: the table gives 1.0 for opus, which is no cap.
  • My finding 2 (docs said a bad value gives the table): fixed. agent-compaction.md now splits the claim: Bob fails open to its own 0.5 default, Codex to the table.
  • My non-blocking items: all addressed. isClaudeCodeAgent deleted. One rule, compactionpoint.IsClientSource, now used by the row writer (dashcapture.go:515) and both dash walks. Codex post-turn is compared as a number, so 0.0 reads as off. The Codex clamp keeps our window with a comment that says it is a sanity bound only — I accept that reason: the client clamps against its own catalog, which we do not know, and the user's limit is the value the client uses.
  • Reviewer 1, finding 1 (Bob's window): fixed, same fix, checked myself.
  • Reviewer 1, finding 2 (no client_default test): fixed. Three new tests: the /compact endpoint with a bobshell/1.0.3 User-Agent asserts client_default and 100,000 (compactioncfg_test.go:171-174); TestReplayCapUsesAClientDefaultCompactionPoint and TestEpisodeWalkUsesAClientDefaultCompactionPoint cover both dash walks. All helpers they use exist.
  • Reviewer 1, non-blocking (bob substring, dead code, three copies of the rule): fixed. clientOf matches the prefix bobshell/ and codex; bobcat/1.0, my-bob-tool/2 and xcodex/1 use the table (tested).

Findings

  1. docs/data-dependence.md:219 — the row does not say the proxy now reads Bob's model/info responses
    • What fails: c10301e gives this feature a new input. The local proxy now reads the body of Bob's GET /inference/v1/model/info responses (proxy/proxy.go forwardBobModelInfo, proxy/compactioncfg.go noteBobModelInfo) and keeps one window number per model id, at most 512 entries, in memory, replaced on each fetch. The row still says the proxy reads "a few short setting values once, at start-up" and lists only config files. A reader of the row cannot tell that the proxy inspects a gateway response body from live traffic. CLAUDE.md makes this row the place that states what a feature reads.
    • Proof: git diff 46b88b0a..c10301ed -- docs/ touches only agent-compaction.md. The how-to doc documents the read ("keeps one number for each model in memory"); the data-dependence row was not updated.
    • Fix: add one sentence to the row: for Bob, the proxy also reads the model list that passes through (/inference/v1/model/info) and keeps one window number per model id in memory, at most 512, replaced on each fetch. Nothing is stored. The per-level claims in the row stay true — this is a doc gap, not a storage change.

Non-blocking

  • clientOf (proxy/compactioncfg.go) matches any User-Agent that starts with codex. A different tool whose UA starts with codex gets Codex's C when a limit is set. The prefix is deliberate and tested against look-alikes; the exposure needs a user-set limit. Consider codex_ if every originator value carries the underscore.
  • The CodeQL inline (bobcodex.go:162, abs := int(n)): the n > 1<<40 guard at line 159 bounds the conversion, and int is 64-bit on the platforms this repo builds. I read the alert as a false positive. A 32-bit build would truncate; none is targeted.
  • forwardBobModelInfo truncates a body over maxRequestBytes (32 MiB) and forwards the truncated bytes with a matching Content-Length. Same pattern as the existing forwardBobProfile, and a model list that size is not realistic. Noted only.

What I checked

  • Last review: round 1, 46b88b0, 2026-11-08T18:43:27Z
  • New commits read: 1 (c10301e "fix(compactionpoint): bound Bob's window, narrow the UA match, test client_default")
  • Read in full: 4 reviews, 3 comments, 2 inline comments (from the three files)
  • New items since my last review, and what I did about each:
    • Commit c10301e: full diff plus the code around each change — Bob.Resolve's new window rule and its edge cases (window unknown, Bob window seen or not, model absent from the list), noteBobModelInfo (bounds, lock, wholesale replace), forwardBobModelInfo and isBobModelInfo in the passthrough (hosted guard, Accept-Encoding dropped so the body is readable), clientOf, the Codex post-turn numeric compare, and every new test.
    • Author's reply to reviewer 1 (19:10:52): each claim checked in the code. All hold.
    • Author's reply to reviewer 2 (19:10:54): each claim checked in the code. All hold.
    • CodeQL inline at 19:11:58 on bobcodex.go:162: checked, assessed above.
    • Reviewer 1's round-1 review (18:45:11, posted after mine): read in full; both findings checked myself, both fixed.
    • Owner-decisions comment (18:38:45): read; consistent with the PR body's approval note.
  • Concurrency: bobWin is written under bobWinMu and read under the same lock; parse happens outside the lock. No race seen.
  • Fail-open: a model/info body that is not the LiteLLM shape records nothing; an unreadable body is streamed unchanged; a model absent from the list keeps the 200,000 fallback, the safe direction.
  • Tests were not run by me (not approved; Go is not on this machine). The author's reply reports mutation checks that fail the new tests; those claims are the author's.

@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 c10301ed3d79 blocking

Verdict: blocking

Round-1 findings

Mine (reviewer 1):

  1. Bob's default C used our window — fixed. Bob.Resolve(window, bobWindow) now uses min(our window, Bob's window); Bob's window comes from the model/info response the proxy passes through (noteBobModelInfo, bobWindow, forwardBobModelInfo), else Bob's own 200,000 fallback. I traced every window combination: ours larger, Bob's larger, Bob not seen, ours unknown, model absent from the list — all give the smaller window or the table, the conservative direction. The Note, the Bob comment and docs/how-to/agent-compaction.md state the rule.
  2. No test for client_default end to end — fixed. The /compact endpoint test now asserts a bobshell/1.0.3 row with client_default and 100,000; TestReplayCapUsesAClientDefaultCompactionPoint and TestEpisodeWalkUsesAClientDefaultCompactionPoint cover both dash walks; TestBobModelInfoPassThroughRecordsWindow covers the capture.
  3. isClaudeCodeAgent dead code — fixed. Deleted; clientOf replaces it.
  4. "bob" substring match — fixed. clientOf matches the prefix bobshell/ and codex; bobcat/1.0, my-bob-tool/2 and xcodex/1 use the table (tested; I traced xcodex/1 myself: the prefix fails and the dash.AgentFor fallback maps only Claude).
  5. One rule in three places — fixed. compactionpoint.IsClientSource is the one rule; the row writer and both dash walks call it.

Reviewer 2's:

  1. Bob's threshold times our window — fixed, same fix. The author rejected the "cap at the table value" alternative because the table gives 1.0 for opus. I checked: the table entry for claude-opus-5 is Frac: 1.00, so the cap would keep C at the window. The reason is right; the min rule is better.
  2. Docs said a bad value gives the table — fixed. The docs now split: Bob gives its own 0.5 default, Codex gives the table.
  3. isClaudeCodeAgent unused — fixed.
  4. FromClient unused — mostly fixed. IsClientSource is the used rule. FromClient itself still has no production caller (non-blocking below).
  5. Codex post-turn 0.0 — fixed. Numeric compare; "", 0, 0.0 read as off, 0.5, 80, abc give the table (tested).
  6. Codex 0.9 clamp on our window — left as is, comment added. Reviewer 2's own round-1 note called it a sanity bound in the safe direction. Accept.

Findings

  1. docs/data-dependence.md:219 — the row does not say the feature now reads Bob's model/info responses and holds a model catalog in memory.
    • What fails: the row (and the PR's Data dependence section) still say the feature reads a few short setting values once at start-up and holds them in memory. Since c10301e it also reads Bob's live /inference/v1/model/info response bodies and holds model ids and their max_input_tokens in memory (at most 512). An auditor reading the row misses that the proxy inspects Bob's control-plane traffic.
    • Proof: c10301e adds noteBobModelInfo, bobWindow and forwardBobModelInfo (proxy/compactioncfg.go, proxy/proxy.go:744) with Handler.bobWin state filled from response bodies. git diff 46b88b0a..HEAD -- docs/ touches only agent-compaction.md. The PR's Data dependence section still reads "reads three short values from two config files". CLAUDE.md requires the row update, in plain words, for every PR that changes a feature.
    • Fix: one sentence in the row (and the PR's Data dependence section): the local proxy also keeps Bob's model ids and their window numbers from the model/info responses that pass through it — in memory, at most 512 entries, never written anywhere; a hosted proxy captures nothing.

Non-blocking

  • The CodeQL inline (ParseInt to int at internal/compactionpoint/bobcodex.go:159) is benign on shipped builds: .goreleaser.yaml builds amd64 and arm64 only, both 64-bit int, and the n > 1<<40 bound fits. To close the alert, bound with int64(math.MaxInt).
  • forwardBobModelInfo truncates a model/info body over 32 MiB and forwards the cut bytes with the smaller Content-Length (proxy/proxy.go:748). Same shape as the existing forwardBobProfile, and a model list that large is not realistic. On a read error it also returns false with the body partially consumed — again the existing profile path's shape, and the response is broken anyway.
  • Point.FromClient still has no production caller; IsClientSource is the rule everything uses.
  • The PR's "What changed" bullet still says compactionPointFor picks the rule by dash.AgentFor; c10301e replaced that with clientOf.

What I checked

  • Last review: round 1, 46b88b0, 2026-11-08T18:45:11Z
  • New commits read: 1 (c10301e "fix(compactionpoint): bound Bob's window, narrow the UA match, test client_default (#963)")
  • Read in full: 3 reviews, 3 comments, 1 inline comment (from .review-in-reviews.txt, .review-in-comments.txt, .review-in-inline.txt)
  • New items since my last review: commit c10301e (full diff and the code around each change); the author's two reply comments at 19:10 (checked every claim against the code); the updated PR body (behavior-change section carries the new Bob numbers). Older items I read for the first time this round: the owner-decisions comment at 18:38 (all three decisions match the code) and reviewer 2's round-1 review (checked each finding and the author's reply to it, including the rejected "cap at the table" alternative); the CodeQL inline from 17:38 (checked against the release architectures).
  • The new code paths: clientOf prefix matching (traced bobshell/, codex_cli_rs, xcodex/1, bob-shell/..., Claude Code UAs), Bob.Resolve window combinations, noteBobModelInfo bounds and locking, forwardBobModelInfo fail-open paths (non-200, unreadable body, hosted mode gated off, Accept-Encoding handling), the Codex post-turn numeric compare.
  • The new tests read in full: bobcodex_test, compactioncfg_test (endpoint, dispatch, bounded map, pass-through), replaycap_test, compactepisode_test.
  • Live tests were not run (not approved). Test and mutation claims in the PR body and the reply are the author's.

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

Copy link
Copy Markdown
Collaborator Author

Reply to both reviewers (round 2). Fixed in b74f1db.

Blocking finding (both reviewers): fixed. The docs/data-dependence.md row now says that, for Bob, the local proxy also reads the model list that passes through it (/inference/v1/model/info). It keeps one window number for each model id, in memory only, at most 512 entries, replaced on each fetch, never written anywhere. A hosted proxy captures nothing. The PR body (Data dependence, What changed) has the same fix. The compactionPointFor line now says clientOf.

Non-blocking: deferred to a follow-up. A code change now would need a new review round.

  • CodeQL int(n) bound: benign. Release builds are 64-bit only, and the n > 1<<40 guard holds. Follow-up: bound with math.MaxInt.
  • codex prefix: deliberate and tested against look-alikes. It needs a user-set limit to matter. Follow-up: consider codex_.
  • Point.FromClient has no production caller. IsClientSource is the rule in use. Follow-up: drop or use it.
  • 32 MiB truncation in forwardBobModelInfo: same shape as forwardBobProfile, and a model list of that size is not real. No change.

Full diff git diff c10301ed b74f1db3 (one file, no .go change):

diff --git a/docs/data-dependence.md b/docs/data-dependence.md
index 839e2247..4d36adad 100644
--- a/docs/data-dependence.md
+++ b/docs/data-dependence.md
@@ -216,7 +216,7 @@ One row for each registered component. The test `components/all/datadep_test.go`
 | Billed-token and cache-time records | metadata | ❌ Gone. `summarize` cannot tell how full the window is. A warm cache can look cold when one conversation comes under two ids. | 🟡 Works, metadata. This record also makes `summarize` start, and so start to waste calls. | 🟡 Works, metadata | To know how full the window is, Context Guru needs the size the provider billed last turn. It also needs the time the cache was last used. The billed size is kept per session and per thread (one integer each). The per-thread one lets `coref` measure how fast one thread grows. |
 | **Session state table** (`--session-state`, #769; on with `--dashboard`) | content and metadata | ❌ Off. Dashboard off, `--session-state=false`, or store off: nothing is written. | 🟡 Works, metadata: only the keys of counts, hashes, ids and verdicts are written (`cg:bin:`, `cg:bint:`, `cg:len:`, `cg:ttl:`, `cg:seen:`, `cg:swd:`, `cg:swk:`, `cg:swx:`, `cg:rst:`, `cg:use:`, `cg:tdf:`). Set `--session-state-metadata-only`. The table is in the dashboard database. | ✅ Works. **Also writes the content keys to the dashboard database**: the summary text (`cg:sum:`), `extract_llm` results (`cg:res:`, `cg:xres:`), freeze decisions (`cg:frz:`) and the sweep's held answer (`cg:swh:`). The rewind payloads (the stash) are never written. | A restart, or a pause of more than 2.8 hours, deletes the summary checkpoint and the last billed input from memory. The next turn then sends the full transcript, which can be over the window, and the summary cannot start. A table lets the proxy give a returning session the same state it had. The table is **not encrypted**. It has its own retention, not the dashboard's. A row lives 30 days after its last write. An eviction or an archive can end it earlier, when no other session uses its key. Decided by: David Amid, 2026-10-29 (the dashboard database, on with the dashboard). David Amid confirmed the data-dependence change for `extract_llm_sweep`. Rows to confirm: `cache_aware_summarizer`, `summarize` (Itay Nakash). |
 | **Tool deferral history** (`ultrahigh`, #485) | metadata | ❌ Off with no durable place: no dashboard database and tool deferral's own file cannot be opened. Then it lives in memory only, a restart starts it from zero, and nothing is deferred until 3 new sessions. With the Store off nothing is deferred at all. | 🟡 Works, metadata | 🟡 Works, metadata | To defer only the tools a user does not use, it keeps, per user, session and tool: whether the session declared the tool, whether it used or loaded it, the project folder and the time. The rule groups MCP tools by server (`mcp__<server>__*`) when it reads this; the table still holds tool names only. It keeps the newest 64 sessions per user, plus the newest 10 sessions of each project, up to 256 sessions per user in all. The extra sessions are there because the rule checks whether this project used a tool in its last 10 sessions; without them, a user in many projects would push a project's older sessions out, and the check would not see them. It deletes sessions idle longer than the session-state retention (30 days by default). The table is `tool_defer_history`, in the dashboard database when there is one, else in tool deferral's own file. A user's first deferral request copies that user's own sessions, and no other user's, from the dashboard's inventory tables. It also keeps the provider check result per endpoint, model and route (`tool_defer_probe`); that row describes an endpoint, not a user. An account purge deletes the user's history rows, thread records and opt-out flags. Tool names, ids, paths, flags and times only. Nothing is shared between users: the history, the records and the opt-outs are keyed by user, and the pending opt-outs are capped per user. The check spends the user's own credential, under $0.01 per check, once a day per model (a failed check is retried after 15 minutes). Decided by: David Amid, #485, 2026-11-02. |
-| **Client compaction setting** (Claude Code #948; Bob and Codex #963) | metadata | ✅ Works. Nothing is kept: the proxy holds the setting in memory. | 🟡 Works, metadata | 🟡 Works, metadata | The user can move the point where Claude Code compacts its own transcript. The savings figures and the summarize trigger must use that point, or they are wrong for that user. The local proxy reads a few short setting values once, at start-up, from its env and from `settings.json` and `.claude.json` (Claude Code), `~/.bob/settings.json` (Bob) and `config.toml` (Codex), and holds them in memory. For Bob it also uses the client's own default threshold. It writes the resulting C (a number) and its source (`configured` or `client_default`) on each request row (`compaction_point`, `compaction_point_source`). No transcript text, no paths, no other settings. A hosted proxy reads nothing. Decided by: David Amid, #948, #963. |
+| **Client compaction setting** (Claude Code #948; Bob and Codex #963) | metadata | ✅ Works. Nothing is kept: the proxy holds the setting in memory. | 🟡 Works, metadata | 🟡 Works, metadata | The user can move the point where Claude Code compacts its own transcript. The savings figures and the summarize trigger must use that point, or they are wrong for that user. The local proxy reads a few short setting values once, at start-up, from its env and from `settings.json` and `.claude.json` (Claude Code), `~/.bob/settings.json` (Bob) and `config.toml` (Codex), and holds them in memory. For Bob it also uses the client's own default threshold. For Bob, the local proxy also reads the model list that passes through it (`/inference/v1/model/info`). It keeps one window number for each model id, in memory only, at most 512 entries, replaced on each fetch, and never written anywhere. It writes the resulting C (a number) and its source (`configured` or `client_default`) on each request row (`compaction_point`, `compaction_point_source`). No transcript text, no paths, no other settings. A hosted proxy reads and captures nothing. Decided by: David Amid, #948, #963. |
 | **Keep-alive pings** | content. The host keeps the credential. | ❌ **Should be off. Today it is still on**, and keeps the last body. The proxy binary also keeps the credential. | ❌ Off | ✅ Works | To keep the prompt cache warm, the proxy sends the exact same prompt again with the user's credential. Without the text, it cannot ping. The Ping button (`POST /api/me/cache/ping`) uses the same body and key. With keep-alive off, a request that carries the header `x-context-guru-ping: 1` is still held, for the button only: no ping is sent for it, and the body and key are released 300 seconds after the last request on a 5-minute cache, or 59 minutes after it on a 1-hour cache (a press does not extend it), and one account holds at most 16 such threads. Without the header nothing is held. The install adds the header and tells the user. An older install (from before `--no-ping-header`) gets it at its next session start, with the same notice. Any other install without the header is never changed. It gets a one-time note instead. The cache-state answer also carries the time of the next planned ping (a number, metadata), so the mod can hide the button while a ping fires before the cache expires. |
 | **Body stash** | content | ❌ **Should be off. Today it is still on**, with 2 full bodies per thread. | ❌ Off. The sweep's question then cannot be asked, and `cache_aware_summarizer` stops. | ✅ Works | To ask the model a cheap question, Context Guru adds the question to the exact text it sent last turn. The provider already cached that text. The sweep keeps **2 more full copies of the conversation per thread**, outside the stash, for a thread the keep-alive can ping (see `extract_llm_sweep` above). |
 | Observe-mode store | content | ❌ **Should follow the level. Today it is still a real Store.** | It should follow the level | ✅ Works | Observe mode runs the pipeline later on a copy, to estimate savings. The copy should store only what the real run would store. |

@amiddavid

Copy link
Copy Markdown
Collaborator Author

The approvals of c10301ed still count at b74f1db3. The owner ruled this. (David Amid, 2026-11-08, given in the session that started this PR.)

  • In round 2, both reviewers blocked only on one docs gap: the docs/data-dependence.md row did not say that the proxy reads Bob's model-info replies.
  • b74f1db3 fixes that gap. It changes only docs/data-dependence.md: 1 file, 1 insertion, 1 deletion. It descends from c10301ed, and it changes no code.
  • The owner ruled that this docs-only fix closes the finding without a third round.
  • The non-blocking code notes are deferred to a follow-up. See feat(compactionpoint): Bob default and Bob/Codex user settings as C (#963) #964 (comment).

Assisted-By: Claude Opus 5.5

Fixes CodeQL alert 6 (go/incorrect-integer-conversion).

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

Copy link
Copy Markdown
Collaborator Author

CodeQL alert 6 fixed in 6a1f582, at the owner's choice.

  • strconv.ParseInt in Codex.Resolve now parses 32 bits. The n > 1<<40 guard stays. No test changed.
  • gofmt -l clean. go vet ./internal/compactionpoint/ clean. go test -race ./internal/compactionpoint/: ok.

Full git diff b74f1db3 6a1f5829:

diff --git a/internal/compactionpoint/bobcodex.go b/internal/compactionpoint/bobcodex.go
index 3e58573c..6bede39a 100644
--- a/internal/compactionpoint/bobcodex.go
+++ b/internal/compactionpoint/bobcodex.go
@@ -155,7 +155,7 @@ func (c Codex) Resolve(window int) (Point, bool) {
 			return Point{}, false
 		}
 	}
-	n, err := strconv.ParseInt(strings.ReplaceAll(strings.TrimSpace(c.Limit), "_", ""), 10, 64)
+	n, err := strconv.ParseInt(strings.ReplaceAll(strings.TrimSpace(c.Limit), "_", ""), 10, 32)
 	if err != nil || n <= 0 || n > 1<<40 {
 		return Point{}, false
 	}

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Live checks after merge: Codex passes, Bob passes on the fallback path

The owner approved both checks. Setup:

  • The proxy was built from main at 354fcb32, which contains this PR's squash ed692a71.
  • It ran in local mode on port 8964 against the plain gateway, not Context Guru.
  • Codex used a throwaway CODEX_HOME. ~/.codex and ~/.bob were not changed.

(c) Codex 0.160.0: pass

The throwaway config.toml sets model_auto_compact_token_limit = 150000. One codex exec with a nonce went through the proxy:

ts             agent  model        compaction_point  compaction_point_source
1794221174961  codex  gpt-6.1-sol  150000            configured
  • C is the user's limit, 150,000. The 0.9 × window bound did not apply.
  • The source is configured.

(b) Bob Shell 1.0.3: pass, on the 200,000 fallback

No Bob setting was set. One bob prompt went through the proxy. Bob was pointed at it with the env vars CUSTOM_BASE_URL and BOB_GATEWAY_URL only.

agent  model    compaction_point  compaction_point_source
bob    premium  100000            client_default
  • C = 0.5 × 200,000 = 100,000, and the source is client_default.
  • Not shown live: the recording of Bob's own window. Bob sent no GET /inference/v1/model/info through the proxy (0 log hits). It reads its catalog from its own gateway. So this value came from the 200,000 fallback. Unit tests cover the recorded-window path.

Cleanup

  • The proxy was stopped by its own pid.
  • The credential file was deleted on exit.
  • The box build directory is removed.

Assisted-By: Claude Opus 5.5

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.

2 participants