First of four stacked PRs (consolidated from the earlier 5-PR series; the old 1/5 and 2/5 now review together here — their commit series is preserved, so the original slice boundaries are still visible commit-by-commit. #4629 auto-merged into this branch as part of the fold.)
Replaces #4551, which bundled the whole subagent-observability feature into one ~3,100-line change.
Scope: the data model, storage, migration — and the providers that populate it. Nothing user-visible yet; the UI lands in #4663.
The model#
Contracts gain a reusable subagent identity — per-activation records (SubagentActivationId, OrchestrationV2SubagentActivation), cumulative usage, a role, recent activity, and workflow grouping. A subagent can rest at idle between activations. Migration 045 creates the activation projection table; legacy rows stay readable through schema defaults and projection replay, so no JSON backfill is required.
The status mapping is the important part. A subagent status is not a turn item status — idle has no timeline equivalent. The two are bridged by an explicit Record<subagent status, turn item status> rather than a copy, which makes the mapping total: adding a subagent status without giving it a timeline meaning is a compile error. This is not hypothetical — an earlier iteration copied the raw status through, wrote an event its own schema could not decode, and the projection rebuild at startup made the server permanently unbootable.
The producers#
All five adapters (Codex, Claude, Cursor, OpenCode, ACP) populate the model: role provenance, token usage, recent activity, per-activation records.
Two usage strategies, because providers differ. Codex reports cumulative usage per thread, so snapshots merge by maximum — a duplicate or late out-of-order frame 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.
The Claude adapter gains full workflow coordinator/worker modeling: workers created under a coordinator with phase membership, parent linkage, per-attempt reopen semantics, settled when the coordinator terminalizes.
Three activation-lifecycle bugs found in review, fixed here (all Claude adapter): a raced resume silently losing its tokens via a pre-opened registry entry; a replayed waiting frame resurrecting a settled subagent; duplicate terminal frames re-stamping completedAt.
Notes for review#
ProviderEventIngestor no longer replaces an explicit null runId/nodeId with the ambient run — activations legitimately have no run id.
- Reuse across runs is deliberately not here: a subagent row still carries the run it was spawned under. That is #4662, kept separate because it is the subtle part.
Testing#
Typecheck and lint clean across server, contracts, client-runtime, web. Server 1,684+ passing; contracts 247; the claude_workflow replay fixture exercises the coordinator/worker path end to end.
Note
High Risk
Large orchestration v2 surface (contracts, projection replay, five adapters, migration) with status-mapping and usage semantics that can corrupt projections or brick startup if mishandled; mitigated by explicit maps, schema defaults, and broad tests.
Overview
Introduces subagent observability in orchestration v2: reusable subagent identities with per-activation records, cumulative usage, roles, recent activity, and workflow grouping. Subagents can rest at idle between activations; projection schema version bumps to 3, migration 045 adds activation persistence (no JSON backfill on legacy subagent rows).
Contracts & projection add SubagentActivationId, subagent-activation.updated events, and an explicit orchestrationV2SubagentStatusAsTurnItemStatus map so timeline rows never store raw subagent statuses (e.g. idle → completed), avoiding undecodable stored events on rebuild.
All five provider adapters (Codex, Claude, Cursor, OpenCode, ACP) emit enriched subagent and activation updates. Usage handling differs by provider: Codex merges cumulative snapshots by max; Claude accumulates activation deltas into lifetime totals. Codex also maps collab agents via codexCollabAgentStatus, tracks token usage and thread status, and records activity summaries on child items. Claude models workflow coordinators and workers from workflow_progress, with resume/reopen fixes (resumePending, settled completion timestamps).
Orchestrator and ProviderEventIngestor honor explicit null runId/nodeId on activations instead of substituting ambient run context. SubagentObservability centralizes role provenance, activation IDs, and usage math.
Fixture and replay tests cover Codex resume/activations, cross-thread projection rebuild, and a new claude_workflow end-to-end scenario.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit f2eefa7b8d9b10356fa30d950e3bfde6f4c66079. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
Note
Add subagent activation data model, persistence, and provider observability to orchestration-v2#
- Introduces
OrchestrationV2SubagentActivation schema and supporting types (OrchestrationV2SubagentUsage, OrchestrationV2SubagentRole, OrchestrationV2SubagentActivity, OrchestrationV2WorkflowPhase) in orchestrationV2.ts, plus a new SubagentActivationId branded id.
- Adds a new
subagent-activation.updated domain event variant and extends OrchestrationV2ThreadProjection with a subagentActivations array; client-side projection reducer handles upserts.
- Persists subagent activations via migration 045, which creates the
orchestration_v2_projection_subagent_activations table with (thread_id, subagent_id, ordinal) and (run_id, status) indexes; projection rebuild now purges stale rows.
- All provider adapters (Claude, Codex, ACP, Cursor, OpenCode) and the delegated-task path in
Orchestrator.ts now populate kind, role, usage, activationCount, currentActivationId, and recentActivity on subagent records and emit subagent_activation.updated events.
- Claude adapter gains the most complex logic:
pending/waiting subagent states, explicit reopen semantics for settled tasks, per-activation usage accumulation, and coordinator/worker subagent modeling for provider workflows.
- Adds
SubagentObservability.ts with shared helpers: subagentActivationId, defaultSubagentRole, appendSubagentActivity, mergeCumulativeSubagentUsage, and accumulateCumulativeSubagentUsage.
- Behavioral Change: Codex and other adapters now report completed subagents with status
idle instead of completed; idle maps to completed in the turn-item status projection.
📊 Macroscope summarized c0a3852. 26 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues#
No issues evaluated.
Review-fix verification (2026-08-01)#
f2eefa7b8 preserves settled activation timestamps while accepting late cumulative usage, and keeps Claude waiting progress streaming without completedAt.
- Focused Codex/Claude replay tests, server typecheck, and the accumulated orchestration-v2 suite cover these paths.
- Chrome verified the resulting Codex Agents panel: the sole settled child and panel total both read
43.2k, with no doubled aggregate.

A fresh Claude visual rerun was blocked by an expired provider OAuth session; the adapter replay remains the proof for Claude waiting-state behavior.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
2a2a495b-3cd0-4ab0-b8fa-ecb2cf5529c1You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
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