Skip to content

Persist provider-observed complete-turn usage - #411

Closed
GraciousGazelles wants to merge 19 commits into
mainfrom
agent/subagent-completion-provider-receipt
Closed

GraciousGazelles wants to merge 19 commits into
mainfrom
agent/subagent-completion-provider-receipt

Conversation

@GraciousGazelles

@GraciousGazelles GraciousGazelles commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Stack

Summary

  • add optional backward-compatible TurnCompleteEvent.provider_usage persistence
  • aggregate exact provider-reported usage across successful sampling, local compaction, and remote-v2 compaction completions
  • reset the aggregate once per logical regular task, preserving usage across steering and sampling re-entry
  • distinguish explicit provider-reported zero usage from absent usage
  • cover legacy omission, multi-response aggregation, compaction, steering, failed follow-up, and constructor propagation in the targeted hosted lane

Semantics

  • provider_usage is the element-wise aggregate of provider usage attached to successful response completions
  • estimates, configured identity, session-total deltas, pricing, and call counts are excluded
  • final_model and model_snapshot continue to identify only the terminal successful sampling response
  • the app-server projection and parent-visible completion receipt remain separate follow-up surfaces

Validation

  • cargo fmt --all -- --check from codex-rs
  • git diff --check
  • jq empty docs/divergences/index.yaml
  • just --show core-multi-agent-orchestration-targeted
  • exact hosted selectors use --no-tests=fail and the core integration selector keeps RUST_MIN_STACK=8388608

Validation-lab run #1864 targeted the earlier 44f2df994457f20c480845b973456a151a30bc7d head. Protocol and failed-follow-up coverage passed; two core assertions expected None for fixtures that explicitly report zero usage. Those expectations and the logical-turn reset seam are corrected in the current head. No final-head validation-lab run has been dispatched yet.

Rust compilation and tests were not run locally; the exact regression selections are registered for GitHub-hosted validation.

@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 provider-observed sub-agent completion receipts and turn-scoped response usage aggregation. It adds an optional provider_usage field to TurnCompleteEvent to track element-wise token usage aggregates from successful provider completions, updating sampling, local compaction, and remote-v2 compaction to contribute to this aggregate. Additionally, MultiAgentV2 child completions now forward a bounded, runtime-authored <completion_provider_receipt> before the payload. Feedback on the changes suggests avoiding a potential panic by replacing an unreachable! macro with a defensive fallback when handling unexpected event variants, and optimizing the XML escaping function bounded_xml_value by pre-allocating string capacity and using a for loop instead of fold.

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 thread codex-rs/core/src/session/mod.rs Resolved

@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 provider-observed sub-agent completion receipts and turn-scoped response usage aggregation. It adds an optional provider_usage field to TurnCompleteEvent to aggregate exact provider-reported token usage across successful response completions (including sampling and compaction) in a turn. Additionally, MultiAgentV2 child completions now forward a bounded, runtime-authored <completion_provider_receipt> containing terminal response identity and turn usage before the child-controlled payload. Feedback on the changes points out a potential compilation issue in TurnContext::record_provider_usage where add_assign is used on TokenUsage without ensuring the AddAssign trait is imported or implemented, and suggests performing the element-wise addition manually.

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.

@GraciousGazelles GraciousGazelles changed the title Add provider-observed subagent completion receipts Persist provider-observed turn usage Jul 14, 2026
@GraciousGazelles GraciousGazelles changed the title Persist provider-observed turn usage Persist provider-observed complete-turn usage Jul 14, 2026
@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 from caef870 to 1ffda75 Compare July 28, 2026 08:09
@GraciousGazelles
GraciousGazelles marked this pull request as ready for review July 28, 2026 08:11
@GraciousGazelles
GraciousGazelles force-pushed the agent/subagent-completion-provider-receipt branch from c813b4b to 8c80eb5 Compare July 28, 2026 14:16
@GraciousGazelles

Copy link
Copy Markdown
Collaborator Author

Closing this current-main candidate as infrastructure-blocked after three exact-head hosted retries. The source-level compile, argument-comment lint, CodeQL, smoke, release, and heavy checks passed; the only blocker was the Ubuntu Bazel clippy lane, which reached 21,652/21,653 and was canceled by the hosted 30-minute limit on each attempt. No source diagnostic was reported. The branch and commits remain preserved for a future retry when that hosted lane is healthy; required checks are not being bypassed.

@GraciousGazelles

Copy link
Copy Markdown
Collaborator Author

Reopened per campaign policy: the candidate remains worthwhile. The prior closure reflected repeated hosted Bazel clippy timeouts, not a source failure; required checks are not being bypassed, and the preserved branch will remain open for a valid retry.

@GraciousGazelles
GraciousGazelles enabled auto-merge (squash) July 29, 2026 05:15
@GraciousGazelles

Copy link
Copy Markdown
Collaborator Author

Superseded by #553, the current-main signed replacement with the review fixes applied; #553 has merged through the native queue.

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