Skip to content

Account subagent token usage toward root goals - #41183

Merged
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94
Aug 27, 2026
Merged

Account subagent token usage toward root goals#41183
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94

Conversation

@copyberry

@copyberry copyberry Bot commented Aug 27, 2026

Copy link
Copy Markdown

Account subagent token usage toward root goals

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.

copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from 3a45310 to 83a9387 Compare August 27, 2026 19:10
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from 73e22b2 to 5a7563c Compare August 27, 2026 19:13
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from eb1fa10 to 779a81b Compare August 27, 2026 19:16
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from 2ecbd3f to 145b14b Compare August 27, 2026 19:20
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from 696b961 to 9b64d81 Compare August 27, 2026 19:22
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from a5750bf to 0267213 Compare August 27, 2026 19:29
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch from 0267213 to dd9a452 Compare August 27, 2026 19:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +132 to +135
.map(|parent| {
parent
.root_accounting_state()
.unwrap_or_else(|| parent.accounting_state())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +412 to +413
#[tokio::test]
async fn spawned_descendant_usage_exhausts_root_goal_budget_once() -> anyhow::Result<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch from dd9a452 to 4af26c0 Compare August 27, 2026 19:32
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from 34ad9ae to 101ef43 Compare August 27, 2026 19:35
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from 72036bd to b11e0db Compare August 27, 2026 19:37
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch from b11e0db to 16a7765 Compare August 27, 2026 19:37
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch from 16a7765 to ab86c0f Compare August 27, 2026 19:39
copyberry Bot pushed a commit that referenced this pull request Aug 27, 2026
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch from ab86c0f to 5657ebe Compare August 27, 2026 19:40
## 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
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch 2 times, most recently from beaf273 to 4761851 Compare August 27, 2026 19:42
@copyberry
copyberry Bot merged commit 4761851 into main Aug 27, 2026
19 of 24 checks passed
@copyberry
copyberry Bot deleted the copyberry/codex-internal-to-codex-oss/8f97ec6778c55b9adf94b887b5fd03999ed0eb94 branch August 27, 2026 19:43
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant