Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(grok): multi-agent visibility via task.* events #5425

ClosedEnzoTironi(GitHub profile, opens in a new tab)wants to merge 5 commits intomain fromrefs/pull/5425/headopened View on GitHub

What Changed

Map Grok in-process subagent tools (spawn_subagent and relatives) to T3 task.started / task.completed so multi-agent work is visible like Claude Task tools.

Stacked on #5424. Fixes #5420

Why

Live grok agent stdio emits tool_call title spawn_subagent with completed status and subagent_id (verified 2026-08-05). V1 deliberately ignored child sessions (#3156); product still needs parent-turn visibility of spawned work without flattening child transcripts.

UI Changes

Uses existing task/work-log surfaces — no new components. Visibility of subagent rows in the thread timeline.

Checklist

  • This PR is small and focused — tip still carries stack; multi-agent delta alone is small
  • I explained what changed and why
  • Timeline screenshot of spawn_subagent to task row
  • Video N/A

Known review findings (must fix — real bugs)

  • HIGH: task.* reuses the tool-call event stamp → same eventId → activity PK collision drops the task row
  • MED: every pending/inProgress update re-emits task.started (need per-taskId guard)
  • MED: isGrokSubagentToolCall matches substring subagent in title/detail (prefer structured tool name)

Test plan

  • Detector unit tests
  • Live probe: spawn_subagent tool_call shape matches detector

Model: grok-4.5 (Grok Build)


Note

Medium Risk Large Grok adapter and provider snapshot changes affect runtime events and composer behavior; reviewers flagged possible task/tool eventId collisions and subagent detector false positives.

Overview Grok spawn_subagent (and similar) tool calls now emit task.started / task.completed on the parent turn so multi-agent work shows up in existing task/work-log UI, with per-toolCallId dedupe for started/completed.

The diff is a broader Grok ACP alignment with live grok agent stdio: ACP session updates for reasoning chunks, usage, available commands, config options, and session titles; token usage from usage_update and prompt result _meta; /compact → thread.state.changed compacted; plan mode via /plan prefix, exit_plan_mode capture, and plan.md tool writes → turn.proposed.completed; mid-thread model/reasoning via session/set_model _meta.reasoningEffort and CLI spawn flags (no forced new thread); slash/skills catalog pushed from initialize/available_commands_update through GrokDriver snapshot streams; provider snapshot adds static /compact, reasoning effort options, and updated Grok presentation flags.

The mock ACP agent and tests cover unsolicited JSON-RPC ids, init commands, compact, session info, usage meta, and the new adapter paths.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3929597e02b7332a11ba19340a38447bc536a671. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add multi-agent task visibility and reasoning effort support to the Grok provider via task.* events

  • Emits task.started and task.completed runtime events for Grok subagent tool calls, surfacing multi-agent activity in the thread UI.
  • Adds reasoning effort support: spawns Grok with --reasoning-effort, passes _meta.reasoningEffort through session/set_model, and exposes a Reasoning select option in model capabilities when advertised by ACP.
  • Parses availableCommands from ACP initialize result to populate slash commands and skills (including a static /compact command always present in the menu).
  • Emits thread.token-usage.updated events from both live UsageUpdated ACP events and prompt RPC _meta, with granular input/output/cached/reasoning token breakdowns and maxTokens from model context windows.
  • Handles x.ai/session_notification with auto_compact_completed to emit thread.state.changed with compacted details, and session_info_update to emit thread.metadata.updated when the session title changes.
  • Adds plan mode support: injects /plan prefix when interactionMode is plan, captures plan.md writes and x.ai/exit_plan_mode calls to surface proposed-plan cards.
  • Behavioral Change: requiresNewThreadForModelChange is now false and showInteractionModeToggle is now true for the Grok provider presentation.
Macroscope summarized 3929597.
    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: 9e217416-eaa6-4142-b701-a64ec8e6b0a9

      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

      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:unvouched

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

      Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. This PR introduces significant new Grok functionality including multi-agent task visibility, plan mode handling, and token usage tracking across multiple files. The scope qualifies as a new feature requiring human review, and there are unresolved comments identifying potential bugs in context window handling and subagent event sequencing.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Review findings from Bugbot/Macroscope for this slice are fixed on the Zoen product tip (zoen/main @ 16474ab0d). Will restack / re-push these PR heads after further slim-slicing. Open remaining: effort restart without session.exited (or adopt #5403 set_model path).

    5. Closing: multi-agent task.* mapping is included in #5423 with stamp uniqueness + dedupe fixes. Issue #5420 remains linked from #5423.

    6. @@ -181,0 +370,21 @@
      370+ const windows = new Map<string, number>();
      371+ const ingest = (models: ReadonlyArray<{ modelId: string; _meta?: unknown }> | undefined) => {
      372+ if (!models) return;
      373+ for (const model of models) {
      374+ const tokens = totalContextTokensFromMeta(model._meta);
      375+ if (tokens !== undefined && model.modelId.trim()) {
      376+ windows.set(model.modelId.trim(), tokens);
      377+ }
      378+ }
      379+ };
      380+ ingest(input.sessionModels?.availableModels);
      381+ const initializeModelState = input.initializeMeta?.modelState;
      382+ if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) {
      383+ const availableModels = initializeModelState.availableModels.flatMap((entry) => {
      384+ if (!isRecord(entry) || typeof entry.modelId !== "string") {
      385+ return [] as Array<{ modelId: string; _meta?: unknown }>;
      386+ }
      387+ return [{ modelId: entry.modelId, _meta: entry._meta }];
      388+ });
      389+ ingest(availableModels);
      390+ }
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/GrokAdapter.ts:380

      buildGrokModelContextWindows ingests session model state first, then unconditionally ingests initialize metadata into the same Map, so an initialize entry with the same modelId overwrites the authoritative session value. When the two context-window values differ, downstream code reads the stale initialize value and reports an incorrect context limit. Ingest initialize data first, or skip keys already set from session state.

      Suggested change
      380- ingest(input.sessionModels?.availableModels);
      381- const initializeModelState = input.initializeMeta?.modelState;
      382- if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) {
      383- const availableModels = initializeModelState.availableModels.flatMap((entry) => {
      384- if (!isRecord(entry) || typeof entry.modelId !== "string") {
      385- return [] as Array<{ modelId: string; _meta?: unknown }>;
      386- }
      387- return [{ modelId: entry.modelId, _meta: entry._meta }];
      388- });
      389- ingest(availableModels);
      390- }
      380+ ingest(input.sessionModels?.availableModels);
      381+ const initializeModelState = input.initializeMeta?.modelState;
      382+ if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) {
      383+ const availableModels = initializeModelState.availableModels.flatMap((entry) => {
      384+ if (!isRecord(entry) || typeof entry.modelId !== "string") {
      385+ return [] as Array<{ modelId: string; _meta?: unknown }>;
      386+ }
      387+ return [{ modelId: entry.modelId, _meta: entry._meta }];
      388+ });
      389+ for (const model of availableModels) {
      390+ const id = model.modelId.trim();
      391+ if (!id || windows.has(id)) continue;
      392+ const tokens = totalContextTokensFromMeta(model._meta);
      393+ if (tokens !== undefined) {
      394+ windows.set(id, tokens);
      395+ }
      396+ }
      397+ }
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/provider/Layers/GrokAdapter.ts around lines 380-390:
      
      `buildGrokModelContextWindows` ingests session model state first, then unconditionally ingests initialize metadata into the same `Map`, so an initialize entry with the same `modelId` overwrites the authoritative session value. When the two context-window values differ, downstream code reads the stale initialize value and reports an incorrect context limit. Ingest initialize data first, or skip keys already set from session state.
    7. 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 3929597e02b7332a11ba19340a38447bc536a671. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -857,0 +1477,21 @@
      1477+ if (!ctx.completedSubagentTaskIds.has(toolCallId)) {
      1478+ ctx.completedSubagentTaskIds.add(toolCallId);
      1479+ const taskStamp = yield* makeEventStamp();
      1480+ yield* offerRuntimeEvent({
      1481+ type: "task.completed",
      1482+ ...taskStamp,
      1483+ provider: PROVIDER,
      1484+ threadId: ctx.threadId,
      1485+ turnId: notificationTurnId,
      1486+ payload: {
      1487+ taskId,
      1488+ status: event.toolCall.status === "failed" ? "failed" : "completed",
      1489+ ...(event.toolCall.detail ? { summary: event.toolCall.detail } : {}),
      1490+ },
      1491+ raw: {
      1492+ source: "acp.jsonrpc",
      1493+ method: "session/update",
      1494+ payload: event.rawPayload,
      1495+ },
      1496+ });
      1497+ }
      cursor[bot](GitHub profile, opens in a new tab)commented

      Completed-only subagent lacks start

      Medium Severity

      Live Grok often reports spawn_subagent only as completed, but this path emits task.completed without a preceding task.started. Projection titles completed tasks from the started description, so the computed title is unused and multi-agent rows show without a useful name—the common live case called out in the PR.

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

Sign in to join this conversation.