Repository navigation
Persist provider usage on aborted turns - #428
GraciousGazelles wants to merge 13 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an optional provider_usage field to TurnAbortedEvent to track exact provider-reported token usage across aborted, interrupted, replaced, and budget-limited turns. It updates various tests, event instantiations, and documentation to support this new field while maintaining backward compatibility with legacy rollouts. Feedback suggests improving the robustness of the test helper function remove_provider_usage_from_persisted_turn_complete by filtering out empty lines before parsing them as JSON.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| let lines = contents | ||
| .lines() | ||
| .map(|line| -> Result<String> { | ||
| let mut line: RolloutLine = serde_json::from_str(line)?; | ||
| if let RolloutItem::EventMsg(EventMsg::TurnComplete(completed)) = &mut line.item { | ||
| completed.provider_usage = None; | ||
| found = true; | ||
| } | ||
| Ok(serde_json::to_string(&line)?) | ||
| }) | ||
| .collect::<Result<Vec<_>>>()?; |
There was a problem hiding this comment.
To make the helper function more robust against potential empty lines or trailing whitespace in the rollout file, consider filtering out empty lines before attempting to parse them as JSON. This prevents unexpected test failures if the file format contains empty lines.
| let lines = contents | |
| .lines() | |
| .map(|line| -> Result<String> { | |
| let mut line: RolloutLine = serde_json::from_str(line)?; | |
| if let RolloutItem::EventMsg(EventMsg::TurnComplete(completed)) = &mut line.item { | |
| completed.provider_usage = None; | |
| found = true; | |
| } | |
| Ok(serde_json::to_string(&line)?) | |
| }) | |
| .collect::<Result<Vec<_>>>()?; | |
| let lines = contents | |
| .lines() | |
| .filter(|line| !line.trim().is_empty()) | |
| .map(|line| -> Result<String> { | |
| let mut line: RolloutLine = serde_json::from_str(line)?; | |
| if let RolloutItem::EventMsg(EventMsg::TurnComplete(completed)) = &mut line.item { | |
| completed.provider_usage = None; | |
| found = true; | |
| } | |
| Ok(serde_json::to_string(&line)?) | |
| }) | |
| .collect::<Result<Vec<_>>>()?; |
…rminal-provider-usage-durability
…rminal-provider-usage-durability
c813b4b to
8c80eb5
Compare
Summary
TurnAbortedEventWhy
The complete-turn aggregate introduced by #411 was only emitted on
TurnComplete. If a successful provider response launched a long-running tool and the turn was later interrupted, replaced, or budget-limited, the already-observed exact usage was lost from the terminal event. Provider usage also needed integration coverage through real rollout write/parse/resume paths.Impact
Consumers can account for exact provider-reported usage on aborted terminal paths without estimating it from local token state. The field is optional, so legacy rollout events remain compatible, and persisted receipts do not seed later turns.
Validation
cargo fmt --all -- --checkgit diff --checkjq empty docs/divergences/index.yamljust --show core-multi-agent-orchestration-targeted--no-tests=fail; no new validation-lab run was dispatched before the final stacked headsStacked on #411.