Skip to content

refactor(compactionpoint): move the compaction-point choice out of the proxy - #1320

Merged
amiddavid merged 3 commits into
mainfrom
feat/mv-1300-compaction
Nov 24, 2026
Merged

amiddavid merged 3 commits into
mainfrom
feat/mv-1300-compaction

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The proxy no longer decides the compaction point C. The choice and the settings readers now live in internal/compactionpoint. Closes #1300. Refs #1309.

What changed

  • New internal/compactionpoint/client.go:
    • Client type: the library takes the client as an input.
    • Settings.Pick(client, ...): the selection order (client rule first, else the caller uses the price table).
    • ReadClaude, ReadBob, ReadCodex: take getenv, home and an Open function. ReadBob also takes goos.
    • CleanBobWindows(windows, max): the clean-up of Bob's window catalog. The proxy passes bob.MaxModelWindows.
    • BobSystemSettingsPath(getenv, goos): Bob's system-settings path. The proxy passes runtime.GOOS.
    • Open: the readers open files through it. The proxy passes os.Open.
  • proxy/compactioncfg.go shrinks from 328 to 135 lines. It keeps clientOf, hostOpen (os.Open), the Handler window store and its mutex, and thin wrappers with the old names and signatures.
  • proxy/proxy.go is not touched.

Behaviour

None. Existing tests pass with no edit.

Differences from the issue text, kept on purpose:

  • noteBobWindows does not move whole. The tests read h.bobWin as a map. A move would edit tests. Only the pure clean-up moved. The mutex and map stay in the host, as host state.
  • clientOf stays in the proxy, unchanged (scope change). Issue refactor(agent): move Claude Code rules into agent/claudecode; add OpenCode and Pi labels #1312 replaces it with one library entry point in agent/. The library takes the client, not the User-Agent.
  • The proxy's ClaudeCompactOffEnv is now an alias of compactionpoint.OffEnv. Same value.

Data dependence

Unchanged. Same inputs: env, the user's settings files, the User-Agent, model id and window numbers. No transcript text. No row in docs/data-dependence.md changes.

How it was tested

macOS, Go 1.27.4, at head aa5b6c8d.

  • go build ./... && go vet ./... && gofmt -l .: clean.
  • go test -count=1 ./internal/compactionpoint ./proxyapp ./dash/...: pass, except TestNoHooksKeepsTheBinaryDefaults in proxyapp. It also fails on origin/main.
  • CGO_ENABLED=1 go test -race ./internal/compactionpoint: pass.
  • Race run of ./proxy in 9 parts (-run ^Test[A], B, C, D-E, F-L, M-O, P-R, S, T-Z): all pass except one test.
    • TestRegistrationRateLimitedPerIP failed once in the P-R part (7 s, while other agents ran suites on this machine).
    • It passes 3 of 3 alone with -race here, and 3 of 3 on origin/main. It is a timing test. It does not touch compaction code.
  • New test TestReadBobCompactAcceptsADotElementInTheSystemPath fails on cb628c7f (Threshold empty) and passes now.
  • New library tests: TestReadersPassPathsUnchangedToTheOpener, TestBobSystemSettingsPath, and the reader tests on an in-memory tree.
  • Mutation: a doubled window cap in CleanBobWindows made TestCleanBobWindows fail. Reverted.

Technical notes

  • Library tests use unix-style absolute paths in MapFS. The host opens files with os.Open, so relative, . and Windows paths behave as before.

…e proxy

Move the client match, the choice order, the three settings readers and the
Bob window clean-up from proxy/compactioncfg.go into internal/compactionpoint.
The readers take getenv and an fs.FS. The host keeps the file system, the
Bob system-settings path and the in-memory window store.

Closes #1300. Refs #1309.

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

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Verdict: approve

Findings

