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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
月光博客
月光博客
博客园_首页
博客园 - 叶小钗
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
量子位
小众软件
小众软件
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
IT之家
IT之家
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

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(media): retry transient remote media fetches · opencl...
vyctorbrzezo · 2026-05-14 · via Recent Commits to openclaw:main

@@ -316,6 +316,167 @@ describe("readRemoteMediaBuffer", () => {

316316

});

317317

});

318318319+

it("retries transient fetch failures when retry is enabled", async () => {

320+

const transientError = Object.assign(new Error("socket hang up"), { code: "ECONNRESET" });

321+

const fetchImpl = vi

322+

.fn()

323+

.mockRejectedValueOnce(transientError)

324+

.mockResolvedValueOnce(new Response("ok", { status: 200 }));

325+326+

const result = await readRemoteMediaBuffer({

327+

url: "https://example.com/file.bin",

328+

fetchImpl,

329+

lookupFn: makeLookupFn(),

330+

maxBytes: 1024,

331+

retry: { attempts: 3, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },

332+

});

333+334+

expect(result.buffer.toString()).toBe("ok");

335+

expect(fetchImpl).toHaveBeenCalledTimes(2);

336+

});

337+338+

it("retries 5xx responses when retry is enabled", async () => {

339+

const fetchImpl = vi

340+

.fn()

341+

.mockResolvedValueOnce(

342+

new Response("busy", { status: 503, statusText: "Service Unavailable" }),

343+

)

344+

.mockResolvedValueOnce(new Response("ok", { status: 200 }));

345+346+

const result = await readRemoteMediaBuffer({

347+

url: "https://example.com/file.bin",

348+

fetchImpl,

349+

lookupFn: makeLookupFn(),

350+

maxBytes: 1024,

351+

retry: { attempts: 3, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },

352+

});

353+354+

expect(result.buffer.toString()).toBe("ok");

355+

expect(fetchImpl).toHaveBeenCalledTimes(2);

356+

});

357+358+

it("retries 408 responses when retry is enabled", async () => {

359+

const fetchImpl = vi

360+

.fn()

361+

.mockResolvedValueOnce(

362+

new Response("timeout", { status: 408, statusText: "Request Timeout" }),

363+

)

364+

.mockResolvedValueOnce(new Response("ok", { status: 200 }));

365+366+

const result = await readRemoteMediaBuffer({

367+

url: "https://example.com/file.bin",

368+

fetchImpl,

369+

lookupFn: makeLookupFn(),

370+

maxBytes: 1024,

371+

retry: { attempts: 3, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },

372+

});

373+374+

expect(result.buffer.toString()).toBe("ok");

375+

expect(fetchImpl).toHaveBeenCalledTimes(2);

376+

});

377+378+

it("retries transient response body read failures when retry is enabled", async () => {

379+

const transientError = Object.assign(new Error("socket hang up"), { code: "ECONNRESET" });

380+

const fetchImpl = vi

381+

.fn()

382+

.mockResolvedValueOnce(

383+

new Response(

384+

new ReadableStream<Uint8Array>({

385+

start(controller) {

386+

controller.error(transientError);

387+

},

388+

}),

389+

{ status: 200 },

390+

),

391+

)

392+

.mockResolvedValueOnce(new Response("ok", { status: 200 }));

393+394+

const result = await readRemoteMediaBuffer({

395+

url: "https://example.com/file.bin",

396+

fetchImpl,

397+

lookupFn: makeLookupFn(),

398+

maxBytes: 1024,

399+

retry: { attempts: 3, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },

400+

});

401+402+

expect(result.buffer.toString()).toBe("ok");

403+

expect(fetchImpl).toHaveBeenCalledTimes(2);

404+

});

405+406+

it("does not retry 4xx responses", async () => {

407+

const fetchImpl = vi

408+

.fn()

409+

.mockResolvedValueOnce(new Response("missing", { status: 404 }))

410+

.mockResolvedValueOnce(new Response("ok", { status: 200 }));

411+412+

await expect(

413+

readRemoteMediaBuffer({

414+

url: "https://example.com/file.bin",

415+

fetchImpl,

416+

lookupFn: makeLookupFn(),

417+

maxBytes: 1024,

418+

retry: { attempts: 3, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },

419+

}),

420+

).rejects.toMatchObject({ code: "http_error", status: 404 });

421+

expect(fetchImpl).toHaveBeenCalledTimes(1);

422+

});

423+424+

it("does not retry caller aborts", async () => {

425+

const abortError = new Error("This operation was aborted");

426+

abortError.name = "AbortError";

427+

const fetchImpl = vi

428+

.fn()

429+

.mockRejectedValueOnce(abortError)

430+

.mockResolvedValueOnce(new Response("ok", { status: 200 }));

431+432+

await expect(

433+

readRemoteMediaBuffer({

434+

url: "https://example.com/file.bin",

435+

fetchImpl,

436+

lookupFn: makeLookupFn(),

437+

maxBytes: 1024,

438+

retry: { attempts: 3, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },

439+

}),

440+

).rejects.toMatchObject({ code: "fetch_failed" });

441+

expect(fetchImpl).toHaveBeenCalledTimes(1);

442+

});

443+444+

it("does not retry SSRF guard blocks", async () => {

445+

const fetchImpl = vi.fn();

446+447+

await expect(

448+

readRemoteMediaBuffer({

449+

url: "http://127.0.0.1/secret.jpg",

450+

fetchImpl,

451+

lookupFn: makeLookupFn(),

452+

maxBytes: 1024,

453+

retry: { attempts: 3, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },

454+

}),

455+

).rejects.toThrow(/private|internal|blocked/i);

456+

expect(fetchWithSsrFGuardMock).toHaveBeenCalledTimes(1);

457+

expect(fetchImpl).not.toHaveBeenCalled();

458+

});

459+460+

it("does not retry maxBytes failures", async () => {

461+

const fetchImpl = vi

462+

.fn()

463+

.mockResolvedValueOnce(

464+

new Response("large", { status: 200, headers: { "content-length": "5" } }),

465+

)

466+

.mockResolvedValueOnce(new Response("ok", { status: 200 }));

467+468+

await expect(

469+

readRemoteMediaBuffer({

470+

url: "https://example.com/file.bin",

471+

fetchImpl,

472+

lookupFn: makeLookupFn(),

473+

maxBytes: 4,

474+

retry: { attempts: 3, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },

475+

}),

476+

).rejects.toMatchObject({ code: "max_bytes" });

477+

expect(fetchImpl).toHaveBeenCalledTimes(1);

478+

});

479+319480

it.each([

320481

{

321482

name: "bounds error-body snippets instead of reading the full response",

@@ -552,9 +713,10 @@ describe("readRemoteMediaBuffer", () => {

552713

});

553714554715

it("retries saveRemoteMedia after a transient fetch failure", async () => {

716+

const transientError = Object.assign(new TypeError("socket reset"), { code: "ECONNRESET" });

555717

const fetchImpl = vi

556718

.fn()

557-

.mockRejectedValueOnce(new TypeError("socket reset"))

719+

.mockRejectedValueOnce(transientError)

558720

.mockResolvedValueOnce(

559721

new Response(makeStream([new Uint8Array([5, 6])]), {

560722

status: 200,