fix(agent): show real token counts in subagent progress - #49
Conversation
Streaming providers (Verboo/OpenAI shim) emit message_start with zeroed usage; the real usage arrives in message_delta, which mutates the last yielded message in place after the consumer already read it. Subagent progress therefore counted tool calls but kept tokens at 0. - Add syncProgressUsageFromMessages() to re-derive token counters from accumulated assistant messages (input cumulative, output summed) - Apply it in runAsyncAgentLifecycle, sync and backgrounded AgentTool paths, both per-message and after the loop ends - Show tokens/tools in the background tasks list (local_agent rows) - Log when a model override is ignored in coordinator mode instead of silently swallowing it - Fix indentation in the backgrounded error block - Sanitize description angle brackets in task notification summary - Add regression test for token convergence after in-place usage mutation
|
Fechando em favor do #51. O bug de token já foi corrigido no Mergear este PR seria pior que não mergear: o git faz auto-merge do E o conserto óbvio (readicionar os campos pra calar o TS) faria os writes virarem no-op silencioso, com o PR parecendo aplicado. O #51 parte do |
Summary
Fixes subagent progress showing tool calls but zero tokens (BUG-1 from review).
Root cause
Streaming providers (Verboo/OpenAI shim) emit
message_startwith zeroed usage; the real usage arrives inmessage_delta, which mutates the last yielded message in place — after the consumer already read it. The subagentProgressTrackertherefore counted tool calls (fromcontent.tool_use) but kept tokens at 0.Changes
LocalAgentTask.tsx: addsyncProgressUsageFromMessages()— re-derives token counters from accumulated assistant messages (input cumulative/latest-wins, output summed per request). The accumulated references are exactly whatmessage_deltamutates in place, so this converges to real usage.agentToolUtils.ts/AgentTool.tsx: apply the recompute inrunAsyncAgentLifecycle, sync path, and backgrounded path — both per-message and after the loop ends (so the final notification carries real totals).BackgroundTask.tsx: show· N tokens · N toolsin the background tasks list forlocal_agentrows (previously only description + status).AgentTool.tsx: log when a model override is ignored in coordinator mode instead of silently swallowing it; fix indentation in the backgrounded error block.LocalAgentTask.tsx: sanitize angle brackets in the task notification summary so a model-supplied description can't break the<summary>envelope.tokenProgress.test.ts— regression test simulating the shim timing (zeroed usage at yield, in-place mutation after) and asserting token convergence.Validation
bun teston related suites: 6 passbun run build: OKtask_progressevents now showtools=2 tokens=11118(previously tokens=0)