Repository navigation
fix(usage): subagent and completion-turn model calls go unattributed in usage reporting - #303
Merged
william-antoline-boon merged 10 commits intoOct 22, 2026
Conversation
Subagent child runs reached the LLM gateway without X-Boon-User-* headers
because the child run has no inbound sender, so usage showed as Unattributed.
Add an optional usageAttribution { userId, userName?, userSource? } to the
agent gateway method. It is honored only for core-built in-process dispatch:
dispatchGatewayMethodInProcessRaw marks the client with
internal.inProcessDispatch only when a core caller opts in. Socket clients
cannot set it, and the plugin SDK dispatchGatewayMethod (which proxies
authenticated HTTP route bodies) neither opts in nor forwards the field. The
caller-supplied lane is not a trust signal. It is deliberately separate from
senderId, which drives sender-scoped tool policy.
- sessions_spawn fills it from the requester run's sender, or from the
attribution that run inherited (nested subagents).
- Persisted on the child SessionEntry next to spawnedBy, so later turns of a
spawnMode=session subagent stay attributed; preserved on /new, /reset and
idle/daily rollover.
- sessions_send (including its agent-to-agent follow-up steps) and subagent
steer/send pass the current turn's attribution, so a run another user drives
is attributed to that user instead of the spawning user.
- withBoonUsageHeaders falls back to it only when the turn has no senderId,
taking the user triple from one source so identities never mix.
- Plugin runtime subagent.run accepts usageAttribution too.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
get-reply-run sets senderSource on the run, but neither the primary-turn sender context nor the queued follow-up runner forwarded it into the embedded run params, so X-Boon-User-Source was never emitted for ordinary user turns. Same drop pattern as oboToken: declare it on FollowupRun.run and forward it at both hops. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Subagent runs did not carry the gateway-audience OBO token of the requester turn, so the child's model calls went out without it. sessions_spawn now carries the requester run's oboToken and passes it as an in-process-only `oboToken` param on the agent call that starts the child's first run. The agent method honors it only for core-built in-process dispatch (same gate as usageAttribution) and drops it for other clients. It is threaded to the run params so the model-call diagnostic context emits x-boon-gateway-obo-token. The token is a per-turn bearer: it is never written to the session entry, and the existing debug line still reports presence only. Later turns of a persisted session-mode child run without it and keep only the user header from usage attribution. Co-Authored-By: Claude Opus 5.5 <[email protected]>
After a subagent finishes, the requester session runs a completion turn with no inbound sender, so its model calls reached the LLM gateway without X-Boon-User-* headers and showed as unattributed. - The announce flow resolves a billing-only usageAttribution for the completion: the child session's persisted attribution (captured from the requester turn's sender at spawn), else the requester session's own inherited attribution. The subagent registry keeps no requester sender, so the child entry is the closest record of it. - SubagentCompletionRequest carries it as optional `usageAttribution`, so plugin completion owners can set it on the turn they build. - The built-in delivery path passes it on the in-process `agent` call (same in-process-only gate as spawn), covering Slack/Teams and other channels that core hands back to the requester agent. - MsgContext gains `UsageAttribution`. get-reply-run maps it (else the session entry's inherited value) onto the queued run, and the primary and follow-up runners forward it to the embedded run, where it feeds the user headers only when the turn has no senderId. It never sets senderId, so command auth, sender-scoped tool policy and OBO handling are unchanged; a completion with no resolvable user still sends no user header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The OBO bearer and usageAttribution are honored only for in-process dispatch, but a subagent spawn that fell back to the WebSocket gateway client still serialized them in the `agent` params. Strip both on that fallback: the credential no longer crosses the socket, and an older gateway whose closed `agent` schema rejects unknown params no longer fails the spawn. The child stays attributed through its session-entry patch. Log redaction now treats `oboToken` / `obo_token` / `obo-token` fields and the `x-boon-gateway-obo-token` header as secrets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
cubic analysis
All reported issues were addressed across 55 files
Linked issue analysis
Linked issue: ENG-21618: [Builders Inc] Usage attribution missing for Dan; tokens falling under unattributed usage
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Attribute subagent and completion usage to the originating user | Usage attribution is propagated to those turns and applied to model-call headers when no sender is present. |
| Show Dan’s attributed usage in the Builders Inc dashboard | The change supplies user headers for the gateway, but live dashboard behavior has not been verified end to end. |
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
View guided diff | Turn on auto-fix | Re-trigger cubic
…ts it Request scopes flow through AsyncLocalStorage into the runs a handler starts, so a nested in-process dispatch inherited an outer core-built request's inProcessDispatch flag. Strip the inherited flag from the scoped client so only the dispatch that declares core-built params is trusted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The run-to-attempt params are an explicit copy and omitted senderSource, so the user-source usage header and the source of the attribution a run hands to its children were always empty. Co-Authored-By: Claude Opus 5.5 <[email protected]>
No production caller steers or sends through subagent control, so the per-call override was dead code. Steered and sent child runs keep the attribution persisted on the child session entry at spawn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Assert attribution reaches sessions_spawn's spawn context, a2a ping-pong and announce steps, both agent-step execution paths, and survives a session reset. Make the blank-token and token-persistence assertions non-vacuous, and keep the plugin loader out of tool unit tests by mocking the in-process dispatch module. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Approving. Reviewed the full source diff (35 non-test files) at 498d7d3.
Verified
- Trust boundary holds.
usageAttributionandoboTokenare read in theagenthandler only whenclient.internal.inProcessDispatch === true. That flag is set only by core-built dispatch (spawn, announce,callAgentWithUsageAttribution, plugin subagent runtime). The SDKdispatchGatewayMethodstrips both fields. The socket fallback incallSubagentGatewaystrips both. Nested dispatches drop an inherited flag viawithoutInheritedInProcessDispatch. - Attribution is billing-only. It is never copied into
senderId.withBoonUsageHeaderstakes the whole user triple from one source (sender if present, otherwise attribution), so identities can't mix. - The OBO token is per-run only. It is read from
opts, not from the session entry. It is not inbuildDirectChildSessionPatchand the child patch is a direct store write. Redaction coversoboTokenandx-boon-gateway-obo-token. - The
senderSourcedrop in the run to attempt copy (run.ts) is fixed. The same field is forwarded through the followup runner and template context. - Attribution survives
/newand idle rollover (session.ts,session-reset-service.ts). Depth-2 children inherit it viaresolveRequesterUsageAttribution. - Optional fields only, so older session entries, plugins and clients are unaffected.
- CI is green except
security-fast. It fails at "Audit production dependencies" on advisories in@modelcontextprotocol/sdk,follow-redirects,markdown-itandvite. This PR has no dependency changes, and a separate fix is already open (ridho/fix-security-fast-pnpm-audit-advisories). That check will probably need a rebase ontoboonafter the fix lands. - cubic's threads are answered with reasons, or fixed in 498d7d3.
Non-blocking notes
callAgentWithUsageAttributionmoves attributedsessions_sendand a2a steps from the socket path to in-process dispatch with a syntheticWRITE_SCOPEclient. Spawn already does this, and the comment says the client shape is the same. Check on canary that provenance andinputProvenancehandling match the socket path.- If there is no in-process gateway context, or the message is queued into an active run, a
sessions_sendfrom user B falls back to the target's persisted attribution (the spawn-time user). This is documented in the code, but usage reports can still mis-attribute that case. - Not yet run against a live gateway, per the PR description. Please verify on canary that the child's
x-boon-user-id,-name,-sourceand the OBO header reach the LLM gateway for spawn, announce and completion turns before wide rollout.
…agent-usage-attribution
inassjunus
approved these changes
Oct 22, 2026
william-antoline-boon
deleted the
william/eng-21618-subagent-usage-attribution
branch
October 22, 2026 05:41
convyusboy
added a commit
that referenced
this pull request
Oct 26, 2026
* chore(release): bump version 2026.6.35-boon.1 -> 2026.6.35-boon.2 Cuts the fork release covering the 9 PRs merged to boon since v2026.6.35-boon.1: #298 (ENG-21265) stuck-generation cut-off retry + sub-agent spawn backstop, #299 workspaceDir threading through outbound channel media adapters, #304 (ENG-19208) real inbound media path in the system prompt, #301 (ENG-21585) forced sessions_yield on narrated sub-agent turns, #305 message-tool source reply observed outside message_tool_only, #306 (ENG-19103) reasoning-stream callbacks honor message_tool_only, #303 sub-agent/completion-turn usage attribution, #302 clears 7 high-severity pnpm-audit-prod advisories, #300 (ENG-21588) boon-estimation trajectory label detail. Bump root package.json/npm-shrinkwrap.json, all bundled plugin manifests, and the version + openclaw peer floor in every extension npm-shrinkwrap.json. Add the 2026.6.35-boon.2 CHANGELOG.md section. No additional dependency or source changes beyond what already shipped in #299 and #302. Co-Authored-By: Claude Sonnet 5 <[email protected]> * docs(changelog): fold PR #309's advisory fixes into the 2026.6.35-boon.2 entry --------- Co-authored-by: Claude Sonnet 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.
What Problem This Solves
Fixes an issue where model calls made by a subagent, and by the parent session's turn that reports a finished subagent, were sent to the LLM gateway without the originating user's usage headers (
x-boon-user-id/-name/-source). Per-user usage reporting showed that work as unattributed, on every channel. The user source header was also dropped on ordinary primary and queued turns, and the gateway-audience OBO token never reached subagent runs.Why This Change Was Made
A new attribution-only field,
usageAttribution: { userId, userName?, userSource? }, carries the requesting user to subagent runs and to completion/announce turns. It is never used assenderId, so sender-scoped tool policy and command auth are unchanged.withBoonUsageHeadersuses it only whensenderIdis absent and takes the whole user triple from one source.sessions_sendpasses the current turn's user for the run it starts. Resets and idle rollover keep it.SubagentCompletionRequest.usageAttribution) andMsgContext.UsageAttributionlet channel plugins and core's own announce delivery attribute the parent's completion turn.senderSourceis now forwarded on primary and queued turns, and into the embedded attempt (the run-to-attempt copy dropped it, so the source header was always empty).agentmethod acceptsusageAttributionandoboTokenonly from core-built in-process dispatch. Socket clients and the plugin SDKdispatchGatewayMethodpath cannot set them (both stripped), and the trust flag is not inherited by nested dispatches that run inside a trusted request's async scope. The WebSocket fallback strips both fields, which also keeps older gateways (strictagentschema) from rejecting the spawn. Log redaction now coversoboTokenand thex-boon-gateway-obo-tokenheader.Non-goals: compaction model calls, agent-harness task completions and background media-generation completions still send no user headers; they can adopt the field later.
User Impact
Operators get per-user usage that includes subagent work and completion turns, instead of an unattributed bucket. No behavior change for tools, permissions or replies. All new fields are optional; older session entries, plugins and clients keep working.
Evidence
agent, server plugins, plugin-SDK gateway method runtime, model-call headers, harness tool policy and log redaction. Key cases:sessions_sendfrom another user attributes the run it starts to that user; a2a ping-pong and announce steps follow itsenderSourceand attribution reach the embedded attempt/newand idle rollover keep attributiontsgocore and core-test typecheck, oxlint/oxfmt, plugin-SDK API check, import-cycle checks: pass.🤖 Generated with Claude Code
Summary by cubic
Fixes per-user usage reporting so model calls from subagents and from the parent session's subagent-completion turns carry the originating user's usage headers (
x-boon-user-id/-name/-source) instead of landing in the unattributed bucket.senderSourcenow flows through primary, queued, and embedded-attempt turns, and the gateway-audience OBO token follows a subagent's first run in memory only.The new billing-only
usageAttributionfield carries the requesting user to subagent runs, their persisted session entries, and completion turns. It is never used assenderId, so sender-scoped tool policy and command auth are unchanged. Steered and sent child runs keep the attribution persisted on the child session entry from spawn.Metering effect (intended)
Subagent and completion-turn calls now carry the same user identity and, on a subagent's first run, the same OBO token as the turn that started them. The gateway's existing internal-test rule therefore applies to them: work triggered by a Boon staff member is no longer metered against the customer, matching how that staff member's own turns are already treated. Work triggered by customer users is metered exactly as before.
Trust boundary
usageAttributionandoboTokenare honored only from core-built in-processagentdispatch; socket clients, the plugin SDKdispatchGatewayMethodpath, and the WebSocket fallback strip both, so older strict gateways still accept spawns.x-boon-gateway-obo-tokenheader.Out of scope
usageAttributionlater.Written for commit efff95f. Summary will update on new commits.