Skip to content

fix(coding-agent): coalesce child usage attribution - #1061

Closed
Lauritz-Timm wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
Lauritz-Timm:fix/coalesce-child-usage-attribution
Closed

fix(coding-agent): coalesce child usage attribution#1061
Lauritz-Timm wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
Lauritz-Timm:fix/coalesce-child-usage-attribution

Conversation

@Lauritz-Timm

@Lauritz-Timm Lauritz-Timm commented Aug 9, 2026

Copy link
Copy Markdown

Summary

  • coalesce child assistant usage across a tool-heavy agent turn
  • persist one child_usage_attributed entry at agent_end instead of one per assistant message
  • retain exact aggregate usage and flush pending usage during cleanup
  • add a 50-tool-call regression and update the existing RLM usage test

Root cause

Every child message_end immediately appended a usage-attribution entry to the parent transcript. Tool-heavy RLM children therefore caused a sustained stream of transcript writes and leaf mutations on the same worker event loop that serves attach and heartbeat requests. Under load, the worker consumed several gigabytes of memory and stopped answering daemon control requests.

The in-memory parent usage total still updates for every assistant message. Only persistence is coalesced to the child turn boundary, preserving billing totals and reload behavior while removing the write flood.

User impact

Long-running RLM sessions remain responsive while subagents execute dense tool loops, and parent transcripts no longer accumulate hundreds of bookkeeping entries for one child turn.

Validation

  • test/suite/regressions/1054-child-usage-attribution-flood.test.ts: 1 passed
  • test/agent-session-recursion.test.ts: 96 passed
  • npm run check: passed

Fixes #1054

Note

Fix child usage attribution flood by coalescing entries per child turn

  • Previously, each assistant message within a child agent's tool loop emitted a separate child_usage_attributed entry on the parent session, flooding the parent transcript.
  • AgentSession.runRlmChild now accumulates usage into a pendingChildUsage buffer and flushes a single aggregated entry per child turn, splitting only when the attribution origin changes mid-turn.
  • The regression test in 1054-child-usage-attribution-flood.test.ts verifies that 50 consecutive tool-loop messages produce exactly one child_usage_attributed entry.

Macroscope summarized c2dacb0.

@sethkarten

Copy link
Copy Markdown
Contributor

Thank you for the report and proposed work. This root cause is now covered by maintainer-owned stacked PR #1162, authored independently from upstream/main.

We did not inspect or reuse this PR's diff, branch, commits, implementation code, or tests; its public description/comments were used only as a bug report. To keep one review surface, this PR is superseded by #1162 and is being closed.

The complete review stack is #1158#1165. It is being left unmerged for human review after CI and review-bot findings are cleared.

@sethkarten sethkarten closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants