Repository navigation
Fix: Default session.client_affinity to on - #1204
Conversation
Client affinity was off unless the config said otherwise, and only the --local built-in config said otherwise. That file is written once and never regenerated, so a laptop installed before the key existed still files every header-less request under whichever session spoke last. Observed: Bob Shell's startup probes and task-classifier completions, priced in Bobcoins, landed inside a concurrent Claude Code session, whose cost column then read "(mixed)". ClientAffinity becomes a *bool read through ClientAffinityEnabled(), nil meaning on, the same shape as session.enabled. An explicit `client_affinity: false` still turns it off, and a live edit to it is still refused by the reloader as needing a restart. In-cluster resolution is unchanged with affinity on: traffic from no known coding agent falls through to ActiveSession() exactly as before (TestClientAffinity_InClusterResolutionIsUnchanged), and `id_headers: []` still disables it along with header bucketing. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughClient affinity now defaults to enabled when its configuration value is unset. Proxy entry points use the effective setting. Session, API, and TUI components can use configurable clocks, and the README demo supplies a shared clock to its components. ChangesClient affinity configuration and integration
Configurable clocks
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue is established. Client affinity now defaults on while preserving explicit opt-out; the demo shares a configured clock across its components. Merge after normal checks pass. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Default-enabled agent attribution broadens exposure to an existing lifecycle gap: after a conversation is removed and its identifier reused, later events and costs can be attributed to the wrong conversation. Explicit opt-out remains available, but applying it requires a restart. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
pdettori
left a comment
There was a problem hiding this comment.
Reviewed and verified.
- All
ClientAffinityconsumers audited: both proxy mains now read through the new accessor; the forwardproxy server keeps its plainbool, which is correct since it's set once at wiring time. - The reloader's
reflect.DeepEqualonsession.*(reloader.go:422) handles the*boolnil↔present distinction, and the newclient_affinity falserefusal test pins it. - Ran
core/config,core/reloader,cmd/authbridge-proxy, andcore/listener/forwardproxytest suites on the PR head locally — all pass. - The failing
Go CI (README demo)/TestCommittedAssetIsCurrentcheck is a flake: the demo feeds synthetic events directly into the session store (tuicapture.go), bypassing the forward proxy, so the affinity default cannot change the SVG. The test passes locally on this branch. Worth a re-run.
The *bool mirroring session.enabled is the right shape — a template-supplied default never reaches installs written before the key existed, and explicit false keeps the off switch.
| `session.client_affinity: true` files a header-less request under the newest session of | ||
| the same agent (by `User-Agent`). An agent's calls before its first header wait in a | ||
| - **Header-less requests are attributed by agent, not by session.** MCP tool calls, | ||
| Claude Code's WebFetch, and Bob's startup probes and task-classifier completions carry |
There was a problem hiding this comment.
suggestion: The new heading says requests are "attributed by agent, not by session", but the next sentence describes the old timing behavior as though it were current. Since affinity is now the default, consider "attributed by agent, not by timing" — or keep the timing sentence but open it with "Before affinity" / "Without it" so the paragraph doesn't read as asserting two contradictory defaults at once.
TestCommittedAssetIsCurrent failed on every run on the 1st of the month and early on the 2nd, and in the first minutes of each UTC day. The fixture is laid out relative to the wall clock: one turn per session sits 26 hours back, so that 7 DAYS and THIS MONTH exceed TODAY. On the 1st that turn lands in the previous month, THIS MONTH drops from $0.79 to $0.65, and the committed asset reads as stale. A rerun cannot clear it. Reproduced on clean main with TZ=UTC on Oct 1, while the same tree passed in local EDT, where it was still Sep 30. The demo now builds a single clock: real time shifted to start at noon on Sep 15, local time. The ledger, the usage aggregator, the session store, the session API and the TUI's UPDATED column all read it, so the output no longer depends on the date or the zone the generator runs in. Four of the five are load-bearing. Removing the clock from the aggregator, the session API or the TUI each turns the test red under TZ=UTC on Oct 1. With only the ledger and aggregator shifted, the session store still stamped UpdatedAt from the real clock: every row rendered "just now" (a negative age) and the usage chart's bars moved. The ledger's clock is not observable in the output, even with the anchor 21 months back, because it is queried with explicit bounds from the clocked session API. It stays wired so that no component of the stack reads a different clock. The anchor is five seconds past the minute because the newest turn sits on the minute boundary, and an anchor exactly on it renders "just now", which the masking does not rewrite. session, sessionapi and tui each gain an additive WithClock option. nil means time.Now, so no production caller changes. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
There is no abctl alias, so an abctl left in ~/.local/bin would keep managing the same launchd/systemd unit as agentop while disagreeing about which build wrote it. install.sh and make dev-install now delete it — but only when the file is ours, judged by the module path Go embeds rather than by running it: that works on stripped release builds (v0.7.0's carries the path several hundred times) and never executes someone else's tool that happens to share the name. install_test.sh covers both release layouts, a foreign abctl whose --version would have fooled a version check, and that none of them is run. Also: - regenerates docs/assets/cortex-demo.svg: the 9 frames that show the title bar or the install line, each two cells wider. The usage frame's chart also changes: it is the first regeneration since rossoctl#1204 pinned the demo's clock, and the committed chart predates that (the staleness test elides the frame, which is why it never went red); - adds a release-notes line saying abctl is now agentop; - records the rename in CLAUDE.md's naming rules. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
Problem
session.client_affinitywas off unless the config turned it on, and only the--localbuilt-in config did. That file is written once (install.shwrites it only when it is missing) and never regenerated. So every laptop installed before the key existed still files header-less requests under whichever session spoke last.docs/laptop-service.mdtold those users to add the line themselves.Seen on a laptop running Claude Code and Bob Shell side by side: Bob's startup probes (
/admin/v1/profile,/inference/v1/model/info) and both task-classifier completions were filed inside the Claude Code session. Those completions are real inference priced in Bob's unit, so the Claude session's cost column read(mixed). The installed config had nosession:block.The cost ledger had the same problem with its own default (see the comment at
cmd/authbridge-proxy/main.go:581): a default that only the template supplies never reaches an installed laptop.Fix
SessionConfig.ClientAffinitybecomes a*bool, read through a newClientAffinityEnabled(). Unset means on, the same shape assession.enabled.client_affinity: falsestill turns it off. A live edit to it is still refused by the reloader as needing a restart, sincesession.*is compared whole.authbridge-proxy,authbridge-cpex) read the accessor.docs/laptop-service.mdand the--localtemplate comment now describe the new default.In-cluster resolution is unchanged. With affinity on, traffic from no known coding agent falls through to
ActiveSession()exactly as before.TestClientAffinity_InClusterResolutionIsUnchangedruns those cases with the knob on.id_headers: [], the documented setting wherever attribution is a trust boundary, still disables affinity along with header bucketing.Before / after
Real-binary smoke test: an isolated proxy started from a config with no
session:block, receiving Claude- and Bob-shaped requests (User-Agents and headers copied from the laptop) in the order observed:The pre-header calls wait in
pending:bob-shell, and Bob's firstX-Task-Idrequest moves them into its session.Not fixed here (#1187)
CONNECT rows are not addressed. They usually carry no User-Agent, so affinity cannot tell whose they are, and they still go to the session that spoke last, in both directions. A replay of the same laptop session through the TLS bridge with affinity on still files 3 Bob CONNECTs under Claude and 3 Claude CONNECTs under Bob. #1187 covers that.
This change is still a prerequisite for #1187: its per-process attribution is planned as a re-keying of affinity, which would otherwise never run on an existing install.
Testing
TestSessionConfig_ClientAffinity: no session block, empty block, block without the key, explicittrueall mean on; explicitfalsemeans off. The unset cases were seen failing before the default changed.TestLoad_PreAffinityLaptopConfigGetsClientAffinity: a pre-affinity laptop config, run throughLoad, comes back with affinity on. Seen failing first.TestReloader_RefusesSessionChange: newclient_affinity falsecase. Under the old plainbool,falsewas indistinguishable from unset, so this case could not be written.core:go vetis clean and all packages pass.cmd/authbridge-proxyandcmd/authbridge-envoyvet and build withGOWORK=off, and the proxy's tests pass.cmd/authbridge-cpexvets with-tags cpex.cmd/abctlbuilds.gofmt -lis clean on every touched path.Also: unflake
Go CI (README demo)The second commit fixes the red
TestCommittedAssetIsCurrenton this PR. This PR didn't cause it: the same failure reproduces on cleanmainwithTZ=UTCon the 1st of the month. The demo fixture is laid out relative to the wall clock and places one turn per session 26 hours back. On the 1st, and early on the 2nd, that turn falls into the previous month, so THIS MONTH drops and the committed SVG reads as stale. A rerun can't clear it.The demo now runs its whole stack on one shifted clock anchored mid-month at midday: session store, session API, usage aggregator, ledger and the TUI's UPDATED column.
session,sessionapiandtuieach gain an additiveWithClockoption; nil meanstime.Now, so production behaviour doesn't change.To verify, run
TZ=UTC go -C scripts/readme-demo test -run TestCommittedAssetIsCurrent ./...on the 1st of a month (red onmain, green here). To check that each clock hookup matters, remove it fromscripts/readme-demo/tuicapture.goand rerun. Removing the ledger's hookup changes nothing in the output; the commit message explains why it stays.Assisted-By: Claude (Anthropic AI) [email protected]
Summary by CodeRabbit
session.client_affinity: falseto disable it and restore timing-based attribution. Changing this setting requires a restart.