Repository navigation
Antigravity: track subagents as tasks on the parent, and count tokens from the transcript - #2827
Open
peyton-alt wants to merge 6 commits into
Open
peyton-alt wants to merge 6 commits into
peyton-alt wants to merge 6 commits into
Conversation
agy writes each model call's usage on its PLANNER_RESPONSE transcript step. Entire read only the statusline snapshots, which miss the turn's last call when Stop fires before the snapshot lands, track context fill rather than a running input total, and never fire for subagent conversations or print mode. In a live session that recorded 95 input tokens for four turns that used 48,383. Implement TokenCalculator over those steps. It returns nil when no step in range has the fields, so older agy keeps the statusline fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5B8ZKKG267HXYPGTACPA40Y
agy runs invoke_subagent as a conversation with its own hooks, which Entire tracked as an unrelated top-level session. Implement SubagentSessionResolver from the two steps agy writes to link them, and mark the subagent's session once its parent is known: it never links a commit, condenses on its own, or answers caller resolution, and its file changes go to the parent, where a live task record carries its transcript so far. A parent waiting on a subagent is resumed by a new execution whose first PreInvocation has invocationNum 0. That restarted the parent's turn, so everything before the last resume dropped out of the turn's tokens. Treat invocationNum 0 as a new turn only when the transcript ends with the prompt's USER_INPUT step, which a resume does not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5BF7Q8MB15D3SCP09NACCD4
A marked subagent session now rebuilds its link from the parent's task record instead of re-reading both transcripts on every hook, and refreshes the parent's interaction time at most once a minute. agy's resolver reads only the head of the child's transcript and decodes only the parent lines that can name the child. A read-only subagent, which reaches no ToolUse, is marked on its suppressed follow-up calls. Condensing a subagent's own session (doctor, the exited-owner sweep) used to return success having done nothing, so it was offered again forever. It now moves any files it holds to the parent and marks itself fully condensed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5BFZYV1XFPD68WPTNB4APB0
agy reports a parent's Stop with fullyIdle=false while its subagents run. When that Stop lands before the last subagent's turn ends, agy sends the parent nothing further, so its turn never ended and its tokens never reached the session total; in -p mode every such parent stayed ACTIVE. A fullyIdle=false Stop now records the pause, a resume clears it, and whichever hook sees both the pause and the last subagent finished (the subagent's turn end or the parent's Stop, which land milliseconds apart in either order) claims it and ends the parent's turn as a reported one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5BKRYD73JMN0W6J7WN79B7R
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b96ae0f. Configure here.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved lifecycle and attribution errors can prematurely finalize checkpoints, miscount tokens or lose pending file handoffs.
5 open issues
Early tool filtering misses child attribution and commits · New Wake-up loses parent turn checkpoint bookkeeping · New Pause finalization races with concurrent stop and resume · New Task records misrepresent child liveness and completion · New Child handoff erases files before parent persistence succeeds · New
What changed in this PR
Improves Antigravity tracking in Entire CLI by counting transcript tokens and associating detached subagents with their parent sessions.
Changes:
- Reads per-call transcript usage, retaining the older statusline fallback.
- Records subagents as parent tasks and excludes them from standalone attribution.
- Adds pause/resume handling, regression tests and documentation.
| File | Description |
|---|---|
| docs/architecture/agent-guide.md | Documents token sources and detached subagents. |
| cmd/entire/cli/strategy/subagent_session_test.go | Tests child exclusion and file handoff. |
| cmd/entire/cli/strategy/session_identity.go | Excludes children from commit linking. |
| cmd/entire/cli/strategy/manual_commit_condensation.go | Transfers child work to parents. |
| cmd/entire/cli/strategy/manual_commit_condensation_test.go | Clarifies fallback test comments. |
| cmd/entire/cli/strategy/caller_session.go | Excludes children from caller resolution. |
| cmd/entire/cli/state.go | Clarifies token-baseline comments. |
| cmd/entire/cli/session/state.go | Adds parent linkage and pause state. |
| cmd/entire/cli/lifecycle.go | Coordinates child attribution and parent completion. |
| cmd/entire/cli/integration_test/antigravity_transcript_tokens_test.go | Tests transcript-based token accounting. |
| cmd/entire/cli/integration_test/antigravity_subagent_test.go | Tests subagent attribution and hook ordering. |
| cmd/entire/cli/agent/event.go | Adds the awaiting-subagents event flag. |
| cmd/entire/cli/agent/antigravity/transcript.go | Reuses step constants; updates comments. |
| cmd/entire/cli/agent/antigravity/tokens.go | Implements transcript token calculation. |
| cmd/entire/cli/agent/antigravity/tokens_test.go | Tests offsets, fallback and deduplication. |
| cmd/entire/cli/agent/antigravity/testdata/transcript_tokens.jsonl | Adds captured token fixtures. |
| cmd/entire/cli/agent/antigravity/subagent_session.go | Resolves parent links and detects prompts. |
| cmd/entire/cli/agent/antigravity/subagent_session_test.go | Tests linking and wake-up detection. |
| cmd/entire/cli/agent/antigravity/statusline.go | Documents fallback behavior. |
| cmd/entire/cli/agent/antigravity/lifecycle.go | Distinguishes prompts, wake-ups and pauses. |
| cmd/entire/cli/agent/antigravity/lifecycle_test.go | Tests paused Stop events. |
| cmd/entire/cli/agent/antigravity/AGENT.md | Updates integration behavior and limitations. |
| cmd/entire/cli/agent/agent.go | Clarifies token-source interface comments. |
Review effort: Balanced
… turn The parent's turn waited for every uncompleted task record, so one left open by a subagent that crashed or was killed kept it ACTIVE for good. Only a record whose subagent session is still ACTIVE, with a live owner and not stuck, counts as running. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5BNCTWVDK4352DK9CGTB81N
…ask records Review found the parent's turn could end too early or never: task records track pending checkpoint work, not which subagents run. A subagent woken again kept its completed record, a commit could prune the record that signalled completion, an unmarked subagent had no record at all, and a parent about to wake on a reply was ended first. The parent's turn now ends only once every subagent the turn involved (launched, messaged, or heard from, per the parent's transcript) has stopped and every reply it sent is in the parent's transcript; a reply still in flight will wake the parent. A subagent whose agent died counts as stopped. The claim lasts for the turn, so a later pause cannot re-arm it. New agent capability: SubagentReplyCounter. Also: a subagent is marked at any tool call, not only file edits, since a shell command can edit and commit; and condensing a subagent's session hands its files to the parent before removing them, leaving them retryable when the parent cannot take them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Entire-Checkpoint: 01M5BRJSZB9JHY9PCRBHZVJ7C6
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.io/gh/entireio/cli/trails/1619
Problem
Entire tracks Antigravity (agy) subagents as unrelated top-level sessions and counts agy's tokens from the wrong source. A live run on main (agy 1.4.2, one subagent):
The causes:
total_input_tokensis how full the context is, not a running total;agy -p.invoke_subagentas a separate conversation with its own hooks, and Entire records it as a separate top-level session.invocationNum0. That fired an unconditional TurnStart, so everything before the last resume dropped out of the turn.fullyIdle: false) lands before the subagent finishes, agy sends the parent nothing further. Its turn never ends, and in-pmode the parent stays ACTIVE as a ghost.Change
input_tokens,output_tokensandcache_read_tokenson itsPLANNER_RESPONSEstep intranscript_full.jsonl.TokenCalculatorover those steps, soresolveTurnTokenUsagereads them before the statusline.output_tokensalready includes reasoning: in print mode agy reportsthinking_tokens2310 insideoutput_tokens2313.SubagentSessionResolver, the interface Factory Droid Workers use.SYSTEM_MESSAGEwithsender=<parent>;TypeNameandRole.ParentSessionID. Such a session never links a commit, never condenses on its own, and is never picked as "the calling session". Identity matching would otherwise tie it with the parent, because they share an agy process.USER_INPUTstep is already in the transcript, while a subagent's reply isn't yet. SoinvocationNum0 starts a turn unconditionally only when the transcript ends withUSER_INPUT, or doesn't exist yet. An Esc-interrupted turn fires no Stop at all, and the next prompt still starts its own turn.fullyIdle: falseStop records the pause (AwaitingSubagentsAt), and a resume clears it.Tests
Unit tests:
Integration tests (simulated hooks, in the hook order captured from live agy):
tasks/<child>/, and the parent's turn kept whole across the wake-up;Each fails without its change.
Live runs with this branch (agy 1.4.2):
notes.txtnotes2.txttasks/<child>/, with the child's transcript, files, type and description.Known limits and follow-ups
input_tokensincludescache_read_tokensis unknown. Both are mapped across as they are.task.jsonbut not the checkpoint total orentire status. Separate PR; an audit found this is right for OpenCode, Droid and agy, and would double count for Claude Code, Codex and Copilot.🤖 Generated with Claude Code