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

推荐订阅源

U
Unit 42
博客园 - Franky
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
爱范儿
爱范儿
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
Microsoft Security Blog
Microsoft Security Blog
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)

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(llm): keep OpenAI-compatible reasoning streams active...
steipete · 2026-06-02 · via Recent Commits to openclaw:main

@@ -2657,6 +2657,11 @@ async function processOpenAICompletionsStream(

26572657

let sawStopFinishReason = false;

26582658

const blockIndex = () => output.content.length - 1;

26592659

const measureUtf8Bytes = (text: string) => Buffer.byteLength(text, "utf8");

2660+

let chunkPushedEvent = false;

2661+

const pushStreamEvent = (event: unknown) => {

2662+

chunkPushedEvent = true;

2663+

stream.push(event);

2664+

};

26602665

const finishCurrentBlock = () => {

26612666

if (!currentBlock) {

26622667

return;

@@ -2697,13 +2702,13 @@ async function processOpenAICompletionsStream(

26972702

currentBlock = {

26982703

type: "thinking",

26992704

thinking: "",

2700-

thinkingSignature: reasoningDelta.signature,

2705+

...(reasoningDelta.signature ? { thinkingSignature: reasoningDelta.signature } : {}),

27012706

};

27022707

output.content.push(currentBlock);

2703-

stream.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });

2708+

pushStreamEvent({ type: "thinking_start", contentIndex: blockIndex(), partial: output });

27042709

}

27052710

currentBlock.thinking += reasoningDelta.text;

2706-

stream.push({

2711+

pushStreamEvent({

27072712

type: "thinking_delta",

27082713

contentIndex: blockIndex(),

27092714

delta: reasoningDelta.text,

@@ -2715,10 +2720,10 @@ async function processOpenAICompletionsStream(

27152720

finishCurrentBlock();

27162721

currentBlock = { type: "text", text: "" };

27172722

output.content.push(currentBlock);

2718-

stream.push({ type: "text_start", contentIndex: blockIndex(), partial: output });

2723+

pushStreamEvent({ type: "text_start", contentIndex: blockIndex(), partial: output });

27192724

}

27202725

currentBlock.text += text;

2721-

stream.push({

2726+

pushStreamEvent({

27222727

type: "text_delta",

27232728

contentIndex: blockIndex(),

27242729

delta: text,

@@ -2782,12 +2787,12 @@ async function processOpenAICompletionsStream(

27822787

};

27832788

currentBlock = block;

27842789

output.content.push(block);

2785-

stream.push({

2790+

pushStreamEvent({

27862791

type: "toolcall_start",

27872792

contentIndex: output.content.indexOf(block),

27882793

partial: output,

27892794

});

2790-

stream.push({

2795+

pushStreamEvent({

27912796

type: "toolcall_delta",

27922797

contentIndex: output.content.indexOf(block),

27932798

delta: toolCall.partialArgs,

@@ -2853,6 +2858,19 @@ async function processOpenAICompletionsStream(

28532858

appendFilteredVisibleTextDelta(delta.text);

28542859

}

28552860

};

2861+

const emitReasoningUsageActivity = (hasReasoningUsageActivity: boolean) => {

2862+

if (!hasReasoningUsageActivity || chunkPushedEvent || !emitReasoning) {

2863+

return;

2864+

}

2865+

const latestBlock = output.content[output.content.length - 1];

2866+

if (currentBlock?.type === "text" || currentBlock?.type === "toolCall") {

2867+

return;

2868+

}

2869+

if (latestBlock?.type === "text" || latestBlock?.type === "toolCall") {

2870+

return;

2871+

}

2872+

appendThinkingDelta({ signature: "", text: "" });

2873+

};

28562874

const flushReasoningTagTextPartitionerAtEnd = () => {

28572875

for (const delta of reasoningTagTextPartitioner.flush()) {

28582876

appendPartitionedVisibleDelta(delta);

@@ -2861,23 +2879,28 @@ async function processOpenAICompletionsStream(

28612879

const cooperativeScheduler = createModelStreamCooperativeScheduler(options?.signal);

28622880

for await (const rawChunk of responseStream as AsyncIterable<unknown>) {

28632881

throwIfModelStreamAborted(options?.signal);

2882+

chunkPushedEvent = false;

28642883

if (!rawChunk || typeof rawChunk !== "object") {

28652884

await cooperativeScheduler.afterEvent();

28662885

continue;

28672886

}

28682887

const chunk = rawChunk as ChatCompletionChunk;

28692888

output.responseId ||= chunk.id;

2889+

let hasReasoningUsageActivity = false;

28702890

if (chunk.usage) {

28712891

output.usage = parseTransportChunkUsage(chunk.usage, model);

2892+

hasReasoningUsageActivity = hasOpenAICompletionsReasoningUsageActivity(chunk.usage);

28722893

}

28732894

const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : undefined;

28742895

if (!choice) {

2896+

emitReasoningUsageActivity(hasReasoningUsageActivity);

28752897

await cooperativeScheduler.afterEvent();

28762898

continue;

28772899

}

28782900

const choiceUsage = (choice as unknown as { usage?: ChatCompletionChunk["usage"] }).usage;

28792901

if (!chunk.usage && choiceUsage) {

28802902

output.usage = parseTransportChunkUsage(choiceUsage, model);

2903+

hasReasoningUsageActivity = hasOpenAICompletionsReasoningUsageActivity(choiceUsage);

28812904

}

28822905

if (choice.finish_reason) {

28832906

const finishReasonResult = mapStopReason(choice.finish_reason);

@@ -2893,6 +2916,7 @@ async function processOpenAICompletionsStream(

28932916

choice.delta ??

28942917

(choice as unknown as { message?: ChatCompletionChunk["choices"][number]["delta"] }).message;

28952918

if (!choiceDelta) {

2919+

emitReasoningUsageActivity(hasReasoningUsageActivity);

28962920

await cooperativeScheduler.afterEvent();

28972921

continue;

28982922

}

@@ -2961,7 +2985,7 @@ async function processOpenAICompletionsStream(

29612985

...(initialSig ? { thoughtSignature: initialSig } : {}),

29622986

};

29632987

output.content.push(block);

2964-

stream.push({

2988+

pushStreamEvent({

29652989

type: "toolcall_start",

29662990

contentIndex: output.content.indexOf(block),

29672991

partial: output,

@@ -2991,7 +3015,7 @@ async function processOpenAICompletionsStream(

29913015

toolCallBlockBytes.set(block, currentBlockArgBytes + nextArgumentBytes);

29923016

block.partialArgs += toolCall.function.arguments;

29933017

block.arguments = parseStreamingJson(block.partialArgs);

2994-

stream.push({

3018+

pushStreamEvent({

29953019

type: "toolcall_delta",

29963020

contentIndex: output.content.indexOf(block),

29973021

delta: toolCall.function.arguments,

@@ -3001,6 +3025,7 @@ async function processOpenAICompletionsStream(

30013025

}

30023026

}

30033027

flushPendingPostToolCallDeltas();

3028+

emitReasoningUsageActivity(hasReasoningUsageActivity);

30043029

await cooperativeScheduler.afterEvent();

30053030

}

30063031

flushReasoningTagTextPartitionerAtEnd();

@@ -4207,6 +4232,15 @@ export function parseTransportChunkUsage(

42074232

return usage;

42084233

}

420942344235+

function hasOpenAICompletionsReasoningUsageActivity(

4236+

rawUsage: NonNullable<ChatCompletionChunk["usage"]>,

4237+

) {

4238+

const reasoningTokens = rawUsage.completion_tokens_details?.reasoning_tokens;

4239+

return (

4240+

typeof reasoningTokens === "number" && Number.isFinite(reasoningTokens) && reasoningTokens > 0

4241+

);

4242+

}

4243+42104244

function mapStopReason(reason: string | null) {

42114245

if (reason === null) {

42124246

return { stopReason: "stop" };