Skip to content

Commit 5cba2c1

Browse files
jsonbaileyclaude
andcommitted
fix(server-ai): check _ldMeta.enabled before returning enabled graph
Addresses PR feedback: when _ldMeta.enabled is false, agentGraph() was still returning { enabled: true, graph } despite the AgentGraphDefinition documenting that enabled graphs are always true. Now returns disabled early if the flag is explicitly disabled. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5191c48 commit 5cba2c1

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

packages/sdk/server-ai/__tests__/agentGraph.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ function makeAgentFlagValue(key: string, enabled = true) {
5555
// agentGraph – disabled / validation failures
5656
// ---------------------------------------------------------------------------
5757

58+
it('returns { enabled: false } when _ldMeta.enabled is false', async () => {
59+
const client = makeClient();
60+
mockVariation.mockResolvedValueOnce({ _ldMeta: { enabled: false }, root: 'root' });
61+
const result = await client.agentGraph('my-graph', testContext);
62+
expect(result.enabled).toBe(false);
63+
});
64+
65+
it('logs debug when graph is disabled via _ldMeta.enabled', async () => {
66+
const client = makeClient();
67+
mockVariation.mockResolvedValueOnce({ _ldMeta: { enabled: false }, root: 'root' });
68+
await client.agentGraph('my-graph', testContext);
69+
expect(mockDebug).toHaveBeenCalledWith(expect.stringContaining('disabled'));
70+
});
71+
5872
it('returns { enabled: false } when graph flag has no root', async () => {
5973
const client = makeClient();
6074
mockVariation.mockResolvedValueOnce({ root: '' }); // no root

packages/sdk/server-ai/src/LDAIClientImpl.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,13 @@ export class LDAIClientImpl implements LDAIClient {
408408
defaultGraphValue,
409409
)) as LDAgentGraphFlagValue;
410410

411-
// Step 2: Validate - graph must be fetchable (has a root)
411+
// Step 2: Validate - graph must be enabled and have a root
412+
// eslint-disable-next-line no-underscore-dangle
413+
if (graphFlagValue._ldMeta?.enabled === false) {
414+
this._logger?.debug(`agentGraph: graph "${graphKey}" is disabled.`);
415+
return disabled;
416+
}
417+
412418
if (!graphFlagValue.root) {
413419
this._logger?.debug(`agentGraph: graph "${graphKey}" is not fetchable or has no root node.`);
414420
return disabled;

0 commit comments

Comments
 (0)