None. The move keeps the behavior. I checked each moved piece against the old proxy code, line by line:

  • ReadClaude, ReadBob, ReadCodex in internal/compactionpoint/client.go are copies of the old ReadClaudeCompact, ReadBobCompact, ReadCodexCompact, with the same off switch, the same path guards (IsAbs, empty home), the same merge order, the same size caps and the same short() rule.
  • ClientOf matches the old clientOf: the same bobshell/ and codex prefix tests on the trimmed, lowercased header, then the Claude test. The Claude test (Contains of claude-code or claude-cli on the lowercased raw header) gives the same answers as the old dash.AgentFor switch, because dash.AgentFor returns claude-code or claude-cli exactly when one of those substrings is present (dash/event.go:1263). clientdash_test.go pins the two together.
  • Settings.Pick makes the same three calls the old switch made, with the same arguments (Claude.Resolve(model, window), Bob.Resolve(window, bobWindow(model)), Codex.Resolve(window)). The hosted-proxy guard (Tenants == nil, r != nil) stays in compactionPointFor.
  • CleanBobWindows keeps the old noteBobWindows result: same bounds, same copy, nil when nothing is stored.
  • MaxBobWindows = 512 equals bob.MaxModelWindows (agent/bob/controlplane.go:16).
  • The proxy keeps wrappers (ReadClaudeCompact etc.) so proxyapp and the existing proxy tests are unchanged, as issue #1300 asks. The new library file imports no proxy, proxyapp or dash package.
  • No leftover users of the removed helpers (clientOf, readSmall, short) in proxy/; the remaining imports in proxy/compactioncfg.go are all used.

Non-blocking

  • internal/compactionpoint/client.go:26 — openAbs cannot open a Windows drive-letter path (C:\Users\... fails fs.ValidPath after ToSlash), so on Windows every settings read would silently fail open. The Makefile builds darwin only, so this is not live today. Note it if a Windows build ever lands.
  • internal/compactionpoint/client.go:26 — a relative home now resolves under / (DirFS root); the old code opened it relative to the working directory. Only proxyapp passes home, and it uses os.UserHomeDir() (absolute or empty), so the case is unreachable in practice. It is an edge-case behavior difference; issue #1300 says "no change in behaviour". The new side is the safer one (it cannot read a project file).
  • internal/compactionpoint/client.go:16 — MaxBobWindows = 512 is a second copy of bob.MaxModelWindows. The comment says this is on purpose. No test ties the two constants together (agent/bob/controlplane_test.go:131 pins only its own). If one changes, nothing fails.
  • proxy/compactioncfg.go:48 — hostFS is a mutable package-level var. Fine as a test seam; just keep writes to it in tests only.

What I checked

  • The full diff 30a80767..HEAD (one commit) and the code around each change.
  • Line-by-line equivalence of the three readers, ClientOf, Pick and CleanBobWindows against the removed proxy code.
  • dash.AgentFor (dash/event.go:1263) against the repeated Claude rule, plus the pin test.
  • Bob.Resolve, Codex.Resolve, ClaudeCode.Resolve signatures and zero-value behavior.
  • Callers: proxyapp/claudecompact.go, proxy/proxy.go, and the unchanged proxy/compactioncfg_test.go (its t.TempDir() paths work through os.DirFS("/") on darwin and Linux).
  • Import direction: dash imports compactionpoint; the new pin test sits in the external compactionpoint_test package, so no cycle.
  • Issue #1300 (the refactor's rules) — the PR follows them; no proxy test was edited.
  • Build targets in the Makefile for the Windows question above.
  • No data-dependence change: the move changes no feature's data dependence, so no docs/data-dependence/ row edit is needed.
  • I did not run builds or tests (not approved for this review).

@amiddavid
amiddavid force-pushed the feat/mv-1300-compaction branch from b8bd50e to cb628c7 Compare November 24, 2026 08:58

@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.331 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 cb628c7fe2f2 approve

Verdict: approve

Findings

None. The change is a move, not a behavior change. I checked each moved piece against the code it replaced, line by line.

Non-blocking

  • internal/compactionpoint/client.go:124 — openAbs roots at os.DirFS("/") (proxy/compactioncfg.go:48). On Windows, a home like C:\Users\me passes filepath.IsAbs, but DirFS("/") cannot open it. The old code used os.Open and could. The read then fails open and C comes from the table. The repo ships linux and darwin only (.goreleaser.yaml), so no released build is affected.
  • internal/compactionpoint/client.go:124 — fs.FS names reject . and .. elements, which os.Open accepted. All current callers pass paths cleaned by filepath.Join and checked with IsAbs, so no reachable change. Only BOB_SHELL_CLI_SYSTEM_SETTINGS_PATH from the env reaches openAbs uncleaned; a value with a . element is now skipped instead of read. Fail open.
  • internal/compactionpoint/client.go:63 — MaxBobWindows = 512 no longer tracks bob.MaxModelWindows (proxy kept bobWindowMax = bob.MaxModelWindows before). If the agent's cap rises, CleanBobWindows returns nil for every catalog over 512 and Bob's windows stop being recorded. The comment says this is deliberate. No test pins the two constants together.
  • proxy/compactioncfg.go:118 — bobSystemSettingsPath stays in the proxy, because it reads runtime.GOOS. A second host must copy it to get the same Bob C. That weakens the stated goal ("every host gets the same C") a little. Fine for now; only one host exists.

What I checked

  • The full diff of all six files, and the code around each change.
  • Parity of the moved readers: ReadClaude, ReadBob, ReadCodex, readOff, readSmall, short in internal/compactionpoint/client.go are the removed proxy code verbatim. The only difference is the file-system injection (os.Open(path) becomes openAbs(fsys, path)).
  • Parity of ClientOf with the removed clientOf: the inline Claude rule (Contains(lower(raw UA), "claude-code" || "claude-cli"), no trim) equals what dash.AgentFor returns for those two names, because dash checks them first in its list (dash/event.go:1264). The Bob and Codex prefix rules are unchanged. clientdash_test.go pins the Claude rule to dash.AgentFor.
  • Parity of Settings.Pick with the removed switch in compactionPointFor: same calls, same arguments; h.bobWindow is never nil, so the nil guard changes nothing. The Tenants == nil and r != nil guards are unchanged.
  • Parity of CleanBobWindows with the removed noteBobWindows body: same empty, over-cap and non-positive-window rules. MaxBobWindows = 512 equals bob.MaxModelWindows (agent/bob/controlplane.go:16).
  • Callers: proxyapp/claudecompact.go still calls the proxy wrappers; home is absolute or "" there. No code outside proxy/compactioncfg.go used the removed helpers clientOf, readSmall or short.
  • No identifier clashes in internal/compactionpoint (Client, Settings, Pick, CleanBobWindows are new; short, readSmall, readOff exist once). Test helpers do not clash across the two test packages.
  • Library boundary: internal/compactionpoint/client.go imports only stdlib and gjson, never proxy.
  • Tests: new tests cover ClientOf, Pick, CleanBobWindows and all three readers, including the off switch, the merge order and fail-open cases. The old proxy tests still cover the wrappers through the real file system.
  • Data dependence: unchanged. The feature row docs/data-dependence/features/client-compaction-setting.md stays accurate; no row edit is needed for a move.
  • Docs: no stale references to proxy.ReadClaudeCompact and friends outside the proxy package; the package comments in bobcodex.go and claudecode.go were updated to the new names.

… in the library

- Read settings files through an injected Open (os.Open in the host), so
  relative, `.` and Windows paths work as before.
- CleanBobWindows takes the cap. The proxy passes bob.MaxModelWindows.
- BobSystemSettingsPath moves to the library and takes goos.
- Add a test for a `.` element in the Bob system path.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid
amiddavid force-pushed the feat/mv-1300-compaction branch from b8bd50e to aa5b6c8 Compare November 24, 2026 09:34
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Fixed in aa5b6c8.

  1. Copied constant. Removed MaxBobWindows. CleanBobWindows takes the cap. The proxy passes bob.MaxModelWindows (bobWindowMax), one definition.
  2. Path edge cases. The library no longer rewrites paths. It reads through an injected Open. The host passes os.Open, so relative, ./.. and Windows paths act as before. New test TestReadBobCompactAcceptsADotElementInTheSystemPath fails on cb628c7 and passes now.
  3. bobSystemSettingsPath. Moved to the library as BobSystemSettingsPath(getenv, goos). The proxy passes runtime.GOOS. ReadBob takes goos and finds the path itself.
  4. hostFS. Now hostOpen, with a comment that only tests may write it.

@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.331 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 aa5b6c8d89ee approve

Verdict: approve

Findings

None. The new commit fixes every note from both round-1 reviews and adds no defect.

Status of the earlier notes

