test(client): assert a failed init_client can be retried - #140
Merged
Merged
Conversation
_resolve_client assigns _client only on success, so a call made before LD_SDK_KEY is available already leaves nothing behind and the next call retries. Nothing asserted it. These tests match the ones added to TypeScript in launchdarkly/js-ai-sdk#105, where the first rejection was cached for the life of the process: - fail without a key, then init_client({"sdkKey": ...}) succeeds - fail, shutdown(), then init succeeds - inspect_config, which swallows the init error, reports disabled while the key is missing and enabled once it is set Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jeffdupont
approved these changes
Oct 5, 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.
Summary
Adds tests asserting that a failed
init_clientis not cached, so a later call can retry. No library change:_resolve_clientalready sets_clientonly on success. Nothing asserted it, though, and the TypeScript side had exactly this bug. There,singleton.initPromisecached the first rejection for the life of the process (fixed in launchdarkly/js-ai-sdk#105).The new tests in
tests/test_lifecycle.py:TestInitClientSDKKeyPath::test_retries_after_a_failed_init_instead_of_replaying_it: with no key,init_client()raises. Theninit_client({"sdkKey": "late-key"})returns the client, andConfigis built withlate-key.TestShutdown::test_allows_initialization_after_a_failed_init: a failed init, thenshutdown(), then an init that succeeds.TestInspectConfig::test_recovers_once_sdk_key_is_available_after_a_failed_lazy_init:inspect_configswallows init errors, so a cached failure would serve disabled configs forever. Here it reports disabled while the key is missing and enabled once it is set.The TypeScript PR adds four more tests that have no Python counterpart:
shutdown()dropping an in-flight init. Python has no shared in-flight promise.waitForInitializationtimeout, including whenclose()also throws.start_waitdoesn't raise. The analogous close-on-failure case is already covered bytest_a_failed_telemetry_setup_leaves_no_client_behind.Tests
uv run pytest packages/client: 1389 passed.ruff checkandruff format --checkare clean.🤖 Generated with Claude Code