From 37658dd2463122cced692fe73aed826bdfb0378b Mon Sep 17 00:00:00 2001
From: Gustav RLo <40185279+GustavBlack@users.noreply.github.com>
Date: Wed, 25 Nov 2026 16:16:41 -0800
Subject: [PATCH 1/5] fix(provider-omp): show subagents spawned by OMP's task
tool
The Pi adapter projected subagent cards only for the tool named
"subagent" (pi-subagents). OMP's fan-out tool is named "task", so its
calls fell through to generic dynamic_tool rows: no cards, no live
progress, and background runs untracked.
PiFlavor gains subagentToolName (pi: "subagent", omp: "task") and the
adapter now projects OMP task calls: SingleResult.output for result text,
assignment/task for the prompt, exitCode for status, running cards from
details.progress[], background runs tracked by details.async.jobId and
settled from the task-result blocks omp delivers through wait results.
Replay tests recorded from omp 19.2.0 RPC cover foreground, parallel and
async sequences.
---
packages/provider-omp/src/server.ts | 1 +
.../provider-pi/src/server/adapter.test.ts | 264 +++++++++++++++++-
packages/provider-pi/src/server/adapter.ts | 188 ++++++++++---
packages/provider-pi/src/server/flavor.ts | 3 +
4 files changed, 415 insertions(+), 41 deletions(-)
diff --git a/packages/provider-omp/src/server.ts b/packages/provider-omp/src/server.ts
index b8c9d7785242e..dfcf5f76d9375 100644
--- a/packages/provider-omp/src/server.ts
+++ b/packages/provider-omp/src/server.ts
@@ -20,6 +20,7 @@ export const OMP_FLAVOR: PiFlavor = {
probeDirName: "omp-status-probe",
defaultAgentDirSegments: [".omp", "agent"],
usageProvider: "omp",
+ subagentToolName: "task",
};
const DEFAULT_OMP_SETTINGS = Schema.decodeSync(OmpSettings)({});
diff --git a/packages/provider-pi/src/server/adapter.test.ts b/packages/provider-pi/src/server/adapter.test.ts
index cdcf6199b6159..346961fc5f2ea 100644
--- a/packages/provider-pi/src/server/adapter.test.ts
+++ b/packages/provider-pi/src/server/adapter.test.ts
@@ -5,6 +5,7 @@ import {
ChatAttachmentId,
EnvironmentId,
NodeId,
+ ProviderDriverKind,
ProviderInstanceId,
ProviderSessionId,
ProviderThreadId,
@@ -529,6 +530,8 @@ const makeAdapter = Effect.fnUntraced(function* (
launchArgs = "",
forkFake?: FakePi,
continuationRequests?: PiAdapterV2Options["continuationRequests"],
+ driverKind?: ProviderDriverKind,
+ subagentToolName?: string,
) {
const spawner =
forkFake === undefined
@@ -570,6 +573,8 @@ const makeAdapter = Effect.fnUntraced(function* (
customModels: [],
},
environment: {},
+ ...(driverKind === undefined ? {} : { driverKind }),
+ ...(subagentToolName === undefined ? {} : { subagentToolName }),
}).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner));
});
@@ -581,8 +586,16 @@ const openRuntime = Effect.fnUntraced(function* (
forkFake?: FakePi,
continuationRequests?: PiAdapterV2Options["continuationRequests"],
initialNativeThreadId?: string,
+ flavorOverride?: { readonly driverKind: ProviderDriverKind; readonly subagentToolName?: string },
) {
- const adapter = yield* makeAdapter(fake, "", forkFake, continuationRequests);
+ const adapter = yield* makeAdapter(
+ fake,
+ "",
+ forkFake,
+ continuationRequests,
+ flavorOverride?.driverKind,
+ flavorOverride?.subagentToolName,
+ );
const runtime = yield* adapter.openSession({
threadId,
providerSessionId,
@@ -3833,6 +3846,255 @@ describe("PiAdapterV2", () => {
}).pipe(Effect.scoped, Effect.provide(layerTest)),
);
+ const OMP_FLAVOR_OVERRIDE = {
+ driverKind: ProviderDriverKind.make("omp"),
+ subagentToolName: "task",
+ };
+
+ it.effect("projects OMP task tool progress and results as subagent cards", () =>
+ Effect.gen(function* () {
+ const fake = yield* makeFakePi;
+ const { runtime, takeEvent } = yield* openRuntime(
+ fake,
+ "default",
+ THREAD_ID,
+ SESSION_ID,
+ undefined,
+ undefined,
+ undefined,
+ OMP_FLAVOR_OVERRIDE,
+ );
+ const providerThread = yield* runtime.ensureThread({
+ threadId: THREAD_ID,
+ modelSelection: modelSelection("default"),
+ runtimePolicy,
+ });
+ yield* startTurn(runtime, providerThread);
+ yield* fake.takeRequest("prompt");
+ yield* fake.emit({ type: "agent_start" });
+ // Frames as omp 19.2.0 sends them for a blocking `task` call (async disabled).
+ yield* fake.emit({
+ type: "tool_execution_update",
+ toolCallId: "call_omp_fg",
+ toolName: "task",
+ partialResult: {
+ content: [{ type: "text", text: "Running agent WriteGamma..." }],
+ details: {
+ projectAgentsDir: null,
+ results: [],
+ totalDurationMs: 89,
+ progress: [
+ {
+ index: 0,
+ id: "WriteGamma",
+ agent: "sonic",
+ agentSource: "bundled",
+ status: "running",
+ task: "Complete assignment thoroughly:\n\n# Target\nCreate gamma.txt",
+ assignment: "# Target\nCreate gamma.txt",
+ },
+ ],
+ },
+ },
+ });
+ const running = yield* takeEvent(
+ (event) => event.type === "subagent.updated" && event.subagent.status === "running",
+ );
+ assert.isTrue(
+ running.type === "subagent.updated" &&
+ running.subagent.title === "sonic" &&
+ running.subagent.prompt === "# Target\nCreate gamma.txt" &&
+ running.subagent.childThreadId === null,
+ );
+ yield* fake.emit({
+ type: "tool_execution_end",
+ toolCallId: "call_omp_fg",
+ toolName: "task",
+ isError: false,
+ result: {
+ content: [{ type: "text", text: "..." }],
+ details: {
+ projectAgentsDir: null,
+ results: [
+ {
+ index: 0,
+ id: "WriteGamma",
+ agent: "sonic",
+ agentSource: "bundled",
+ description: "Create gamma.txt with GAMMA content",
+ task: "Complete assignment thoroughly:\n\n# Target\nCreate gamma.txt",
+ assignment: "# Target\nCreate gamma.txt",
+ exitCode: 0,
+ output: "Created gamma.txt.",
+ },
+ ],
+ totalDurationMs: 2700,
+ },
+ },
+ });
+ const doneCard = yield* takeEvent(
+ (event) => event.type === "subagent.updated" && event.subagent.status === "completed",
+ );
+ assert.isTrue(
+ doneCard.type === "subagent.updated" &&
+ doneCard.subagent.title === "sonic" &&
+ doneCard.subagent.result === "Created gamma.txt.",
+ );
+ }).pipe(Effect.scoped, Effect.provide(layerTest)),
+ );
+
+ it.effect("projects each OMP parallel task result as its own completed subagent", () =>
+ Effect.gen(function* () {
+ const fake = yield* makeFakePi;
+ const { runtime, takeEvent } = yield* openRuntime(
+ fake,
+ "default",
+ THREAD_ID,
+ SESSION_ID,
+ undefined,
+ undefined,
+ undefined,
+ OMP_FLAVOR_OVERRIDE,
+ );
+ const providerThread = yield* runtime.ensureThread({
+ threadId: THREAD_ID,
+ modelSelection: modelSelection("default"),
+ runtimePolicy,
+ });
+ yield* startTurn(runtime, providerThread);
+ yield* fake.takeRequest("prompt");
+ yield* fake.emit({ type: "agent_start" });
+ yield* fake.emit({
+ type: "tool_execution_end",
+ toolCallId: "call_omp_par",
+ toolName: "task",
+ isError: false,
+ result: {
+ content: [{ type: "text", text: "two task results" }],
+ details: {
+ projectAgentsDir: null,
+ results: [
+ {
+ index: 0,
+ id: "AlphaWriter",
+ agent: "sonic",
+ agentSource: "bundled",
+ description: "Write alpha",
+ task: "Complete assignment thoroughly:\n\n# Target\nalpha.txt",
+ assignment: "# Target\nalpha.txt",
+ exitCode: 0,
+ output: "ALPHA written",
+ },
+ {
+ index: 1,
+ id: "BetaWriter",
+ agent: "sonic",
+ agentSource: "bundled",
+ description: "Write beta",
+ task: "Complete assignment thoroughly:\n\n# Target\nbeta.txt",
+ assignment: "# Target\nbeta.txt",
+ exitCode: 0,
+ output: "BETA written",
+ },
+ ],
+ totalDurationMs: 7100,
+ },
+ },
+ });
+ const results: Array = [];
+ while (results.length < 2) {
+ const event = yield* takeEvent(
+ (event) => event.type === "subagent.updated" && event.subagent.status === "completed",
+ );
+ if (event.type === "subagent.updated") results.push(event.subagent.result ?? "");
+ }
+ assert.deepEqual(results.sort(), ["ALPHA written", "BETA written"]);
+ }).pipe(Effect.scoped, Effect.provide(layerTest)),
+ );
+
+ it.effect("tracks OMP background task runs until wait delivers their results", () =>
+ Effect.gen(function* () {
+ const fake = yield* makeFakePi;
+ const { runtime, takeEvent } = yield* openRuntime(
+ fake,
+ "default",
+ THREAD_ID,
+ SESSION_ID,
+ undefined,
+ undefined,
+ undefined,
+ OMP_FLAVOR_OVERRIDE,
+ );
+ const providerThread = yield* runtime.ensureThread({
+ threadId: THREAD_ID,
+ modelSelection: modelSelection("default"),
+ runtimePolicy,
+ });
+ yield* startTurn(runtime, providerThread);
+ yield* fake.takeRequest("prompt");
+ yield* fake.emit({ type: "agent_start" });
+ // Spawn end frame as omp 19.2.0 sends it over RPC: background job, no results yet.
+ yield* fake.emit({
+ type: "tool_execution_end",
+ toolCallId: "call_omp_bg",
+ toolName: "task",
+ isError: false,
+ result: {
+ content: [{ type: "text", text: "Spawned agent `GammaWriter` (job `GammaWriter`)." }],
+ details: {
+ projectAgentsDir: null,
+ results: [],
+ totalDurationMs: 2,
+ progress: [
+ {
+ index: 0,
+ id: "GammaWriter",
+ agent: "sonic",
+ agentSource: "bundled",
+ status: "pending",
+ task: "Complete assignment thoroughly",
+ assignment: "# Target\nWrite GAMMA",
+ },
+ ],
+ async: { state: "running", jobId: "GammaWriter", type: "task" },
+ },
+ },
+ });
+ const pendingSignal = yield* takeEvent((event) => event.type === "background_work.updated");
+ assert.isTrue(pendingSignal.type === "background_work.updated" && pendingSignal.pending);
+ yield* fake.emit({ type: "turn_end", message: { role: "assistant", content: [] } });
+ // The coordinator settles the job later via the wait tool; omp delivers the
+ // subagent's result as a task-result block inside the wait result's text.
+ yield* fake.emit({
+ type: "tool_execution_end",
+ toolCallId: "call_wait",
+ toolName: "wait",
+ isError: false,
+ result: {
+ content: [
+ {
+ type: "text",
+ text: '## Completed (1)\n\n### GammaWriter [task] — completed\n```\n\n\n\n\n```',
+ },
+ ],
+ details: {},
+ },
+ });
+ const doneCard = yield* takeEvent(
+ (event) => event.type === "subagent.updated" && event.subagent.status === "completed",
+ );
+ assert.isTrue(
+ doneCard.type === "subagent.updated" &&
+ doneCard.subagent.title === "sonic" &&
+ doneCard.subagent.result === "Created gamma.txt with GAMMA.",
+ );
+ const settledSignal = yield* takeEvent(
+ (event) => event.type === "background_work.updated" && !event.pending,
+ );
+ assert.isTrue(settledSignal.type === "background_work.updated");
+ }).pipe(Effect.scoped, Effect.provide(layerTest)),
+ );
+
it.effect("shows the members of an async pi-subagents workflow as running subagents", () =>
Effect.gen(function* () {
const fake = yield* makeFakePi;
diff --git a/packages/provider-pi/src/server/adapter.ts b/packages/provider-pi/src/server/adapter.ts
index f1adce3b9e8cd..17aadfc3fe4b5 100644
--- a/packages/provider-pi/src/server/adapter.ts
+++ b/packages/provider-pi/src/server/adapter.ts
@@ -209,6 +209,8 @@ export interface PiAdapterV2Options {
readonly linkedToInferenceServer?: boolean;
readonly driverKind?: ProviderDriverKind;
readonly defaultBinary?: string;
+ /** Tool name projecting subagent cards; pi-subagents uses "subagent", OMP uses "task". */
+ readonly subagentToolName?: string;
readonly continuationRequests?: {
readonly offer: (
request: ProviderContinuationRequests.ProviderContinuationRequest,
@@ -321,13 +323,6 @@ function piToolOutput(result: unknown, toolName: string): unknown {
};
}
-function providerRef(
- nativeId: string,
- strength: "strong" | "weak" = "strong",
-): OrchestrationV2ProviderRef {
- return { driver: PI_PROVIDER, nativeId, strength };
-}
-
const PI_THINKING_LEVELS = new Set(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
interface PiStreamItemState {
@@ -477,6 +472,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
) {
const PI_PROVIDER = options.driverKind ?? PI_DRIVER_KIND;
const defaultBinary = options.defaultBinary ?? "pi";
+ const subagentToolName = options.subagentToolName ?? "subagent";
const providerRef = (
nativeId: string,
strength: "strong" | "weak" = "strong",
@@ -653,12 +649,15 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
const customAnswerFollowUps = new Map();
const sessionApprovals = new Set();
// Async pi-subagents runs launched in this session, by async id, until they settle.
+ // omp `task` runs are tracked by job id; `members` names the spawned subagents
+ // so `wait` results can settle them.
const piAsyncRuns = new Map<
string,
{
readonly turn: ActivePiTurn;
readonly toolCallId: string;
readonly emitted: Map;
+ readonly members: Set;
}
>();
// The launch snapshot arrives before the tool result that names its run.
@@ -1536,9 +1535,14 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
...(viewedImagePath === undefined ? {} : { viewedImagePath }),
},
});
- if (toolName === "subagent") {
+ if (toolName === subagentToolName) {
yield* emitSubagentTasks(turn, toolCallId, resultRecord, completed);
}
+ // omp settles background `task` runs through `wait` results; pi members
+ // arrive in the subagent-async widget instead.
+ if (toolName === "wait" && piAsyncRuns.size > 0) {
+ yield* settleOmpWaitResults(resultRecord);
+ }
});
const emitSubagentTasks = Effect.fnUntraced(function* (
@@ -1549,40 +1553,76 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
) {
const details = recordField(resultRecord, "details");
const results = recordField(details, "results");
- if (!Array.isArray(results)) return;
let emitted = false;
- for (const [index, result] of results.entries()) {
- const agent = recordString(result, "agent");
- const task = recordString(result, "task");
- if (agent === undefined || task === undefined) continue;
- emitted = true;
- const finished = completed || recordField(result, "finished") === true;
- const stopReason = recordString(result, "stopReason");
- const interrupted = finished && stopReason === "aborted";
- const failed =
- finished &&
- !interrupted &&
- ((recordNumber(result, "exitCode") ?? 0) !== 0 || stopReason === "error");
- const outputText = piSubagentOutput(result);
- yield* emitSubagent(turn, toolCallId, `${recordNumber(result, "step") ?? index}`, {
- agent,
- task,
- model: recordString(result, "model") ?? null,
- status: interrupted
- ? "interrupted"
- : failed
- ? "failed"
- : finished
- ? "completed"
- : "running",
- progress: !finished && outputText.length > 0 ? outputText.slice(0, 200) : undefined,
- result: finished && outputText.length > 0 ? outputText.slice(0, 10_000) : null,
- });
+ if (Array.isArray(results)) {
+ for (const [index, result] of results.entries()) {
+ const agent = recordString(result, "agent");
+ const task = recordString(result, "assignment") ?? recordString(result, "task");
+ if (agent === undefined || task === undefined) continue;
+ emitted = true;
+ const finished = completed || recordField(result, "finished") === true;
+ const stopReason = recordString(result, "stopReason");
+ const interrupted = finished && stopReason === "aborted";
+ const failed =
+ finished &&
+ !interrupted &&
+ ((recordNumber(result, "exitCode") ?? 0) !== 0 || stopReason === "error");
+ const outputText = piSubagentOutput(result);
+ yield* emitSubagent(turn, toolCallId, `${recordNumber(result, "step") ?? index}`, {
+ agent,
+ task,
+ model: recordString(result, "model") ?? null,
+ status: interrupted
+ ? "interrupted"
+ : failed
+ ? "failed"
+ : finished
+ ? "completed"
+ : "running",
+ progress: !finished && outputText.length > 0 ? outputText.slice(0, 200) : undefined,
+ result: finished && outputText.length > 0 ? outputText.slice(0, 10_000) : null,
+ });
+ }
}
- // Async launches return no results; their members arrive in the subagent-async widget.
- const asyncId = recordString(details, "asyncId");
- if (!emitted && asyncId !== undefined && !piAsyncRuns.has(asyncId)) {
- const tracked = { turn, toolCallId, emitted: new Map() };
+ // omp streams running members through `progress[]` while `results[]` is still empty.
+ if (!emitted) {
+ const progress = recordField(details, "progress");
+ if (Array.isArray(progress)) {
+ for (const [index, entry] of progress.entries()) {
+ const agent = recordString(entry, "agent");
+ if (agent === undefined) continue;
+ emitted = true;
+ const status = recordString(entry, "status") ?? "running";
+ yield* emitSubagent(turn, toolCallId, recordString(entry, "id") ?? `${index}`, {
+ agent,
+ task: recordString(entry, "assignment") ?? recordString(entry, "task") ?? "",
+ model: null,
+ status:
+ status === "completed"
+ ? "completed"
+ : status === "failed" || status === "error"
+ ? "failed"
+ : status === "aborted"
+ ? "interrupted"
+ : "running",
+ result: null,
+ });
+ }
+ }
+ }
+ // Async launches return no results; pi members arrive in the subagent-async
+ // widget, omp members in `wait` results. Track the run until it settles.
+ const asyncId =
+ recordString(details, "asyncId") ?? recordString(recordField(details, "async"), "jobId");
+ if (asyncId !== undefined && !piAsyncRuns.has(asyncId)) {
+ const progress = recordField(details, "progress");
+ const members = new Set(
+ (Array.isArray(progress) ? progress : []).flatMap((entry) => {
+ const id = recordString(entry, "id");
+ return id === undefined ? [] : [id];
+ }),
+ );
+ const tracked = { turn, toolCallId, emitted: new Map(), members };
piAsyncRuns.set(asyncId, tracked);
// Keeps the run ingesting after the coordinator's turn ends, until the run settles.
yield* emit({
@@ -1596,6 +1636,68 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
}
});
+ // omp delivers background `task` results through `wait` tool results as
+ // task-result blocks; settle the tracked run's members from them.
+ const settleOmpWaitResults = Effect.fnUntraced(function* (resultRecord: unknown) {
+ if (piAsyncRuns.size === 0) return;
+ const outputText = contentText(recordField(resultRecord, "content"));
+ if (outputText.length === 0) return;
+ const blockPattern =
+ /([\s\S]*?)<\/task-result>/g;
+ for (const match of outputText.matchAll(blockPattern)) {
+ const id = match[1];
+ const agent = match[2];
+ const status = match[3];
+ const body = match[4];
+ if (
+ id === undefined ||
+ agent === undefined ||
+ status === undefined ||
+ body === undefined
+ ) {
+ continue;
+ }
+ const trackedEntry = [...piAsyncRuns.entries()].find(([, tracked]) =>
+ tracked.members.has(id),
+ );
+ if (trackedEntry === undefined) continue;
+ const [runId, tracked] = trackedEntry;
+ const output = /