Skip to content

Persist provider usage on aborted turns - #428

Closed
GraciousGazelles wants to merge 13 commits into
agent/subagent-completion-provider-receiptfrom
agent/terminal-provider-usage-durability
Closed

GraciousGazelles wants to merge 13 commits into
agent/subagent-completion-provider-receiptfrom
agent/terminal-provider-usage-durability

Conversation

@GraciousGazelles

Copy link
Copy Markdown
Collaborator

Summary

  • add an optional exact provider-usage receipt to TurnAbortedEvent
  • preserve usage through explicit interruption/replacement/budget-limit handling and task self-abort handling
  • distinguish provider-reported zero usage from absent usage in local compaction coverage
  • prove rollout persistence, legacy absence compatibility, and fresh-turn isolation after resume

Why

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 -- --check
  • git diff --check
  • jq empty docs/divergences/index.yaml
  • just --show core-multi-agent-orchestration-targeted
  • focused hosted selectors are registered with --no-tests=fail; no new validation-lab run was dispatched before the final stacked heads

Stacked on #411.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +69 to +79
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<_>>>()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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<_>>>()?;

@GraciousGazelles GraciousGazelles added the code-reviewed Completed required code review label Jul 14, 2026
@GraciousGazelles
GraciousGazelles force-pushed the agent/subagent-completion-provider-receipt branch 2 times, most recently from c813b4b to 8c80eb5 Compare July 28, 2026 14:16
@GraciousGazelles

Copy link
Copy Markdown
Collaborator Author

Closing this dependent draft as superseded by current-main PR #411. Its worthwhile aborted-turn provider-usage durability behavior has been folded into #411; this historical branch is not an independent landing candidate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-reviewed Completed required code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant