Skip to content

fix(auto): honour a dropped incoming parent in the zero-code Node agent - #715

Merged
nik13 merged 9 commits into
devfrom
fix/node-orphan-1118
Nov 18, 2026
Merged

nik13 merged 9 commits into
devfrom
fix/node-orphan-1118

Conversation

@nik13

@nik13 nik13 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

What

When an upstream service drops a trace, it still sends traceparent: 00-<trace>-<span>-00 (sampled flag 0). The zero-code Node agent did not honour that non-recording parent. The next AI call in the request started a new root trace, which exported an orphan chat span under a fresh trace id.

Change (typescript/packages/traceai_auto/src/agent-context.ts)

  • A valid but non-recording incoming parent is now installed for the request. AI calls in that request become its children, so the default parent-based sampler drops them: nothing is exported and no new trace id is created.
  • The dropped parent's lifetime is tracked apart from isRecording(). A parent that has really ended is never reused, including from contexts derived from it (withSession, nested call scopes).
  • Cross-cell unwinding is limited to ended dropped requests. All-recording chains keep their existing parentage and session metadata.
  • A non-recording HTTP span is installed only when it is a valid local child: same trace id, a distinct span id, not remote. An echoed no-op span from a supplied tracer can no longer replace a live sampled parent.

Tests

  • integration-call-scope.test.ts: live and ended unsampled incoming requests, derived session contexts, nested cells ending out of order, a dropped request under a live grandparent, and a no-op HTTP tracer on a supplied provider.
  • e2e.test.ts: the default-sampler case runs with an isolated empty config file (test/apps/empty.toml).
  • ratio-cross-language.test.ts: Python to Node dropped and kept traces. It is opt-in with TRACEAI_TEST_PYTHON, so the ordinary job does not need a Python install.
  • Full @traceai/auto suite: 1,827 passed, 14 skipped. Vercel package: 280/280.

All changes are limited to typescript/packages/traceai_auto/.

Cover awaited nested-call and explicit parents with and without a previous span. Before the fix, both keep the ended request. The existing cross-language cases also fail in the ordinary Node-only environment because they launch system Python.
Track dropped request lifetimes weakly across package copies. When a helper or explicit parent carries an ended request, restore the previous parent span without replacing its derived context values.
@nik13
nik13 marked this pull request as ready for review November 18, 2026 20:59
@nik13
nik13 merged commit 3a849a2 into dev Nov 18, 2026
12 checks passed
@nik13
nik13 deleted the fix/node-orphan-1118 branch November 18, 2026 20:59
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