Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(orchestration-v2): subagent observability — data model and providers (1/4) #4779

Closedshivamhwp(GitHub profile, opens in a new tab)wants to merge 9 commits intot3code/codex-turn-mapping fromsubagent-obs/01-contractsopened View on GitHub

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.

Codex Agents panel

A fresh Claude visual rerun was blocked by an expired provider OAuth session; the adapter replay remains the proof for Claude waiting-state behavior.

    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: 2a2a495b-3cd0-4ab0-b8fa-ecb2cf5529c1

      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/01-contracts`

      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

      This PR introduces a new subagent observability feature with schema changes, database migration, new event types, and modifications across multiple provider adapters. The scope represents significant new functionality. Additionally, an unresolved review comment identifies that migration 045 tests don't actually run the migration they claim to cover.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. shivamhwp(GitHub profile, opens in a new tab) changed the title

    5. 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).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c0a38525eab4be5480a8f40bb0d5faceebab3fc4. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -0,0 +38,21 @@
      38+ 'codex',
      39+ NULL,
      40+ NULL,
      41+ 'provider_native',
      42+ 'completed',
      43+ '2026-07-26T00:00:00.000Z',
      44+ '2026-07-26T00:01:00.000Z',
      45+ '2026-07-26T00:01:00.000Z',
      46+ ${legacyPayload}
      47+ )
      48+ `;
      49+
      50+ yield* runMigrations({ toMigrationInclusive: 44 });
      51+
      52+ const activationTable = yield* sql<{ readonly name: string }>`
      53+ SELECT name
      54+ FROM sqlite_master
      55+ WHERE type = 'table'
      56+ AND name = 'orchestration_v2_projection_subagent_activations'
      57+ `;
      58+ assert.lengthOf(activationTable, 1);

      Migration tests skip migration 45

      High Severity

      Both migration tests still call runMigrations with toMigrationInclusive: 44, so migration 045 never runs. The new test then asserts that orchestration_v2_projection_subagent_activations exists, and the contiguous-id test expects migration 45 in effect_sql_migrations, so these assertions cannot pass against the migration they intend to cover.

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c0a38525eab4be5480a8f40bb0d5faceebab3fc4. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. Converged into #4664, which now carries the full series against the orchestrator-v2 base — the commit history there preserves this PR's slice, and this PR's review record (findings and fix replies) remains the reference for it.

Sign in to join this conversation.