Repository navigation
feat(local-agent-loop): 止めた呼び出しの途中までの使用量と session ID を残す - #297
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq
…nt に残す Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq
coji
marked this pull request as ready for review
October 10, 2026 09:48
coji
marked this pull request as draft
October 10, 2026 11:54
assistant メッセージの usage は応答を始めた時点の値で output がほぼ入らないため、 止めた Claude 呼び出しの output が 0 近くで記録されていた。途中の使用量を記録する 呼び出しでは includePartialMessages を有効にし、message_start と message_delta から 応答ごとの output を数える。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq
coji
marked this pull request as ready for review
October 10, 2026 12:05
This was referenced Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
examples/local-agent-loopで、supersede(検査の失敗で止めたレビュー)、factory の時間切れ、run の取り消しで止めた agent 呼び出しにも、止めるまでに受け取ったモデル別の使用量と provider の session ID を残す(#296)。止めた呼び出しの結果は今までどおり使わない。原因は runner ではなく provider だった。runner は途中の使用量を受け取れば残す作りだったが、Claude と Codex の provider はどちらも呼び出しの途中で使用量を通知していなかった(
partialUsage = false)。ADR-0032 の「時間切れの試行は途中の使用量を保つ」も、実際の provider では空振りしていた。includePartialMessagesを有効にし、message_startで応答を、message_deltaでその応答の output を読む(各 leg は応答内で最大の値)。同じ message ID は 1 回だけ数え、<synthetic>と token のないフレームは数えない。subagent は command-mode review だけで数える(最終のmodelUsageと同じ範囲)。session ID は各メッセージから早めに取る。実 provider で、最後まで走らせた呼び出しの最後の途中値が最終 usage と全 leg で一致すること(output 2,529 = 2,529、修正前は 19 対 3,322)と、supersede した呼び出しの output が checkpoint・replay・集計に残ること(11 秒で 474)を確認した。thread/tokenUsage/updatedから当該 turn の累計を作る(再開した thread の過去 turn は含めない、token のない更新は無視)。raw の部品はgenerateTextに渡さず、活動にも数えない。token のある使用量の通知は ADR-0032 どおり無通信タイマーを数え直す。thread ID はonSessionCreatedから取る。1 呼び出し 1 モデルなので、モデル別の内訳は解決済みモデルで記録する(reportedModelにはしない)。partialに保存し、replay で provider を呼ばずに復元する。run の取り消しと lease 喪失は今までどおり start-only checkpoint のuncertainのままで、値は attempt の measurement にだけ残す。最終結果を受けた呼び出しは最終の使用量で置き換え、途中だけの内訳は消す。usageUntilStop(理由、通知件数、最後の通知の時刻と開始からの時間)を付ける。通知が 1 つもなければusageはnullのまま。JSON のstoppedCallsと Markdown の「Usage of stopped calls」節に出す。止めた呼び出しを含む集計はcomplete: false/costComplete: false(下限)として扱う。realInvocationIds・fullLoopVerifiedは変えない。送る前に止めたレビュー(not-sent)は集計に入らない。Test plan
usage: nullで、report で区別できるpnpm validateReview gate
GO in round 5. Reviewed head:
ab9e00fab5b58091ccfa271015843a2edb2b9e95. Base:0f163298f6eae52b8398dcb231cdcc12dfeb8d0d.pnpm validate: pass. CI: pass.06b4d3a): NO-GO. Both tracks independently found two P2s. A call that finished with no final usage after partial reports was summed as complete (B1). After a worker died between the stop checkpoint and the terminal write, dedupe kept the stalestartedrow, so the stopped call was missing from the report (B2). Fixed: anyprovider-partialusage makes a sum a lower bound, and dedupe prefers settled stop rows.362eb40): NO-GO. The Markdown aggregate line used its own dedupe (R2-1). A finished call without final usage or session lost its early values on replay (R2-2). Fixed: one shared invocation selection, and the result checkpoint keepspartialwhen the result lacks usage or session.1849555): NO-GO. The run summary printed an incomplete token total unmarked (R3-1). Fixed:summary.tokensCompleteand(PARTIAL);demo comparetreats incomplete totals as unknown.cc2eb94): NO-GO.demo comparestill counted an incomplete stage's cache reads (R4-1). Fixed.ab9e00f): Codex CLEAR, Opus no blocker.Non-blocking findings (P3):
requireSessioncheck after its checkpoint, if its worker dies before the terminal write, replays without usage. This was possible before this PR, and the window is tiny.experimentalRawEvents. The library offers no other public API for this, and ADR-0034 records it.StoppedCallUsage/UsageUntilStopfields are duplicated, andusageTotalsrepeats the cost calculation.Closes #296
Generated with spec-implement-accept skill
🤖 Generated with Claude Code
https://claude.ai/code/session_013YE1FnUCruD4Mtwbjx3nyq