Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(orchestration-v2): populate subagent observability from providers (2/5) #4629

Mergedshivamhwp(GitHub profile, opens in a new tab)merged 4 commits intosubagent-obs/01-contracts fromrefs/pull/4629/headmerged by shivamhwp(GitHub profile, opens in a new tab) View on GitHub

Second of five stacked PRs replacing #4551. Stacked on #4779 — review that first; this diff is against it, not the base branch.

PR 1 added the schema, migration, and storage with adapters on neutral defaults. This one makes the adapters actually populate it, across Codex, Claude, Cursor, OpenCode and ACP: role provenance, token usage, recent activity, and per-activation records.

Two usage strategies, because providers differ

Codex reports cumulative usage per thread, so those snapshots merge by maximum — a duplicate or late out-of-order frame then leaves the total unchanged rather than inflating it. Claude reports per activation, so lifetime usage accumulates the delta since the previous snapshot. Using either strategy for the other provider double-counts or freezes the number, so they are separate functions with their own tests.

A subagent identity is reusable, so finishing an activation leaves it at idle rather than completed. The timeline row for that activation is still recorded as completed, via PR 1's status mapping.

Three activation-lifecycle bugs found in review

All in the Claude adapter, all fixed here:

  • A raced resume silently lost its tokens. When a resume arrives past settle, the wake buffer pre-opens the registry entry — which erased the terminal status the reopen check reads. The resume then reused the finished activation instead of starting a new one: its ordinal stopped matching reality, and its usage was measured against the previous activation's totals, clamping the delta to zero. The pre-open now records that it happened, and the reopen check honours it.
  • A replayed waiting frame could resurrect a settled subagent. Only pending/running were guarded.
  • Duplicate terminal frames re-stamped completedAt, drifting the recorded completion time. Codex already preserved it; Claude now matches.

Explicitly not here

Reuse across runs. A subagent row still carries the run it was spawned under, so a later run's update can still be dropped by routing — visible in the subagent_continue fixture. That is PR 3, deliberately kept separate because it is the subtle part.

Testing

Typecheck and lint clean. Server 1,682 passing; whole-repo run 5,460 passing (the only failures are pre-existing apps/desktop collection errors from a broken local Electron install, untouched by this PR).

Reviewed by an independent agent pass before opening; the three lifecycle bugs above came out of it and are fixed in this commit.

Note

Populate subagent observability from ACP, Claude, Codex, Cursor, and OpenCode provider adapters

  • Each provider adapter now emits subagent_activation.updated events alongside subagent.updated, carrying activation id, ordinal, status, usage, and timestamps for each discrete subagent run.
  • Adds SubagentObservability helpers: providerSubagentRole, appendSubagentActivity, mergeCumulativeSubagentUsage, and accumulateCumulativeSubagentUsage for normalizing and accumulating usage across activations.
  • Subagent tasks now track currentActivationId (nulled on settle), activationCount, recentActivity, and preserve completedAt across rebuild emits.
  • The Claude adapter gains full workflow coordinator/worker modeling: worker subagents are created under a coordinator with phase membership, parent linkage, per-attempt reopen semantics, and are settled when the coordinator terminalizes.
  • Codex adapter maps completed provider state to idle subagent status; all adapters align on idle as the terminal reusable state instead of completed.
  • Behavioral Change: subagent status for settled reusable agents is now idle (not completed); existing tests and fixtures have been updated to match.
Macroscope summarized 2038f11.

Note

Medium Risk Touches orchestration projection for all major provider adapters and changes settled subagent status semantics (idle vs completed); Claude resume/workflow logic is intricate but heavily tested.

Overview Provider adapters (ACP, Claude, Codex, Cursor, OpenCode) now emit subagent_activation.updated alongside subagent updates and fill roles, usage, recent activity, and activation metadata instead of neutral defaults.

SubagentObservability adds provider role provenance, bounded activity history, and two usage paths: Codex merges cumulative thread snapshots by maximum; Claude accumulates per-activation deltas into lifetime totals.

Settled reusable subagents end in idle (not completed); activations still record terminal status. currentActivationId, activationCount, and preserved completedAt on rebuild emits align across adapters.

Claude models workflow coordinators and workers from workflow_progress, settles workers when the coordinator terminalizes, and fixes resume/reopen races (resumePending, waiting reopen guards).

Codex maps collab agent states via codexCollabAgentStatus, handles token usage and thread status, and records subagent model from the turn selection. Fixtures and tests updated for idle and activation rows.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2038f11117a1a4905f37485f69c19442d8de47f8. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 41ca544d-dcf6-4c8b-a001-f29b8fa09bfd

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `subagent-obs/02-adapters`

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. This PR introduces new subagent observability features across multiple provider adapters, including new event emission, status tracking, and usage accumulation logic. The scope represents significant new runtime behavior, and there is an unresolved review comment identifying a potential bug in the waiting status handling.

      No code changes detected at 2038f11. Prior analysis still applies.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2038f11117a1a4905f37485f69c19442d8de47f8. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -3272,0 +3369,21 @@
      3369+ const usage = {
      3370+ totalTokens: total.totalTokens,
      3371+ inputTokens: total.inputTokens,
      3372+ cachedInputTokens: total.cachedInputTokens,
      3373+ outputTokens: total.outputTokens,
      3374+ reasoningOutputTokens: total.reasoningOutputTokens,
      3375+ } satisfies OrchestrationV2SubagentUsage;
      3376+ yield* emitSubagentTaskUpdate({
      3377+ subagent,
      3378+ status: subagent.task.status,
      3379+ usage,
      3380+ });
      3381+
      3382+ const activeContext = (yield* Ref.get(activeTurns)).get(payload.turnId);
      3383+ if (
      3384+ activeContext === undefined ||
      3385+ activeContext.subagent !== subagent ||
      3386+ activeContext.subagentActivation === null
      3387+ ) {
      3388+ return;
      3389+ }

      Late usage skips activation records

      Medium Severity

      thread/tokenUsage/updated only writes per-activation usage when the turn is still in activeTurns. Turn finalization removes that entry first, so a late usage frame updates lifetime totals but leaves the activation's usage unset.

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2038f11117a1a4905f37485f69c19442d8de47f8. Configure [here](https://www.cursor.com/dashboard/bugbot).

Sign in to join this conversation.