Skip to content

Fix SDK key environment variable not being used for SSE and telemetry#16

Merged
jkebinger merged 6 commits into
mainfrom
jd/sse-sdk-issue
Dec 20, 2025
Merged

Fix SDK key environment variable not being used for SSE and telemetry#16
jkebinger merged 6 commits into
mainfrom
jd/sse-sdk-issue

Conversation

@jdwyah
Copy link
Copy Markdown
Contributor

@jdwyah jdwyah commented Dec 19, 2025

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.

jdwyah and others added 6 commits December 19, 2025 18:04
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 jkebinger merged commit 477ac9d into main Dec 20, 2025
4 checks passed
@jkebinger jkebinger deleted the jd/sse-sdk-issue branch December 20, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants