Skip to content

agentHost: rotate stale OTel session anchors - #334584

Open
Austin Traver (austintraver) wants to merge 1 commit into
microsoft:mainfrom
austintraver:fix/agent-host-otel-anchor-refresh
Open

agentHost: rotate stale OTel session anchors#334584
Austin Traver (austintraver) wants to merge 1 commit into
microsoft:mainfrom
austintraver:fix/agent-host-otel-anchor-refresh

Conversation

@austintraver

@austintraver Austin Traver (austintraver) commented Sep 4, 2026

Copy link
Copy Markdown

Summary

  • replay each synthetic Agent Host session anchor immutably while its generation is current
  • rotate the anchor span ID and timestamp after 12 hours while retaining the native trace ID
  • rematerialize Claude's resumable subprocess when its propagated traceparent or tracestate changes
  • document the downstream trace-segmentation trade-off and cover replay, rotation, and Claude rebind behavior with tests

Problem

Agent Host currently creates a zero-duration vscode.agent_host.session parent and can reference that same span for the entire lifetime of a persisted session. Native-OTLP consumers may retain their trace/span-to-run parent-resolution mappings only temporarily. After that state expires, a consumer can acknowledge a late child with HTTP 200 but never materialize it.

I reproduced this with valid late spans still present in Agent Host's local SQLite store while the downstream LangSmith project omitted them. In a controlled comparison, a fresh root materialized but a fresh child referencing an old session anchor did not, despite successful ingestion responses for both.

Re-exporting the identical anchor restores parent-resolution state for shorter idle periods and preserves immutable span identity. It cannot work indefinitely, though: sufficiently old spans can fall outside a downstream ingestion window. Updating the timestamp on the same span ID would mutate history and can produce invalid parent/child chronology.

This change therefore bounds each anchor generation to 12 hours. At the boundary it emits a fresh zero-duration parent with a new span ID and current timestamp, but keeps the session's native trace ID. The interval matches LangSmith's documented self-hosted parent-mapping default and remains inside its observed 24-hour ingestion window; this does not assume LangSmith Cloud uses the same TTL.

Copilot and Codex already resolve the current session context at turn boundaries. Claude receives W3C context through its long-lived subprocess environment, so it uses the existing resumable pipeline rebind path when the context changes. The SDK conversation is resumed rather than replaced.

If a backend's native trace mapping has already expired, it may display a rotated anchor as the beginning of a new backend trace even though the native trace ID is stable. That segmentation is preferable to silently losing every subsequent span.

This is separate from github/copilot-cli#4726, where a post-reload resumed root can omit captured input content.

Validation

  • NODE_OPTIONS=--max-old-space-size=8192 ./node_modules/.bin/tsc6 --project ./src/tsconfig.json --noEmit --skipLibCheck
  • NODE_OPTIONS=--max-old-space-size=8192 npm run gulp compile-client (compile-src completed with 0 errors; unrelated generated monaco.d.ts drift from current main was excluded from this commit)
  • node test/unit/node/index.js --run src/vs/platform/agentHost/test/node/otel/agentHostOTelService.integrationTest.ts --run src/vs/platform/agentHost/test/node/claudeAgent.test.ts (307 passing)
  • git diff --check origin/main...HEAD

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 4, 2026 18:54
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

TylerLeonhardt

Matched files:

  • src/vs/platform/agentHost/node/claude/claudeAgentSession.ts

Copilot AI 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.

🟡 Changes recommended

Peer chats use inconsistent anchor keys, and anchor delivery is not ordered before provider spans.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates Agent Host OTel session anchors to remain resolvable for long-lived sessions.

Changes:

  • Replays anchors and rotates them after 12 hours while preserving trace IDs.
  • Rebuilds Claude subprocesses when propagated trace context changes.
  • Adds documentation and tests for replay, rotation, and rebinding.
File summaries
File Description
src/vs/platform/agentHost/OTEL.md Documents anchor rotation behavior.
src/vs/platform/agentHost/common/otel/agentHostOTelService.ts Updates the trace-context contract.
src/vs/platform/agentHost/node/otel/agentHostOTelService.ts Implements anchor replay and rotation.
src/vs/platform/agentHost/node/claude/claudeAgentSession.ts Rebinds Claude when context changes.
src/vs/platform/agentHost/test/node/otel/agentHostOTelService.integrationTest.ts Tests anchor replay and rotation.
src/vs/platform/agentHost/test/node/claudeAgent.test.ts Tests Claude trace-context rebinding.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// New turn: reset the per-turn credit accumulator so proxy reports
// for this turn's `/v1/messages` calls sum from zero.
this._currentTurnNanoAiu = 0;
const traceContext = this._otelService.getSessionTraceContext(this.sessionId, resource.toString());
Comment on lines +312 to +314
if (existing && Date.now() - existing.timestamp < SESSION_TRACE_ANCHOR_MAX_AGE_MS) {
this._emitSessionAnchor(existing);
return existing.context;
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