feat(grok): multi-agent visibility via task.* events #5425
ClosedEnzoTironi(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/5425/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/provider/Layers/GrokAdapter.ts lines 291 to 291OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -181,0 +271,21 @@271+/** Live Grok model `_meta.reasoningEffort` after process spawn. */272+function reasoningEffortFromMeta(meta: unknown): string | undefined {273+ if (!isRecord(meta)) return undefined;274+ const raw = meta.reasoningEffort ?? meta.reasoning_effort;275+ return typeof raw === "string" && raw.trim() ? raw.trim() : undefined;276+}277+278+function preferredModelMeta(input: {279+ readonly sessionModels: EffectAcpSchema.SessionModelState | null | undefined;280+ readonly initializeMeta: Record<string, unknown> | undefined;281+ readonly preferredModelId: string | undefined;282+}): unknown {283+ const pick = (284+ models: ReadonlyArray<{ modelId: string; _meta?: unknown }> | undefined,285+ preferred: string | undefined,286+ ): unknown => {287+ if (!models || models.length === 0) return undefined;288+ const preferredMatch = preferred289+ ? models.find((model) => model.modelId === preferred)290+ : undefined;291+ return preferredMatch?._meta ?? models[0]?._meta;apps/server/src/provider/Drivers/GrokDriver.ts line 114Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -106,3 +110,4 @@106110 env: processEnv,107111 });108112113+ const commandCatalogRef = yield* Ref.make({apps/server/src/provider/acp/GrokAcpSupport.ts line 128Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -47,0 +91,21 @@91+ readonly text: string | undefined;92+ readonly interactionMode: "plan" | "default" | undefined;93+}): string | undefined {94+ const trimmed = input.text?.trim();95+ if (!trimmed) {96+ return trimmed;97+ }98+ if (input.interactionMode === "plan") {99+ if (/^\/plan(?:\s|$)/i.test(trimmed)) {100+ return trimmed;101+ }102+ return `/plan ${trimmed}`;103+ }104+ return trimmed;105+}106+107+/**108+ * Detect Grok in-process subagent tools (spawn_subagent and relatives) so the109+ * adapter can emit T3 task.* events for multi-agent visibility.110+ */111+export function isGrokSubagentToolCall(toolCall: {apps/server/src/provider/Layers/GrokProvider.ts lines 285 to 287OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -137,4 +272,16 @@137272 clientInfo: { name: "t3-code-provider-probe", version: "0.0.0" },138273 });139274 const started = yield* acp.start();140- return buildGrokDiscoveredModelsFromSessionModelState(started.sessionSetupResult.models);275+ // Prefer modelState from session setup; fall back to initialize _meta (live wire).276+ const initializeMeta =277+ started.initializeResult._meta &&278+ typeof started.initializeResult._meta === "object" &&279+ !Array.isArray(started.initializeResult._meta)280+ ? (started.initializeResult._meta as Record<string, unknown>)281+ : undefined;282+ const modelsFromSession = buildGrokDiscoveredModelsFromSessionModelState(283+ started.sessionSetupResult.models,284+ );285+ const modelsFromInitialize = buildGrokDiscoveredModelsFromSessionModelState(286+ initializeMeta?.modelState as EffectAcpSchema.SessionModelState | undefined,287+ );
- apps/server/src/provider/Layers/GrokAdapter.ts line 1522Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -857,0 +1302,21 @@1302+ event.toolCall.status === "failed"1303+ ) {1304+ yield* offerRuntimeEvent({1305+ type: "task.completed",1306+ ...stamp,1307+ provider: PROVIDER,1308+ threadId: ctx.threadId,1309+ turnId: notificationTurnId,1310+ payload: {1311+ taskId,1312+ status: event.toolCall.status === "failed" ? "failed" : "completed",1313+ ...(event.toolCall.detail ? { summary: event.toolCall.detail } : {}),1314+ },1315+ raw: {1316+ source: "acp.jsonrpc",1317+ method: "session/update",1318+ payload: event.rawPayload,1319+ },1320+ });1321+ }1322+ }apps/server/src/provider/Layers/GrokAdapter.ts line 1521Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -857,0 +1301,21 @@1301+ event.toolCall.status === "completed" ||1302+ event.toolCall.status === "failed"1303+ ) {1304+ yield* offerRuntimeEvent({1305+ type: "task.completed",1306+ ...stamp,1307+ provider: PROVIDER,1308+ threadId: ctx.threadId,1309+ turnId: notificationTurnId,1310+ payload: {1311+ taskId,1312+ status: event.toolCall.status === "failed" ? "failed" : "completed",1313+ ...(event.toolCall.detail ? { summary: event.toolCall.detail } : {}),1314+ },1315+ raw: {1316+ source: "acp.jsonrpc",1317+ method: "session/update",1318+ payload: event.rawPayload,1319+ },1320+ });1321+ }apps/server/src/provider/Layers/GrokAdapter.ts line 1951Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1206,3 +1757,19 @@12061757 }).pipe(12071758 Effect.ensuring(12081759 Effect.gen(function* () {1760+ // Usage must surface even when xAI settled the turn before the prompt RPC.1761+ if (yield* Ref.get(promptRpcSucceeded)) {1762+ const promptResult = yield* Ref.get(promptResultRef);1763+ if (promptResult !== undefined) {1764+ yield* withThreadLock(1765+ input.threadId,1766+ Effect.gen(function* () {1767+ const live = sessions.get(input.threadId);1768+ if (!live || live.stopped || live.acpSessionId !== prepared.acpSessionId) {1769+ return;1770+ }1771+ yield* offerGrokPromptTokenUsage(live, prepared.turnId, promptResult._meta);1772+ }),1773+ ).pipe(Effect.catch(() => Effect.void));1774+ }1775+ }
EnzoTironi(GitHub profile, opens in a new tab) closed this
- @@ -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+ }
- @@ -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+ }
Sign in to join this conversation.


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:
9e217416-eaa6-4142-b701-a64ec8e6b0a9You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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