Files
t3code/packages/shared/src/orchestrationV2Timeline.ts
T
Mike Olsonandcodex 9b91d3b8ca fix(orchestrator): harden Grok v2 lifecycle (#3578)
Integrate the current Grok settlement, monitor/subagent lifecycle, interrupt containment, steer visibility, and image support stack into the orchestration-v2 branch.

Co-authored-by: codex <[email protected]>
2026-08-03 11:45:08 -04:00

59 lines
1.8 KiB
TypeScript

import type {
OrchestrationV2Run,
OrchestrationV2RunAttempt,
OrchestrationV2TurnItem,
} from "@t3tools/contracts";
type TimelineRun = Pick<OrchestrationV2Run, "id" | "status">;
type TimelineRunAttempt = Pick<OrchestrationV2RunAttempt, "runId" | "rootNodeId" | "status">;
type TimelineTurnItem = Pick<OrchestrationV2TurnItem, "type" | "runId" | "nodeId">;
export function isOrchestrationV2SupersededInterrupt(input: {
readonly item: TimelineTurnItem;
readonly attempts: ReadonlyArray<TimelineRunAttempt>;
readonly items: ReadonlyArray<TimelineTurnItem>;
}): boolean {
const { item } = input;
if (item.type !== "run_interrupt_result" || item.runId === null || item.nodeId === null) {
return false;
}
const isSuperseded = input.attempts.some(
(attempt) =>
attempt.runId === item.runId &&
attempt.rootNodeId === item.nodeId &&
attempt.status === "superseded",
);
if (!isSuperseded) {
return false;
}
// Paired stop-then-steer results have a matching request on the same run and
// must stay visible. Legacy plain-steer results have no request and stay hidden.
const hasMatchingRequest = input.items.some(
(candidate) => candidate.type === "run_interrupt_request" && candidate.runId === item.runId,
);
return !hasMatchingRequest;
}
export function isOrchestrationV2TurnItemVisible(input: {
readonly item: TimelineTurnItem;
readonly runs: ReadonlyArray<TimelineRun>;
readonly attempts: ReadonlyArray<TimelineRunAttempt>;
readonly items: ReadonlyArray<TimelineTurnItem>;
}): boolean {
const { item } = input;
if (
item.runId !== null &&
input.runs.some((run) => run.id === item.runId && run.status === "rolled_back")
) {
return false;
}
return !isOrchestrationV2SupersededInterrupt({
item,
attempts: input.attempts,
items: input.items,
});
}