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

推荐订阅源

H
Help Net Security
月光博客
月光博客
IT之家
IT之家
B
Blog RSS Feed
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
博客园_首页
B
Blog
V
V2EX
腾讯CDC
Vercel News
Vercel News
量子位
Microsoft Security Blog
Microsoft Security Blog

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(google): retry stalled Gemini first response (#79668)...
joshavant · 2026-05-09 · via Recent Commits to openclaw:main

@@ -15,6 +15,7 @@ vi.mock("openclaw/plugin-sdk/provider-transport-runtime", async (importOriginal)

1515

}));

16161717

let buildGoogleGenerativeAiParams: typeof import("./transport-stream.js").buildGoogleGenerativeAiParams;

18+

let buildGoogleGemini3FirstResponseRetryParams: typeof import("./transport-stream.js").buildGoogleGemini3FirstResponseRetryParams;

1819

let createGoogleGenerativeAiTransportStreamFn: typeof import("./transport-stream.js").createGoogleGenerativeAiTransportStreamFn;

1920

let createGoogleVertexTransportStreamFn: typeof import("./transport-stream.js").createGoogleVertexTransportStreamFn;

2021

let hasGoogleVertexAuthorizedUserAdcSync: typeof import("./vertex-adc.js").hasGoogleVertexAuthorizedUserAdcSync;

@@ -85,10 +86,40 @@ function buildSseResponse(events: unknown[]): Response {

8586

});

8687

}

878889+

function buildDelayedSecondSseResponse(params: {

90+

first: unknown;

91+

second: unknown;

92+

delayMs: number;

93+

}): Response {

94+

const encoder = new TextEncoder();

95+

const first = `data: ${JSON.stringify(params.first)}\n\n`;

96+

const second = `data: ${JSON.stringify(params.second)}\n\ndata: [DONE]\n\n`;

97+

let timeout: ReturnType<typeof setTimeout> | undefined;

98+

const body = new ReadableStream<Uint8Array>({

99+

start(controller) {

100+

controller.enqueue(encoder.encode(first));

101+

timeout = setTimeout(() => {

102+

controller.enqueue(encoder.encode(second));

103+

controller.close();

104+

}, params.delayMs);

105+

},

106+

cancel() {

107+

if (timeout) {

108+

clearTimeout(timeout);

109+

}

110+

},

111+

});

112+

return new Response(body, {

113+

status: 200,

114+

headers: { "content-type": "text/event-stream" },

115+

});

116+

}

117+88118

describe("google transport stream", () => {

89119

beforeAll(async () => {

90120

({

91121

buildGoogleGenerativeAiParams,

122+

buildGoogleGemini3FirstResponseRetryParams,

92123

createGoogleGenerativeAiTransportStreamFn,

93124

createGoogleVertexTransportStreamFn,

94125

} = await import("./transport-stream.js"));

@@ -248,6 +279,124 @@ describe("google transport stream", () => {

248279

});

249280

});

250281282+

it("builds a lean Gemini 3 first-response retry payload", () => {

283+

const model = buildGeminiModel({

284+

id: "gemini-3.1-pro-preview",

285+

name: "Gemini 3.1 Pro Preview",

286+

});

287+

const retryPayload = buildGoogleGemini3FirstResponseRetryParams({

288+

model,

289+

request: {

290+

contents: [{ role: "user", parts: [{ text: "hello" }] }],

291+

generationConfig: {

292+

thinkingConfig: {

293+

includeThoughts: true,

294+

thinkingLevel: "HIGH",

295+

},

296+

},

297+

},

298+

});

299+300+

expect(retryPayload?.generationConfig).toEqual({

301+

thinkingConfig: {

302+

thinkingLevel: "LOW",

303+

},

304+

});

305+

});

306+307+

it("retries Gemini 3 requests with lean thinking when the first attempt has no first response", async () => {

308+

vi.stubEnv("OPENCLAW_GOOGLE_GEMINI_FIRST_RESPONSE_RETRY_MS", "10");

309+

guardedFetchMock

310+

.mockImplementationOnce(

311+

(_url: string, init?: RequestInit) =>

312+

new Promise<Response>((_resolve, reject) => {

313+

init?.signal?.addEventListener("abort", () => {

314+

reject(init.signal?.reason ?? new Error("aborted"));

315+

});

316+

}),

317+

)

318+

.mockResolvedValueOnce(

319+

buildSseResponse([

320+

{

321+

candidates: [{ content: { parts: [{ text: "recovered" }] }, finishReason: "STOP" }],

322+

},

323+

]),

324+

);

325+326+

const model = buildGeminiModel({

327+

id: "gemini-3.1-pro-preview",

328+

name: "Gemini 3.1 Pro Preview",

329+

});

330+

const streamFn = createGoogleGenerativeAiTransportStreamFn();

331+

const stream = await Promise.resolve(

332+

streamFn(

333+

model,

334+

{

335+

messages: [{ role: "user", content: "hello", timestamp: 0 }],

336+

tools: [

337+

{

338+

name: "lookup",

339+

description: "Look up a value",

340+

parameters: {

341+

type: "object",

342+

properties: { q: { type: "string" } },

343+

},

344+

},

345+

],

346+

} as never,

347+

{ reasoning: "high" } as never,

348+

),

349+

);

350+

const result = await stream.result();

351+352+

expect(result.content).toEqual([{ type: "text", text: "recovered" }]);

353+

expect(guardedFetchMock).toHaveBeenCalledTimes(2);

354+

const firstBody = JSON.parse(guardedFetchMock.mock.calls[0]?.[1]?.body as string);

355+

const retryBody = JSON.parse(guardedFetchMock.mock.calls[1]?.[1]?.body as string);

356+

expect(firstBody.generationConfig.thinkingConfig).toMatchObject({

357+

includeThoughts: true,

358+

thinkingLevel: "HIGH",

359+

});

360+

expect(retryBody.generationConfig.thinkingConfig).toEqual({

361+

thinkingLevel: "LOW",

362+

});

363+

expect(retryBody.tools).toEqual(firstBody.tools);

364+

});

365+366+

it("keeps streaming after the first Gemini 3 chunk arrives before the retry deadline", async () => {

367+

vi.stubEnv("OPENCLAW_GOOGLE_GEMINI_FIRST_RESPONSE_RETRY_MS", "10");

368+

guardedFetchMock.mockResolvedValueOnce(

369+

buildDelayedSecondSseResponse({

370+

first: {

371+

candidates: [{ content: { parts: [{ text: "first " }] } }],

372+

},

373+

second: {

374+

candidates: [{ content: { parts: [{ text: "second" }] }, finishReason: "STOP" }],

375+

},

376+

delayMs: 25,

377+

}),

378+

);

379+380+

const model = buildGeminiModel({

381+

id: "gemini-3.1-pro-preview",

382+

name: "Gemini 3.1 Pro Preview",

383+

});

384+

const streamFn = createGoogleGenerativeAiTransportStreamFn();

385+

const stream = await Promise.resolve(

386+

streamFn(

387+

model,

388+

{

389+

messages: [{ role: "user", content: "hello", timestamp: 0 }],

390+

} as never,

391+

{ reasoning: "high" } as never,

392+

),

393+

);

394+

const result = await stream.result();

395+396+

expect(result.content).toEqual([{ type: "text", text: "first second" }]);

397+

expect(guardedFetchMock).toHaveBeenCalledTimes(1);

398+

});

399+251400

it("uses bearer auth when the Google api key is an OAuth JSON payload", async () => {

252401

guardedFetchMock.mockResolvedValueOnce(buildSseResponse([]));

253402