Repository navigation
Count OpenCode child sessions and Droid Workers in the parent's tokens - #2824
Merged
Merged
Conversation
OpenCode child sessions and Factory AI Droid Workers keep their usage in their own sessions, so the parent's transcript never carries it and no total included it. The completion that claims a child's task record now credits its usage once to a new summed field, ChildSessionTokens, kept apart from the replace-on-snapshot SubagentTokens. A bounded ledger of credited calls outlives condensation, so a repeated stop is not counted again. Checkpoint metadata adds the pending share; status, sessions and session tokens show it. OpenCode marks its stops with SubagentUsageOutsideParent. The explain header total now includes subagents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5BHS1AQB3Z2RF41XC9A5BDG
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Finalization and recovery can omit child usage, while concurrent attach can count it twice.
3 open issues
What changed in this PR
Includes OpenCode child-session and Droid Worker usage in parent-session totals and checkpoint metadata.
Changes:
- Adds separate child-token accounting and a bounded deduplication ledger.
- Updates checkpoint, attach, adopt, and display paths.
- Adds regression tests and documents accounting behavior.
| File | Description |
|---|---|
| docs/development/checkpoint-implementation.md | Documents child-token accounting. |
| cmd/entire/cli/strategy/task_token_usage_test.go | Tests credits and checkpoint windows. |
| cmd/entire/cli/strategy/manual_commit_git.go | Credits completed child tasks. |
| cmd/entire/cli/strategy/manual_commit_condensation.go | Includes pending child usage in checkpoints. |
| cmd/entire/cli/status.go | Displays combined totals. |
| cmd/entire/cli/sessions.go | Updates session token displays. |
| cmd/entire/cli/session/state.go | Adds child totals, baselines, and ledger. |
| cmd/entire/cli/session/state_test.go | Tests deduplication and totals. |
| cmd/entire/cli/session_tokens.go | Includes children in token reports. |
| cmd/entire/cli/session_adopt.go | Preserves child accounting during adoption. |
| cmd/entire/cli/lifecycle.go | Routes child completions to crediting. |
| cmd/entire/cli/integration_test/opencode_subagent_test.go | Tests child totals across commits. |
| cmd/entire/cli/integration_test/factoryai_worker_session_test.go | Checks Worker totals across checkpoints. |
| cmd/entire/cli/explain.go | Includes subagents in header totals. |
| cmd/entire/cli/explain_test.go | Tests subagent-inclusive headers. |
| cmd/entire/cli/attach.go | Detects concurrent child-token changes. |
| cmd/entire/cli/agent/opencode/lifecycle.go | Marks separately accounted child usage. |
| cmd/entire/cli/agent/event.go | Defines the child-usage event flag. |
Review effort: Balanced
…tokens-in-totals # Conflicts: # cmd/entire/cli/integration_test/opencode_subagent_test.go
…tokens-in-totals # Conflicts: # docs/development/checkpoint-implementation.md
The SessionEnd sweep completed a still-running OpenCode child without crediting its tokens, and a later stop then found the record completed, so the child never counted. OpenCode now declares agent.ChildSessionSubagents instead of flagging each stop event, so every completion credits; the sweep records the call's start as unknown. The credit ledger now matches an unknown start on either side, and a child's task entry is no longer recounted at condensation, so it shows the credited figure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5JWF8AHV4JM0J93SGX0A6CY
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5JWSMSDD6D93B7879RY10SV
Soph
approved these changes
Oct 23, 2026
peyton-alt
added a commit
that referenced
this pull request
Oct 23, 2026
Reconciles with #2824: child sessions (Droid Workers, OpenCode children) are counted only by its child-session credit. The Droid counter reads the session's own files, and ledger checkpoints and attach add the pending child-session tokens as the per-turn path does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5N9V8N0S99EC3S6Z52G2QA9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

https://entire.com/gh/entireio/-/trails/2340/changes/cli/1616
What was missing
OpenCode child sessions and Factory AI Droid Workers keep their token usage in their own sessions. The parent's transcript never includes it, so it was missing from every total: status, sessions, session tokens, attach and checkpoint metadata. The
entire explainheader total also left out subagents.The fix
ChildSessionTokens. It stays separate fromTokenUsage.SubagentTokens, which each turn's snapshot replaces, so a later snapshot cannot erase a Worker.CreditedChildCalls(last 256), survives condensation. It is keyed like completion-record keying: call ID, child and start. A stop repeated after condensation is not credited again. A reused call ID with a new start is still credited. An unknown start on either side matches any entry for the same child and call.agent.ChildSessionSubagents, so every completion of its children credits, including the SessionEnd sweep's completion of a child still running when the session ends. The sweep records the call's start as unknown, and an unknown start on either side matches in the ledger, so a later stop adds nothing. Droid Worker turns are credited on the existing per-turn path.SessionState.TotalTokenUsage().entire explainnow counts subagents in its header total.Overlaps
TestFactoryDroidWorkerTokensComeFromItsOwnSettingsnow also checks thatTotalTokenUsage()counts the Worker once.Known limits
entire session attach, a child's tokens go into the attach checkpoint while its task.json goes into the next one. Nothing is counted twice.Tests
New strategy, session, explain and integration tests. Each one fails on main, and the ledger tests also fail without the ledger.
mise run test:integrationand the canary pass, and lint reports 0 issues.Size: +728/-39.
🤖 Generated with Claude Code