Skip to content

fix(telemetry): Propagate daemon ACP trace context#5047

Merged
doudouOUC merged 1 commit into
QwenLM:mainfrom
doudouOUC:codex/daemon-acp-trace-continuity
Jun 12, 2026
Merged

fix(telemetry): Propagate daemon ACP trace context#5047
doudouOUC merged 1 commit into
QwenLM:mainfrom
doudouOUC:codex/daemon-acp-trace-continuity

Conversation

@doudouOUC

Copy link
Copy Markdown
Collaborator

What this PR does

This PR keeps daemon-to-ACP telemetry stitched through prompt dispatch by deriving the ACP prompt metadata traceparent from the active daemon bridge span instead of relying on the global outbound propagator. It also records the generated prompt id on the active daemon HTTP request span and stamps deferred blocked-on-user and hook spans with the owning session id resolved from their logical parent context.

The regression coverage exercises the daemon trace metadata injection path, the bridge prompt dispatch span ordering, the daemon prompt id span attribute, and the multi-session session attribution cases for deferred spans.

Why it's needed

qwen serve installs a no-op outbound propagator by default, so using propagation.inject() for daemon-to-ACP prompt metadata could leave the ACP child interaction without a usable parent traceparent. The daemon HTTP span also generated a promptId without attaching it to the current request span, and some deferred spans could fall back to a stale process-global session id in multi-session daemon scenarios. Together these gaps made the daemon HTTP span → bridge span → ACP child interaction span chain harder to reconstruct in OTel backends.

Reviewer Test Plan

How to verify

Run cd packages/core && npx vitest run src/telemetry/daemon-tracing.test.ts src/telemetry/session-tracing.test.ts and expect 130 passing tests.

Run cd packages/acp-bridge && npx vitest run src/bridge.test.ts and expect 251 passing tests.

Run cd packages/cli && npx vitest run src/serve/server.test.ts and expect 408 passing tests.

Run npx prettier --check packages/core/src/telemetry/daemon-tracing.ts packages/core/src/telemetry/daemon-tracing.test.ts packages/core/src/telemetry/session-tracing.ts packages/core/src/telemetry/session-tracing.test.ts packages/cli/src/serve/server.ts packages/cli/src/serve/server.test.ts packages/acp-bridge/src/bridge.test.ts and expect all matched files to use Prettier code style.

Run npm run build && npm run typecheck and expect exit code 0. Local output still includes existing VS Code companion curly lint warnings, Browserslist stale-data warnings, and the existing web-shell chunk-size warning.

Evidence (Before & After)

N/A

Tested on

OS Status
🍏 macOS ✅ tested
🪟 Windows ⚠️ not tested
🐧 Linux ⚠️ not tested

Environment (optional)

Node.js v22.22.3, npm 10.9.8.

Risk & Scope

  • Main risk or tradeoff: The daemon now synthesizes ACP prompt traceparent from the active span and continues stripping client-supplied reserved trace metadata; tracestate is not synthesized because this codebase has no internal tracestate source for this path.
  • Not validated / out of scope: Windows and Linux were not run locally; CI should cover cross-platform behavior.
  • Breaking changes / migration notes: None.

Linked Issues

Related to #4554.

中文说明

What this PR does

这个 PR 让 daemon 到 ACP 的 prompt dispatch telemetry 链路保持贯通:ACP prompt metadata 里的 traceparent 改为从当前 active daemon bridge span 派生,不再依赖全局 outbound propagator。同时,生成的 prompt id 会写到当前 daemon HTTP request span 上,deferred 的 blocked-on-user 和 hook spans 也会从逻辑父上下文解析 owning session id。

回归测试覆盖 daemon trace metadata 注入路径、bridge prompt dispatch span 顺序、daemon prompt id span attribute,以及 deferred spans 在多 session 场景下的 session 归因。

Why it's needed

qwen serve 默认安装 no-op outbound propagator,因此用 propagation.inject() 写 daemon 到 ACP 的 prompt metadata 时,ACP child interaction 可能拿不到可用的父级 traceparent。daemon HTTP span 也生成了 promptId 但没有写回当前 request span,部分 deferred spans 在多 session daemon 场景下还可能退回到过期的进程全局 session id。这些缺口会让 OTel 后端里 “daemon HTTP span → bridge span → ACP child interaction span” 链路更难还原。

Reviewer Test Plan

How to verify

运行 cd packages/core && npx vitest run src/telemetry/daemon-tracing.test.ts src/telemetry/session-tracing.test.ts,预期 130 个测试通过。

运行 cd packages/acp-bridge && npx vitest run src/bridge.test.ts,预期 251 个测试通过。

运行 cd packages/cli && npx vitest run src/serve/server.test.ts,预期 408 个测试通过。

运行 npx prettier --check packages/core/src/telemetry/daemon-tracing.ts packages/core/src/telemetry/daemon-tracing.test.ts packages/core/src/telemetry/session-tracing.ts packages/core/src/telemetry/session-tracing.test.ts packages/cli/src/serve/server.ts packages/cli/src/serve/server.test.ts packages/acp-bridge/src/bridge.test.ts,预期所有匹配文件符合 Prettier 格式。

运行 npm run build && npm run typecheck,预期退出码为 0。本地输出仍包含既有的 VS Code companion curly lint warnings、Browserslist stale-data warnings,以及既有的 web-shell chunk-size warning。

Evidence (Before & After)

N/A

Tested on

OS Status
🍏 macOS ✅ tested
🪟 Windows ⚠️ not tested
🐧 Linux ⚠️ not tested

Environment (optional)

Node.js v22.22.3,npm 10.9.8。

Risk & Scope

  • Main risk or tradeoff: daemon 现在会从 active span 合成 ACP prompt traceparent,并继续剥离客户端传入的保留 trace metadata;由于这条路径在代码库里没有内部 tracestate 来源,因此不会合成 tracestate
  • Not validated / out of scope: 本地未跑 Windows 和 Linux;跨平台行为交给 CI 覆盖。
  • Breaking changes / migration notes: 无。

Linked Issues

关联 #4554

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@doudouOUC doudouOUC marked this pull request as ready for review June 12, 2026 12:40
Copilot AI review requested due to automatic review settings June 12, 2026 12:40

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wenshao wenshao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No issues found. LGTM! ✅ — qwen3.7-max via Qwen Code /review

@doudouOUC

Copy link
Copy Markdown
Collaborator Author

@qwen-code /review

@github-actions

Copy link
Copy Markdown
Contributor
_Qwen Code review request accepted. Review is queued in [workflow run](https://github.com/QwenLM/qwen-code/actions/runs/27425035889)._

@yiliang114 yiliang114 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@doudouOUC doudouOUC merged commit a283ca0 into QwenLM:main Jun 12, 2026
40 checks passed
@doudouOUC doudouOUC deleted the codex/daemon-acp-trace-continuity branch June 12, 2026 16:11
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.

4 participants