Skip to content

test(client): assert a failed init_client can be retried - #140

Merged
XieX merged 1 commit into
xie/agent-skillsfrom
xie/init-client-retry-test
Oct 5, 2026
Merged

XieX merged 1 commit into
xie/agent-skillsfrom
xie/init-client-retry-test

Conversation

@XieX

@XieX XieX commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds tests asserting that a failed init_client is not cached, so a later call can retry. No library change: _resolve_client already sets _client only on success. Nothing asserted it, though, and the TypeScript side had exactly this bug. There, singleton.initPromise cached 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. Then init_client({"sdkKey": "late-key"}) returns the client, and Config is built with late-key.
  • TestShutdown::test_allows_initialization_after_a_failed_init: a failed init, then shutdown(), then an init that succeeds.
  • TestInspectConfig::test_recovers_once_sdk_key_is_available_after_a_failed_lazy_init: inspect_config swallows 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:

  • Concurrent callers sharing one rejected init promise, and shutdown() dropping an in-flight init. Python has no shared in-flight promise.
  • Closing the built client after a waitForInitialization timeout, including when close() also throws. start_wait doesn't raise. The analogous close-on-failure case is already covered by test_a_failed_telemetry_setup_leaves_no_client_behind.

Tests

  • Each new test fails against a mutation that caches the missing-key failure.
  • uv run pytest packages/client: 1389 passed. ruff check and ruff format --check are clean.

🤖 Generated with Claude Code

_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 jeffdupont mentioned this pull request Oct 5, 2026
@XieX
XieX merged commit 542233b into xie/agent-skills Oct 5, 2026
7 of 8 checks passed
@XieX
XieX deleted the xie/init-client-retry-test branch October 5, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants