Skip to content

fix: Check disabled state before AI Config mode mismatch#1758

Draft
jsonbailey wants to merge 2 commits into
mainfrom
jb/disabled-config-mode-check
Draft

fix: Check disabled state before AI Config mode mismatch#1758
jsonbailey wants to merge 2 commits into
mainfrom
jb/disabled-config-mode-check

Conversation

@jsonbailey

@jsonbailey jsonbailey commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

This PR fixes two related issues in LDAIClientImpl._evaluate() in the server-ai package, both around how a served AI Config variation's mode is reconciled with the mode the caller requested.

Fix 1 — Check disabled state before the mode comparison

Bug: A disabled AI Config variation is served by LaunchDarkly as {"_ldMeta": {"enabled": false}} with no mode field. The mode-mismatch check ran before the enabled check, so the absent mode defaulted to 'completion'. Calling agentConfig() (or judgeConfig()) on a disabled config then made 'completion' !== 'agent' true and emitted a spurious warning:

AI Config mode mismatch for sample-agent: expected agent, got completion. ...

The config was simply disabled, not a genuine mode mismatch.

Fix: Short-circuit disabled variations before the mode comparison. When value._ldMeta?.enabled === false, _evaluate() returns LDAIConfigUtils.createDisabledConfig(key, mode, ...) of the requested mode — no mode comparison, no warning. (=== false matches the existing disabled-check convention in agentGraph().)

Fix 2 — Return the caller's default on a genuine mode mismatch

Bug (pre-existing): When a config is enabled but its mode genuinely differs from what the caller requested (e.g. an enabled completion config requested via agentConfig()), js-core logged "...Returning disabled config." and returned an empty disabled config. Per the AI Config spec (the "mode mismatch returns the caller's supplied default" rule, merged to sdk-specs main via PR #229 / AIC-2207), the SDK must instead return the caller's supplied default of the requested mode. .NET already does this; js-core was off-spec.

Fix: In the genuine-mismatch branch (which now only runs for enabled configs, after Fix 1's disabled short-circuit), build the returned config from the caller's supplied default (converted to the requested mode via the already-computed ldFlagValue) instead of an empty disabled config. The warning text now reads "Returning caller's default." to match the new behavior and .NET's wording. Matching-mode and disabled paths are unchanged.

Tests

  • Replaced the old "returns disabled config" mismatch test with one asserting the returned config equals the caller's default (enabled, model, provider, messages) and that the warning is still emitted.
  • Disabled-variation regression tests (agent / judge / completion served as {"_ldMeta": {"enabled": false}}) assert no mode-mismatch warning and a disabled config of the requested type — unchanged and still passing.
  • All 225 server-ai tests pass; lint clean.

Companion changes

  • Spec change in sdk-specs on branch jb/disabled-config-mode-check.
  • Companion SDK fix in dotnet-core on branch jb/disabled-config-mode-check.

No changelog or version edits (handled at release time).

BEGIN_COMMIT_OVERRIDE
fix: Check disabled state before AI Config mode mismatch
fix: Return caller's default on AI Config mode mismatch
END_COMMIT_OVERRIDE

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 31978 bytes
Compressed size limit: 34000
Uncompressed size: 114243 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 26365 bytes
Compressed size limit: 29000
Uncompressed size: 129044 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 38739 bytes
Compressed size limit: 39000
Uncompressed size: 212244 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 179579 bytes
Compressed size limit: 200000
Uncompressed size: 831422 bytes

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.

1 participant