惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
博客园 - 司徒正美
V
Visual Studio Blog
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
S
SegmentFault 最新的问题
T
The Blog of Author Tim Ferriss
D
Docker
Vercel News
Vercel News
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
爱范儿
爱范儿
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(diagnostics): harden trace context parsing (#70955) ·...
vincentkoc · 2026-04-24 · via Recent Commits to openclaw:main

@@ -2,9 +2,11 @@ import { randomBytes } from "node:crypto";

2233

const TRACEPARENT_VERSION = "00";

44

const DEFAULT_TRACE_FLAGS = "01";

5+

const MAX_TRACEPARENT_LENGTH = 128;

56

const TRACE_ID_RE = /^[0-9a-f]{32}$/;

67

const SPAN_ID_RE = /^[0-9a-f]{16}$/;

78

const TRACE_FLAGS_RE = /^[0-9a-f]{2}$/;

9+

const TRACEPARENT_VERSION_RE = /^[0-9a-f]{2}$/;

810911

export type DiagnosticTraceContext = {

1012

/** W3C trace id, 32 lowercase hex chars. */

@@ -29,6 +31,22 @@ function isNonZeroHex(value: string): boolean {

2931

return !/^0+$/.test(value);

3032

}

313334+

function randomTraceId(): string {

35+

let traceId = randomHex(16);

36+

while (!isNonZeroHex(traceId)) {

37+

traceId = randomHex(16);

38+

}

39+

return traceId;

40+

}

41+42+

function randomSpanId(): string {

43+

let spanId = randomHex(8);

44+

while (!isNonZeroHex(spanId)) {

45+

spanId = randomHex(8);

46+

}

47+

return spanId;

48+

}

49+3250

export function isValidDiagnosticTraceId(value: unknown): value is string {

3351

return typeof value === "string" && TRACE_ID_RE.test(value) && isNonZeroHex(value);

3452

}

@@ -68,12 +86,19 @@ function normalizeTraceFlags(value: unknown): string | undefined {

6886

export function parseDiagnosticTraceparent(

6987

traceparent: string | undefined,

7088

): DiagnosticTraceContext | undefined {

71-

const parts = traceparent?.trim().toLowerCase().split("-");

72-

if (!parts || parts.length !== 4) {

89+

if (typeof traceparent !== "string" || traceparent.length > MAX_TRACEPARENT_LENGTH) {

90+

return undefined;

91+

}

92+

const parts = traceparent.trim().toLowerCase().split("-");

93+

if (!parts || parts.length < 4) {

7394

return undefined;

7495

}

7596

const [version, traceId, spanId, traceFlags] = parts;

76-

if (version !== TRACEPARENT_VERSION) {

97+

if (

98+

!TRACEPARENT_VERSION_RE.test(version) ||

99+

version === "ff" ||

100+

(version === TRACEPARENT_VERSION && parts.length !== 4)

101+

) {

77102

return undefined;

78103

}

79104

const normalizedTraceId = normalizeTraceId(traceId);

@@ -108,8 +133,8 @@ export function createDiagnosticTraceContext(

108133

input: DiagnosticTraceContextInput = {},

109134

): DiagnosticTraceContext {

110135

const parsed = parseDiagnosticTraceparent(input.traceparent);

111-

const traceId = normalizeTraceId(input.traceId) ?? parsed?.traceId ?? randomHex(16);

112-

const spanId = normalizeSpanId(input.spanId) ?? parsed?.spanId ?? randomHex(8);

136+

const traceId = normalizeTraceId(input.traceId) ?? parsed?.traceId ?? randomTraceId();

137+

const spanId = normalizeSpanId(input.spanId) ?? parsed?.spanId ?? randomSpanId();

113138

const parentSpanId = normalizeSpanId(input.parentSpanId);

114139

return {

115140

traceId,