Skip to content

test(client): add makeGraphTrackData to the root exports snapshot - #137

Merged
XieX merged 2 commits into
mainfrom
xie/fix-root-values-graph-track-data
Oct 15, 2026
Merged

XieX merged 2 commits into
mainfrom
xie/fix-root-values-graph-track-data

Conversation

@XieX

@XieX XieX commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Why

#101 exported makeGraphTrackData from the @launchdarkly/ai-server root (packages/client/src/index.ts) but didn't update ROOT_VALUES in packages/client/src/__tests__/skills.test.ts. The "the package root exports exactly the snapshotted values" test has failed on main since 4d97cfa, and yarn test stops before the later workspaces run, so every branch cut from main is red.

What

  • Add 'makeGraphTrackData' to ROOT_VALUES in sorted order.
  • Regenerate packages/client/etc/ai-server.api.md (api:update) so the Type check job's api:check passes.

The approved-names list in ai-sdks-monorepo gets the matching - makeGraphTrackData line (leaving the public surface, like makeNodeTrackData / makeRunTrackData): launchdarkly/ai-sdks-monorepo#61. Its JSDoc already marks it @internal for the native graph adapters.

Testing

  • yarn workspace @launchdarkly/ai-server run test: 1401 passed, 11 skipped.
  • yarn workspace @launchdarkly/ai-server api:check passes.

🤖 Generated with Claude Code


Note

Overview
Fixes a failing root export snapshot test after makeGraphTrackData was added to the @launchdarkly/ai-server package entry in an earlier change.

Adds 'makeGraphTrackData' to the sorted ROOT_VALUES list in skills.test.ts so Object.keys(packageIndex) matches the snapshotted exports again. The API Extractor report (ai-server.api.md) is updated to document the existing @internal makeGraphTrackData export alongside makeNodeTrackData / makeRunTrackData.

Reviewed by Cursor Bugbot for commit bb7f00d. Bugbot is set up for automated code reviews on this repo. Configure here.

#101 exported makeGraphTrackData from the package root but left
ROOT_VALUES in skills.test.ts unchanged, so the snapshot test failed
on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XieX
XieX marked this pull request as ready for review October 14, 2026 21:38
@jeffdupont

Copy link
Copy Markdown
Contributor

Thanks, this fixes the Tests job. Type check still fails because etc/ai-server.api.md wasn't regenerated. Running yarn workspace @launchdarkly/ai-server build locally adds the 5-line makeGraphTrackData entry, and api:check passes after that. Once this merges, main is green and the open PRs can rebase.

…Data

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jeffdupont jeffdupont left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at bb7f00d. The API report is regenerated with the makeGraphTrackData entry, so Type check passes now along with Tests and the rest of CI. The paired approved-names change (ai-sdks-monorepo#61) has merged. The ae-internal-missing-underscore warning matches the 4 already on main. Once this lands, main's CI (red since 4d97cfa) goes green.

@jeffdupont jeffdupont mentioned this pull request Oct 15, 2026
@XieX
XieX merged commit c4691cd into main Oct 15, 2026
10 checks passed
@XieX
XieX deleted the xie/fix-root-values-graph-track-data branch October 15, 2026 19:45
XieX added a commit that referenced this pull request Oct 19, 2026
… success (#138)

## Problem

With an Anthropic key that had no credits, a Claude Agents run returned
`{ output: 'Credit balance is too low' }` as a successful run.
`config().invoke` tracked `$ld:ai:generation:success`, a caller would
show the error text to a user as model output, and the trace showed an
OK `chat <synthetic>` span.

The Claude Code CLI does not fail a run when an API call fails. Captured
live from Agent SDK 0.3.220 with a rejected key (no credits takes the
same path):

- an assistant message with `model: "<synthetic>"`, `error:
"authentication_failed"`, zero usage, and the error text as content
- then a result with `subtype: "success"`, **`is_error: true`**,
`api_error_status: 401`, `terminal_reason: "api_error"`, and the error
text in `result`

The handlers checked only `subtype`. The agent SDK itself treats
`is_error` as the failure signal and raises after the result, but the
handler stops reading at the result and never sees that.

## Fix

- `assertRunSucceeded` (exported from `handler.ts`, not from the package
root) fails a run when `subtype !== 'success'` or `is_error === true`,
and narrows the message to `SDKResultSuccess` otherwise. Both handler
paths and `toClaudeAgents` use it.
- `toClaudeAgents` now gates on `message.type === 'result'` instead of
`'result' in message`. The old gate also let an error-subtype result
through as an empty answer. A failed root now rejects and tracks
`$ld:ai:graph:invocation_failure`; a failed sub-agent fails its tool
call.
- An assistant message whose `model` is `<synthetic>` gets no `chat`
span, joins no conversation, and adds no usage. It keys on `model`, not
the `error` field, because the CLI also emits a synthetic message after
a response stops at `max_output_tokens`, and that run can still succeed.
- `agents.md` documents the rule and drops the stale `'result' in
message` example.

## Tests

Six new tests, each failing on `main` for the intended reason: an
API-error result on the blocking and streaming paths, a synthetic
message that shares a real response's id in a run that then succeeds,
and the native graph root (API error, and `error_max_turns`) and
sub-agent cases. A seventh pins that `is_error: false` stays a success.

Changed existing fixtures: two `native-graph.test.ts` results yielded `{
result, usage }` with no `type`, which only worked through the old gate;
they now carry `type: 'result', subtype: 'success'`.

The `client` package-exports snapshot test fails on `main` independently
of this change; #137 fixes it.

Also checked end to end against the real CLI with a fake key and an
empty `CLAUDE_CONFIG_DIR`: both paths reject with `Claude agent run
ended with an error result (HTTP 401): Invalid API key · Fix external
API key`, and the only span is `invoke_agent` with status ERROR.

Spec: TESTING.md §2.2 "Anthropic agents handler — run outcome from the
`result` message" (launchdarkly/ai-sdks-monorepo#62).
Counterpart: launchdarkly/python-ai-sdk#174.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Fixes a case where Claude Agent SDK runs could **succeed** while
returning API error text (e.g. “Credit balance is too low”) because the
CLI emits `subtype: 'success'` with **`is_error: true`**.
> 
> **Run outcome:** Adds exported **`assertRunSucceeded`** and uses it on
blocking, streaming, and **`toClaudeAgents`** paths. Result handling now
gates on **`message.type === 'result'`** instead of `'result' in
message`, so error subtypes without a `result` field and API-error
“success” results both **throw** (generation/graph failure tracking
instead of treating error text as model output).
> 
> **Telemetry:** Assistant messages with **`model: '<synthetic>'`** are
ignored for `chat` spans, conversation history, and usage so
CLI-injected error notices do not pollute traces or span content when a
run later succeeds.
> 
> Docs in **`agents.md`** and new/updated tests cover API errors,
streaming, synthetic messages, and native-graph root/sub-agent failures.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
f5258bb. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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