The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
fix(pi): async subagents leave Running when their run settles first (#39888)
Julius Marminge committed
Nov 20, 2026 at 13:18 UTC
c53ac237a0af3d48229a509945edb0168fc92df1
2 files changed
+6
packages/provider-pi/src/server/adapter.test.ts
+2
@@ -3864,6 +3864,8 @@ describe("PiAdapterV2", () => {
3864
statuses: ["running", "running"],
3865
pending: [true],
3866
});
3867
+ // pi-subagents can mark the run settled one snapshot before the member that ran last.
3868
+ yield* emitSnapshot("failed", "running", "failed");
3869
yield* emitSnapshot("failed", "complete", "failed");
3870
assert.deepEqual(yield* collect("marker-2"), {
3871
statuses: ["completed", "failed"],
packages/provider-pi/src/server/adapter.ts
+4
@@ -1618,12 +1618,14 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
1618
run: unknown,
1619
) {
1620
const children = recordField(run, "children");
1621
+ let childrenSettled = true;
1622
for (const child of Array.isArray(children) ? children : []) {
1623
const id = recordString(child, "id");
1624
const agent = recordString(child, "agent");
1625
const status = piAsyncSubagentStatus(recordString(child, "state"));
1626
if (recordString(child, "kind") !== "step" || id === undefined) continue;
1627
if (agent === undefined || status === undefined) continue;
1628
+ if (status === "running" || status === "pending") childrenSettled = false;
1629
const model = recordString(child, "model") ?? null;
1630
const key = `${status}:${model}`;
1631
if (tracked.emitted.get(id) === key) continue;
@@ -1638,6 +1640,8 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
1640
}
1641
const runStatus = piAsyncSubagentStatus(recordString(run, "state"));
1642
if (runStatus === undefined || runStatus === "running" || runStatus === "pending") return;
1643
+ // pi-subagents can settle the run one snapshot before its last step.
1644
+ if (!childrenSettled) return;
1645
piAsyncRuns.delete(runId);
1646
const providerTurnId = tracked.turn.providerTurn.id;
1647
for (const other of piAsyncRuns.values()) {