Resolve WebSocket handshake headers per connect attempt - #106
Open
mikhailm-coder wants to merge 1 commit into
Open
mikhailm-coder wants to merge 1 commit into
mikhailm-coder wants to merge 1 commit into
Conversation
custom_header captures its value once, which is fine for x-machine-id but wrong for a credential: a token that rotates while the client is connected can never reach the server, because the header was frozen when ConnectOptions was built. Adopting a new one means discarding the client and rebuilding it, along with every subscription hanging off it. custom_header_provider takes a closure the connector calls on every connect attempt, so the next reconnect carries the current token on its own. Values resolving to an empty string are skipped. custom_header keeps the fixed-value form and now shares the same resolution path. Header names appear in ConnectOptions' Debug output; values do not. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0187LY8GpfSvFDqYN1cDAi9u
This was referenced Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #105 — review that one first; this PR's diff is only the delta on top of it.
Base retargets to
mainautomatically once #105 merges.Why
The agent sends its bearer token as
?authorization=<jwt>in the NATS WebSocket URL. Anythingthat logs a URL logs a live customer credential — in front of our agents that is the Google load
balancer, ~113k entries a day, retained 30 days. A handshake header reaches none of those sinks.
The catch:
custom_headercaptures its value once, whenConnectOptionsis built. That is finefor
x-machine-id, but a token that rotates while the client is connected can then never reachthe server — the only way to adopt a new one is to discard the client and rebuild it, along with
every subscription hanging off it. In
openframe-clientthat meant a 133-line rotationsupervisor, a drain, and a rebind hazard across six JetStream listeners.
What
custom_header_provider(name, || async { ... })— a closure the connector calls on everyconnect attempt, so the next reconnect carries the current token by itself.
custom_headerkeepsthe fixed-value form and now shares the same resolution path.
sent, exactly as before, so nothing already deployed changes behaviour.
connection_timeout: they run inline on the connection handler, so onethat never returns would otherwise stop the client reconnecting entirely.
ConnectOptions'Debug; values never do, guarded by a test.Effect on the caller
Applied to
openframe-client,nats_connection_manager.rsgoes +16 −93 — the supervisor,the rebuild, the drain and the
Notifyall disappear, and rotation needs no client code at all.Verified by building the client against this branch.
Verified
cargo build --all-targetsandcargo check --no-default-features --features ring, both underRUSTFLAGS="-D warnings", plus--features websocketsdebug_does_not_render_handshake_header_valuestest passes
🤖 Generated with Claude Code
https://claude.ai/code/session_0187LY8GpfSvFDqYN1cDAi9u