Account subagent token usage toward root goals - #41183
Conversation
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
3a45310 to
83a9387
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
73e22b2 to
5a7563c
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
eb1fa10 to
779a81b
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
2ecbd3f to
145b14b
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
696b961 to
9b64d81
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
a5750bf to
0267213
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
0267213 to
dd9a452
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cde20814f7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| .map(|parent| { | ||
| parent | ||
| .root_accounting_state() | ||
| .unwrap_or_else(|| parent.accounting_state()) |
There was a problem hiding this comment.
Rebind descendants after root runtime reloads
When an existing child rollout is resumed before its root runtime, this one-time lookup produces no root_accounting_state; similarly, a child that survives a root runtime reload retains the obsolete state. Because the value is captured for the lifetime of the child runtime, later token usage never reaches the resumed root goal, silently undercounting tokensUsed and delaying budget enforcement. Resolve or rebind the root state when the root runtime registers or when descendant usage is recorded.
AGENTS.md reference: AGENTS.md:L102-L110
Useful? React with 👍 / 👎.
| #[tokio::test] | ||
| async fn spawned_descendant_usage_exhausts_root_goal_budget_once() -> anyhow::Result<()> { |
There was a problem hiding this comment.
Add an end-to-end subagent accounting test
This coverage directly invokes extension callbacks and manually constructs TokenUsageInfo.last_token_usage, so it cannot catch failures in the real subagent spawn/session-source propagation or production token-update path on which this feature depends. Add a test_codex integration test that actually spawns descendants and verifies the root goal's usage and budget status.
AGENTS.md reference: AGENTS.md:L112-L118
Useful? React with 👍 / 👎.
dd9a452 to
4af26c0
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
34ad9ae to
101ef43
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
72036bd to
b11e0db
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
b11e0db to
16a7765
Compare
16a7765 to
ab86c0f
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
ab86c0f to
5657ebe
Compare
## What changed - Roll token usage from spawned descendants, including nested subagents, into the root goal's usage. - Apply descendant usage during active and idle progress accounting so it contributes to token budgets. - Reset descendant accounting baselines when the active goal changes and preserve usage recorded concurrently with a checkpoint. ## Testing - Cover child and grandchild usage, budget exhaustion, unloaded parent runtimes, goal replacement, idle accounting, and concurrent checkpoints. GitOrigin-RevId: 8f97ec6778c55b9adf94b887b5fd03999ed0eb94
beaf273 to
4761851
Compare
Account subagent token usage toward root goals
What changed
Testing