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

推荐订阅源

I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
B
Blog
罗磊的独立博客
GbyAI
GbyAI
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
The GitHub Blog
The GitHub Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏

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(dev): bound Claude usage debug fetches · openclaw/ope...
vincentkoc · 2026-05-27 · via Recent Commits to openclaw:main

@@ -5,14 +5,26 @@ import os from "node:os";

55

import path from "node:path";

66

import { pathToFileURL } from "node:url";

77

import { normalizeOptionalString } from "../src/shared/string-coerce.ts";

8-

import { maskIdentifier, previewForDevToolLog, redactHomePath } from "./lib/dev-tooling-safety.ts";

8+

import {

9+

maskIdentifier,

10+

parseStrictIntegerOption,

11+

previewForDevToolLog,

12+

redactHomePath,

13+

} from "./lib/dev-tooling-safety.ts";

9141015

type Args = {

1116

agentId: string;

1217

reveal: boolean;

1318

sessionKey?: string;

1419

};

152021+

type FetchOptions = {

22+

fetchImpl?: typeof fetch;

23+

timeoutMs?: number;

24+

};

25+26+

const DEFAULT_FETCH_TIMEOUT_MS = 30_000;

27+1628

const mask = (value: string) => {

1729

return maskIdentifier(

1830

value,

@@ -80,17 +92,68 @@ const pickAnthropicTokens = (store: {

8092

return found;

8193

};

829483-

const fetchAnthropicOAuthUsage = async (token: string) => {

84-

const res = await fetch("https://api.anthropic.com/api/oauth/usage", {

85-

headers: {

86-

Authorization: `Bearer ${token}`,

87-

Accept: "application/json",

88-

"anthropic-version": "2023-06-01",

89-

"anthropic-beta": "oauth-2025-04-20",

90-

"User-Agent": "openclaw-debug",

91-

},

95+

const resolveFetchTimeoutMs = (raw = process.env.OPENCLAW_DEBUG_CLAUDE_USAGE_FETCH_TIMEOUT_MS) => {

96+

return parseStrictIntegerOption({

97+

fallback: DEFAULT_FETCH_TIMEOUT_MS,

98+

label: "OPENCLAW_DEBUG_CLAUDE_USAGE_FETCH_TIMEOUT_MS",

99+

min: 1,

100+

raw,

101+

});

102+

};

103+104+

const withFetchTimeout = async <T>(

105+

label: string,

106+

timeoutMs: number,

107+

run: (signal: AbortSignal) => Promise<T>,

108+

): Promise<T> => {

109+

const controller = new AbortController();

110+

let timeout: ReturnType<typeof setTimeout> | undefined;

111+

const timeoutPromise = new Promise<T>((_resolve, reject) => {

112+

timeout = setTimeout(() => {

113+

const error = new Error(`${label} exceeded timeout of ${timeoutMs}ms`);

114+

reject(error);

115+

controller.abort(error);

116+

}, timeoutMs);

92117

});

93-

const text = await res.text();

118+

try {

119+

return await Promise.race([run(controller.signal), timeoutPromise]);

120+

} finally {

121+

if (timeout) {

122+

clearTimeout(timeout);

123+

}

124+

}

125+

};

126+127+

const fetchText = async (

128+

label: string,

129+

url: string,

130+

init: RequestInit,

131+

options: FetchOptions = {},

132+

) => {

133+

const fetchImpl = options.fetchImpl ?? fetch;

134+

const timeoutMs = options.timeoutMs ?? resolveFetchTimeoutMs();

135+

return await withFetchTimeout(label, timeoutMs, async (signal) => {

136+

const res = await fetchImpl(url, { ...init, signal });

137+

const text = await res.text();

138+

return { res, text };

139+

});

140+

};

141+142+

const fetchAnthropicOAuthUsage = async (token: string, options: FetchOptions = {}) => {

143+

const { res, text } = await fetchText(

144+

"Anthropic OAuth usage request",

145+

"https://api.anthropic.com/api/oauth/usage",

146+

{

147+

headers: {

148+

Authorization: `Bearer ${token}`,

149+

Accept: "application/json",

150+

"anthropic-version": "2023-06-01",

151+

"anthropic-beta": "oauth-2025-04-20",

152+

"User-Agent": "openclaw-debug",

153+

},

154+

},

155+

options,

156+

);

94157

return { status: res.status, contentType: res.headers.get("content-type"), text };

95158

};

96159

@@ -303,15 +366,19 @@ const findClaudeSessionKey = (): { sessionKey: string; source: string } | null =

303366

return null;

304367

};

305368306-

const fetchClaudeWebUsage = async (sessionKey: string) => {

369+

const fetchClaudeWebUsage = async (sessionKey: string, options: FetchOptions = {}) => {

307370

const headers = {

308371

Cookie: `sessionKey=${sessionKey}`,

309372

Accept: "application/json",

310373

"User-Agent":

311374

"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15",

312375

};

313-

const orgRes = await fetch("https://claude.ai/api/organizations", { headers });

314-

const orgText = await orgRes.text();

376+

const { res: orgRes, text: orgText } = await fetchText(

377+

"Claude organizations request",

378+

"https://claude.ai/api/organizations",

379+

{ headers },

380+

options,

381+

);

315382

if (!orgRes.ok) {

316383

return { ok: false as const, step: "organizations", status: orgRes.status, body: orgText };

317384

}

@@ -321,8 +388,12 @@ const fetchClaudeWebUsage = async (sessionKey: string) => {

321388

return { ok: false as const, step: "organizations", status: 200, body: orgText };

322389

}

323390324-

const usageRes = await fetch(`https://claude.ai/api/organizations/${orgId}/usage`, { headers });

325-

const usageText = await usageRes.text();

391+

const { res: usageRes, text: usageText } = await fetchText(

392+

"Claude usage request",

393+

`https://claude.ai/api/organizations/${orgId}/usage`,

394+

{ headers },

395+

options,

396+

);

326397

return usageRes.ok

327398

? { ok: true as const, orgId, body: usageText }

328399

: { ok: false as const, step: "usage", status: usageRes.status, body: usageText };

@@ -397,7 +468,9 @@ export const testing = {

397468

CLAUDE_COOKIE_HOST_SQL,

398469

CLAUDE_FIREFOX_COOKIE_HOST_SQL,

399470

browserRootLabel,

471+

fetchAnthropicOAuthUsage,

400472

mask,

473+

resolveFetchTimeoutMs,

401474

};

402475403476

if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {