Add delegate observability + metering (#39 slice 6)#48
Merged
Conversation
Meter delegated sub-calls and surface them, without corrupting the spend-avoided headline. The deferred non-local delegate metering. - measurement: records gain a `kind` field (task|delegate; old records read as task). `rollup` keeps delegate records OUT of the headline (no double-count — the parent task already credits the whole job) and aggregates them separately into `summary["delegates"]` (count, by backend, est tokens, informational cloud-equiv). `format_rollup` shows a "Delegated sub-tasks" section. Process-level lock serializes the log append (delegate_many fans out across threads). - delegate: `run_delegate` meters each sub-call as kind="delegate" at a single seam (delegate_many inherits it); a metering error never breaks the delegation. - GUI: stats card shows the delegate breakdown. - README/ARCHITECTURE/CHANGELOG/roster comment + docstrings updated (the old "not metered" notes corrected). +13 hermetic tests (380 pass) + a gated live metering check. Independent Critic: SHIP (3 doc-parity fixes applied). The per-parent-task cross-process tree is deferred.
This was referenced Jun 18, 2026
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
The deferred non-local delegate metering, landed as orchestration-tree observability. Delegated sub-calls are now metered and broken down by backend — without corrupting the existing "spend avoided" headline.
measurement— records gain akindfield (taskdefault /delegate; older records read astask).rollupkeeps delegate records out of the headline (no double-count — the parent task already credits the whole job) and aggregates them separately intosummary["delegates"]={count, by_backend: {model: {count, in/out tokens}}, in/out tokens, cloud_equiv_usd}.format_rollupadds a "Delegated sub-tasks" section (omitted when there are none). A process-level lock serializes the log append (delegate_many fans out across threads).delegate—run_delegatemeters each sub-call askind="delegate"at a single seam, sodelegate_manyinherits it for free. A metering error never breaks the delegation.Why
Slice 6 of the scatter-gather roadmap (#39). Until now, delegated work was invisible to measurement — you could see the top-level task but not which backends did the offloaded sub-work. This makes the fan-out observable (which backend → how much) while keeping the spend-avoided number honest (delegations are informational, never double-credited). It's also the data source that would tell us whether a
delegate_reducetool (slice 4) ever earns code.Scope
The per-parent-task tree (linking each delegation to its specific top-level task across processes) is deferred — it needs a task-id propagated through the orchestrator CLIs to the MCP child, which can't be verified hermetically. This slice delivers the robust by-backend aggregate.
Test plan
+13hermetic tests:kindwritten (default/explicit);rollupexcludes delegates from the headline (tasks/by_tier/tokens/spend_avoided unaffected) and intodelegates; kindless record → task; by-backend aggregation;format_rollupshows/omits the section; 20-thread concurrent append → 20 well-formed lines (thread-safety);run_delegatemeterskind="delegate"; a raisingrecord_taskdoesn't break delegation; GUIview_statscarriesdelegates.+1gated live metering check (tempTANGLEBRAIN_STATE_DIR).~/.cache/tanglebrain/usage.jsonlwas untouched (3 lines → 3 lines).make lintOK.Part of #39 (slice 6; does not close the epic). Also promotes the pending slice-4
### Internalentry into this release.🤖 Generated with Claude Code