My round-1 notes (all non-blocking):

  1. openAbs broke Windows drive paths — fixed. Open (client.go:123) is an injected opener; the host passes hostOpen, a wrapper over os.Open (proxy/compactioncfg.go:49). A C:\Users\... path now reaches os.Open as before.
  2. fs.FS rejected . and .. elements — fixed. Same injection. The library hands the path to the opener unchanged. TestReadersPassPathsUnchangedToTheOpener (client_test.go:140) pins that, and TestReadBobCompactAcceptsADotElementInTheSystemPath (proxy/compactioncfg_test.go:314) reads a real file through a . element.
  3. MaxBobWindows was a second copy of bob.MaxModelWindows — fixed. The constant is gone. CleanBobWindows takes the cap (client.go:95) and the proxy passes bobWindowMax = bob.MaxModelWindows (proxy/compactioncfg.go:98). One definition.
  4. bobSystemSettingsPath stayed host-side — fixed. It moved to the library as BobSystemSettingsPath(getenv, goos) (client.go:233), a verbatim copy. The proxy passes runtime.GOOS (proxy/compactioncfg.go:121). TestBobSystemSettingsPath covers env override, trim, darwin, linux and windows.

Reviewer 1's notes: 1 and 2 (Windows, relative home) fixed by the same Open injection — a relative home now opens relative to the working directory, the base behavior that issue #1300 asks to keep. 3 (copied constant) fixed as above. 4 (hostFS mutable var) addressed: it is now hostOpen with a comment that only tests may write it. I checked each fix myself; I agree with all of them.

Non-blocking

  • internal/compactionpoint/client.go:17 — the file-header comment still says the host passes "Bob's system-settings path". The host now passes goos, and the library finds the path itself (client.go:217, 233). One stale sentence; the rest of the comment is right.

What I checked

  • Last review: round 1, cb628c7, 2026-11-24T09:00:16Z.
  • New commits read: 1 — aa5b6c8 "refactor(compactionpoint): keep the old path behaviour, one cap, GOOS in the library".
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files .review-in-reviews.txt, .review-in-comments.txt, .review-in-inline.txt).
  • New items since my last review: the author's comment at 2026-11-24T09:51:57Z ("Fixed in aa5b6c8", four points) — I checked each point against the code; commit aa5b6c8 — full diff and the four changed files read around each change.
  • The new Open seam: hostOpen wraps os.Open because os.Open's result type does not assign to Open directly; the wrapper keeps the same semantics (nil, err on error). readSmall and ReadCodex call open(path) with the path exactly as built — no rewriting, so relative, ./.. and Windows paths behave as in the base.
  • Parity of BobSystemSettingsPath with the removed proxy function: verbatim (env override with trim, darwin path, else /etc/bob-shell/settings.json). ReadBob calls it itself; the proxy passes runtime.GOOS.
  • CleanBobWindows(windows, max): same empty, over-cap and non-positive rules as before, now with the caller's cap. The proxy passes bobWindowMax = bob.MaxModelWindows, so the cap has one definition again.
  • No leftover references: MaxBobWindows, openAbs, hostFS and bobSystemSettingsPath are gone from the repo; every ReadBob caller uses the new 4-argument form.
  • Imports: strings removed from proxy/compactioncfg.go (no user left), io/fs added (used by hostOpen); path/filepath and io/fs still used in client.go.
  • Tests: the round-1 tests were updated to the new signatures, plus three new tests (TestBobSystemSettingsPath, TestReadersPassPathsUnchangedToTheOpener, TestReadBobCompactAcceptsADotElementInTheSystemPath). The path-recording test asserts the exact string, so a future rewrite of paths would fail it.
  • The old proxy tests still run through hostOpen and the real file system, so the wrappers stay covered.
  • Library boundary unchanged: client.go imports only stdlib and gjson.

@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.331 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 aa5b6c8d89ee approve

Verdict: approve

Findings

None. The new commit aa5b6c8d fixes every round-1 finding, mine and reviewer 2's, and adds no defect. I checked each fix in the code:

  • Path behavior restored. Open func(path string) (fs.File, error) (internal/compactionpoint/client.go:123) replaces the fs.FS + openAbs pair. The host passes a wrapper over os.Open (proxy/compactioncfg.go:49), so a path means what it meant before the PR: relative paths resolve against the working directory, . and .. elements work, and a Windows drive path works. readSmall, ReadClaude, ReadBob and ReadCodex pass the path to the opener unchanged — no rewriting anywhere in the library.
  • One cap. MaxBobWindows is gone. CleanBobWindows(windows, max) takes the cap (internal/compactionpoint/client.go:95) and the proxy passes bobWindowMax = bob.MaxModelWindows (proxy/compactioncfg.go:98,106). The cap has one definition again, as before the PR.
  • Bob path rule in the library. bobSystemSettingsPath moved from the proxy to BobSystemSettingsPath(getenv, goos) (internal/compactionpoint/client.go:233), a verbatim copy with goos in place of runtime.GOOS. ReadBob takes goos and finds the path itself; the proxy passes runtime.GOOS (proxy/compactioncfg.go:121). A second host now gets the same rule for free.
  • hostOpen. Renamed from hostFS, still a package-level var, now with "Only tests may write this variable" in its comment. That covers my note.

Status of round-1 findings

Mine (all non-blocking, all fixed):

  1. Windows drive-letter paths broke under DirFS — fixed (os.Open through hostOpen).
  2. Relative home resolved under / — fixed (os.Open semantics restored).
  3. MaxBobWindows = 512 duplicated bob.MaxModelWindows — fixed (cap passed as a parameter).
  4. hostFS mutable var — fixed (renamed, documented).

Reviewer 2's (all non-blocking, all fixed):

  1. Windows DirFS — same fix as my 1. Fixed.
  2. ./.. elements rejected — fixed, and covered by two new tests (see below).
  3. MaxBobWindows no longer tracks the agent's cap — fixed (one definition).
  4. bobSystemSettingsPath stays in the proxy — fixed (moved to the library).

The author's comment (2026-11-24T09:51:57Z) lists the same four fixes. Each claim checks out in the diff.

New tests in aa5b6c8d

  • TestReadersPassPathsUnchangedToTheOpener (internal/compactionpoint/client_test.go) proves the library hands /a/./b/../s.json to the opener verbatim.
  • TestReadBobCompactAcceptsADotElementInTheSystemPath (proxy/compactioncfg_test.go) proves a . element in the env path reads the file through the real os.Open. The author says it fails on cb628c7f; that matches fs.ValidPath rejecting . elements, so the claim is right.
  • TestBobSystemSettingsPath covers darwin, linux, windows and a trimmed env value.

Non-blocking

  • internal/compactionpoint/client.go:16 — the file-header comment still says a host passes "the file system, and Bob's system-settings path". The host now passes an opener and goos, and the library finds Bob's path itself. The comment is one commit behind the code.

What I checked

  • Last review: round 1, cb628c7, 2026-11-24T08:58:50Z.
  • New commits read: 1 — aa5b6c8d "refactor(compactionpoint): keep the old path behaviour, one cap, GOOS in the library".
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from .review-in-reviews.txt, .review-in-comments.txt, .review-in-inline.txt).
  • New items since my last review: reviewer 2's round-1 review (read in full; its four non-blocking findings match mine or add the ./.. and host-copy points, all now fixed), the author's fix comment (each claim verified in the diff), and commit aa5b6c8d (reviewed below).
  • The full diff cb628c7f..aa5b6c8d and the final state of internal/compactionpoint/client.go, proxy/compactioncfg.go and both test files.
  • No other package uses the changed API (ReadBob, ReadClaude, ReadCodex, CleanBobWindows): dash uses only Point sources, proxyapp goes through the proxy wrappers.
  • Imports: strings left proxy/compactioncfg.go with its last user; io/fs entered for fs.File; every remaining import in both files is used.
  • Issue #1300's rules still hold: no proxy behavior change (the os.Open path semantics are the pre-PR ones), no library import of proxy, proxyapp or dash.
  • I did not run builds or tests (not approved).

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

Copy link
Copy Markdown
Collaborator Author

Head is now 85f3d14. Output of scripts/release/approval-still-valid.sh 1320 aa5b6c8d89ee:

approved: aa5b6c8d89ee (base 30a80767bd31) patch-id bb4a70d9291d
head:     85f3d14b999f (base 30a80767bd31) patch-id 741d0a1d9b19
--- git range-diff
1:  cb628c7f = 1:  cb628c7f refactor(compactionpoint): move the compaction-point choice out of the proxy
2:  aa5b6c8d = 2:  aa5b6c8d refactor(compactionpoint): keep the old path behaviour, one cap, GOOS in the library
-:  -------- > 3:  85f3d14b docs(compactionpoint): fix the file-header comment
COMMENTS ONLY: aa5b6c8d89ee..85f3d14b999f changes only comment lines in .go and .sh files. The approval of aa5b6c8d89ee still counts. Say so on the PR.

@amiddavid
amiddavid merged commit 9f7475c into main Nov 24, 2026
10 of 11 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 24, 2026
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.

refactor(compactionpoint): move the compaction-point choice out of the proxy

1 participant