Fix SDK key environment variable not being used for SSE and telemetry#16
Merged
Conversation
When calling NewSdk() without WithSdkKey(), the SDK correctly read the REFORGE_BACKEND_SDK_KEY environment variable for initial HTTP config loads, but failed to use it for SSE live updates and telemetry submission. This caused SSE connections and telemetry to use empty authentication, preventing live flag updates. The root cause was inconsistent SDK key resolution across components. HTTPClient called SdkKeySettingOrEnvVar() at request time, while SSEClient and TelemetrySubmitter directly used options.SdkKey at initialization time (which was empty when the env var was used). This fix normalizes the SDK key once at the beginning of NewSdk(), ensuring options.SdkKey is populated from the environment variable before any components are initialized. This makes all components consistently use the resolved SDK key. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
… sdk.go:102, but the unit test was calling BuildSSEClient directly without that normalization step. Now the test follows the same pattern as the production code.
Previously, BuildSSEClient validated the SDK key during client construction, which caused tests and code paths that didn't actually need to connect (like offline mode tests) to fail when no SDK key was available. This change defers SDK key retrieval and validation to when StartSSEConnection is called - when the connection is actually established. BuildSSEClient now returns both the client and options, and StartSSEConnection uses the options to get the SDK key at connection time. This allows: - Tests using offline sources to work without an SDK key - APIConfigStore to be constructed without requiring an SDK key - SDK key to be read from environment variables when actually needed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Prepare for release v1.2.0 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
jkebinger
approved these changes
Dec 20, 2025
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.
When calling NewSdk() without WithSdkKey(), the SDK correctly read the REFORGE_BACKEND_SDK_KEY environment variable for initial HTTP config loads, but failed to use it for SSE live updates and telemetry submission. This caused SSE connections and telemetry to use empty authentication, preventing live flag updates.
The root cause was inconsistent SDK key resolution across components. HTTPClient called SdkKeySettingOrEnvVar() at request time, while SSEClient and TelemetrySubmitter directly used options.SdkKey at initialization time (which was empty when the env var was used).
This fix normalizes the SDK key once at the beginning of NewSdk(), ensuring options.SdkKey is populated from the environment variable before any components are initialized. This makes all components consistently use the resolved SDK key.