Repository navigation
fix(grok): count spontaneous root follow-up usage - #327
Merged
Merged
Conversation
xxchan
force-pushed
the
fix/grok-background-usage
branch
from
October 10, 2026 09:16
0465460 to
3805905
Compare
Merged
xxchan
added a commit
that referenced
this pull request
Oct 10, 2026
Release OAR and CLI 0.54.2. This PR changes only the two package version fields. **Fixed: grok's own follow-up turn counts in `usage()`** (#325, #327) - When a background subagent finishes, grok starts a root turn on its own (`prompt_id: "subagent-completed-<child>"`). It has no `session/prompt` answer, which is where OAR read the root's ledger, so its spend was missing from `usage().total`. OAR now adds that turn's `turn_completed.usage` to the same running total as prompt answers, once per native `_meta.eventId`; later prompt answers keep it. The original frames stay in the record stream. - History is never billed again. grok replays old notifications when a session is opened with `session/load`. OAR records, on the wire, whether each notification arrived before or after the session-open answer, even when the ACP SDK delivers it later, and counts only those after it that are not marked as a replay. A resumed or loaded session's total starts empty, as before. **Still not counted, now documented:** a background subagent's own spend when it finishes after the parent's turn ends. grok includes a child's spend in the parent's prompt ledger only when the child finishes during that prompt, and neither `subagent_finished.will_wake`, the model's `background` argument nor the order of the notifications tells OAR which happened (grok can apply the child's usage before it schedules the finished notification on another worker). Grok child ledgers therefore stay native-only and `withChildren` stays absent for grok, so `usage().total` can undercount such a child. `docs/runtimes/grok.md` has the evidence and a repeatable probe (`experiments/grok-background-usage-2026-10-10.md`). **Behavior changes** - On grok, `usage().total` grows when grok runs a follow-up turn after a background subagent, with a `usage` event on that notification's frame. Validation: #327 passed all 17 checks on its final head, and its merged tree equals the tree verified locally on top of 0.54.1 (typecheck, lint, full tests). Lookout verified it against real grok 1.0.50 with a mock provider, with no account: background, foreground and resumed sessions, and a shim that forced `session/load` and renamed grok's replayed history to the live notification name, so replays looked exactly like live reports. No replayed ledger was counted. After this PR passes CI and merges, tag its exact squash commit as `v0.54.2` to trigger npm trusted publishing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: exe.dev user <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Grok starts a root follow-up after a background subagent finishes, without an ACP
session/promptreply. Its usage was therefore omitted. Count the independentsubagent-completed-*root terminal ledger once per native event id, using the same accumulator as ordinary prompt replies so later replies retain it. Duplicate native frames remain available.Opening history stays native-only. Track notification arrival against the matching successful
session/new,session/resumeorsession/loadanswer on the decoded wire, before the SDK can delay notification callbacks. Remember historical identities, including explicit replay reports, so late duplicates cannot become new bills. The messages and their recorded native payloads are unchanged.Child accounting remains partial. The native probe demonstrates that
will_wake: truecan accompany either an inclusive or exclusive parent ledger; source inspection also rules out inferring inclusion from completion-notification order. Keep child ledgers native-only and document the remaining late-child undercount instead of risking double counting.Evidence and a repeatable probe: Grok background usage report. Includes three recorded completion orders, duplicate delivery and JSON replay, opening-history regressions, ownership and partial-ledger boundaries. All provider calls use isolated local mocks; no account or quota.
Validation passed:
CI=1 pnpm run check(1,622 tests plus mock behavior) and build on the final code, based on maine5793f9. Claude/Codex/Pi/Pi Durable behavior suites passed; Pi was rechecked after incorporating the new main changes. Nine applicable Grok vendor tests and the three-scenario native Grok 1.0.50 probe passed after the wire-boundary revision. Twenty-seven regressions cover accounting and opening boundaries. The first callback-based gate failed on repeat; the report records why it was replaced with wire-order tracking.Fixes #325 under the agreed scope: count independent root follow-ups and document the child ledger gap. This is a separate follow-up to #320, outside the 0.54.0 release batch.