agentHost: rotate stale OTel session anchors - #334584
Open
Austin Traver (austintraver) wants to merge 1 commit into
Open
agentHost: rotate stale OTel session anchors#334584Austin Traver (austintraver) wants to merge 1 commit into
Austin Traver (austintraver) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: TylerLeonhardtMatched files:
|
Copilot started reviewing on behalf of
Austin Traver (austintraver)
September 4, 2026 18:57
View session
Contributor
There was a problem hiding this comment.
🟡 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
traceparentortracestatechangesProblem
Agent Host currently creates a zero-duration
vscode.agent_host.sessionparent 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 --skipLibCheckNODE_OPTIONS=--max-old-space-size=8192 npm run gulp compile-client(compile-srccompleted with 0 errors; unrelated generatedmonaco.d.tsdrift from currentmainwas 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