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]>
This commit is contained in:
Mike Olsonandcodex authored and Julius Marminge committed 2026-08-15 16:49:58 +02:00
1 parent 0282ab8608
commit e16d4e514b
53 files changed
+15859 -985

No files matched your search

@@ -39,6 +39,7 @@ function shouldShowLocalTurnItem(
item,
runs: projection.runs,
attempts: projection.attempts,
items: projection.turnItems,
});
}
+10
View File
@@ -27,6 +27,10 @@ export interface AcpClientOptions {
readonly logIncoming?: boolean;
readonly logOutgoing?: boolean;
readonly logger?: (event: AcpProtocol.AcpProtocolLogEvent) => Effect.Effect<void, never>;
readonly onIncomingRequest?: AcpProtocol.AcpPatchedProtocolOptions["onIncomingRequest"];
readonly onTermination?: AcpProtocol.AcpPatchedProtocolOptions["onTermination"];
readonly onOutgoingResponseFailure?: AcpProtocol.AcpPatchedProtocolOptions["onOutgoingResponseFailure"];
readonly onOutgoingResponse?: AcpProtocol.AcpPatchedProtocolOptions["onOutgoingResponse"];
}
type AcpClientRaw = {
@@ -404,6 +408,12 @@ export const make = Effect.fn("effect-acp/AcpClient.make")(function* (
...(options.logIncoming !== undefined ? { logIncoming: options.logIncoming } : {}),
...(options.logOutgoing !== undefined ? { logOutgoing: options.logOutgoing } : {}),
...(options.logger ? { logger: options.logger } : {}),
...(options.onIncomingRequest ? { onIncomingRequest: options.onIncomingRequest } : {}),
...(options.onTermination ? { onTermination: options.onTermination } : {}),
...(options.onOutgoingResponseFailure
? { onOutgoingResponseFailure: options.onOutgoingResponseFailure }
: {}),
...(options.onOutgoingResponse ? { onOutgoingResponse: options.onOutgoingResponse } : {}),
onNotification: dispatchNotification,
onExtRequest: dispatchExtRequest,
});
+200
View File
@@ -3,8 +3,12 @@ import * as AcpError from "./errors.ts";
import * as Effect from "effect/Effect";
import * as Deferred from "effect/Deferred";
import * as Fiber from "effect/Fiber";
import * as Exit from "effect/Exit";
import * as Queue from "effect/Queue";
import * as Schema from "effect/Schema";
import * as Scope from "effect/Scope";
import * as Sink from "effect/Sink";
import * as Stdio from "effect/Stdio";
import * as Stream from "effect/Stream";
import * as Ref from "effect/Ref";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
@@ -491,6 +495,177 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => {
}),
);
it.effect("acknowledges outgoing responses and reports encoding failures by request id", () =>
Effect.gen(function* () {
const { stdio } = yield* makeInMemoryStdio();
const acknowledged = yield* Deferred.make<string>();
const failed = yield* Deferred.make<readonly [string, AcpError.AcpError]>();
const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
stdio,
serverRequestMethods: new Set(),
onOutgoingResponse: (requestId) =>
Deferred.succeed(acknowledged, requestId).pipe(Effect.asVoid),
onOutgoingResponseFailure: (requestId, error) =>
Deferred.succeed(failed, [requestId, error]).pipe(Effect.asVoid),
});
yield* transport.serverProtocol.send(0, {
_tag: "Exit",
requestId: "success-1",
exit: { _tag: "Success", value: { ok: true } },
});
assert.equal(yield* Deferred.await(acknowledged), "success-1");
const circular: { self?: unknown } = {};
circular.self = circular;
yield* transport.serverProtocol
.send(0, {
_tag: "Exit",
requestId: "failure-1",
exit: { _tag: "Success", value: circular },
})
.pipe(Effect.exit);
const [requestId, error] = yield* Deferred.await(failed);
assert.equal(requestId, "failure-1");
assert.instanceOf(error, AcpError.AcpProtocolParseError);
}),
);
it.effect("acknowledges a response only after the stdout write completes", () =>
Effect.gen(function* () {
const writeStarted = yield* Deferred.make<void>();
const releaseWrite = yield* Deferred.make<void>();
const acknowledged = yield* Deferred.make<string>();
const stdio = Stdio.make({
args: Effect.succeed([]),
stdin: Stream.never,
stdout: () =>
Sink.forEach(() =>
Deferred.succeed(writeStarted, undefined).pipe(
Effect.andThen(Deferred.await(releaseWrite)),
),
),
stderr: () => Sink.drain,
});
const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
stdio,
serverRequestMethods: new Set(),
onOutgoingResponse: (requestId) =>
Deferred.succeed(acknowledged, requestId).pipe(Effect.asVoid),
});
const sendFiber = yield* transport.serverProtocol
.send(0, {
_tag: "Exit",
requestId: "held-write",
exit: { _tag: "Success", value: { ok: true } },
})
.pipe(Effect.forkScoped);
yield* Deferred.await(writeStarted);
assert.isUndefined(sendFiber.pollUnsafe());
assert.isFalse(yield* Deferred.isDone(acknowledged));
yield* Deferred.succeed(releaseWrite, undefined);
yield* Fiber.join(sendFiber);
assert.equal(yield* Deferred.await(acknowledged), "held-write");
}),
);
it.effect("fails current, queued, and future responses when the stdout writer fails", () =>
Effect.gen(function* () {
const writeStarted = yield* Deferred.make<void>();
const releaseFailure = yield* Deferred.make<void>();
const failures = yield* Queue.unbounded<string>();
const terminated = yield* Deferred.make<AcpError.AcpError>();
const stdio = Stdio.make({
args: Effect.succeed([]),
stdin: Stream.never,
stdout: () =>
Sink.forEach(() =>
Deferred.succeed(writeStarted, undefined).pipe(
Effect.andThen(Deferred.await(releaseFailure)),
Effect.andThen(Effect.die("stdout failed")),
),
),
stderr: () => Sink.drain,
});
const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
stdio,
serverRequestMethods: new Set(),
onOutgoingResponseFailure: (requestId) => Queue.offer(failures, requestId),
onTermination: (error) => Deferred.succeed(terminated, error).pipe(Effect.asVoid),
});
const send = (requestId: string) =>
transport.serverProtocol
.send(0, {
_tag: "Exit",
requestId,
exit: { _tag: "Success", value: { ok: true } },
})
.pipe(Effect.exit);
const current = yield* send("current").pipe(Effect.forkScoped);
yield* Deferred.await(writeStarted);
const queued = yield* send("queued").pipe(Effect.forkScoped);
yield* Effect.yieldNow;
assert.isUndefined(current.pollUnsafe());
assert.isUndefined(queued.pollUnsafe());
yield* Deferred.succeed(releaseFailure, undefined);
assert.instanceOf(yield* Deferred.await(terminated), AcpError.AcpTransportError);
yield* Fiber.join(current);
yield* Fiber.join(queued);
yield* send("future");
assert.deepEqual(
new Set(yield* Queue.takeN(failures, 3)),
new Set(["current", "queued", "future"]),
);
}),
);
it.effect(
"atomically rejects an admitted response when the writer closes before queue offer",
() =>
Effect.gen(function* () {
const admitted = yield* Deferred.make<void>();
const releaseAdmission = yield* Deferred.make<void>();
const failures = yield* Queue.unbounded<string>();
const protocolScope = yield* Scope.make();
const stdio = Stdio.make({
args: Effect.succeed([]),
stdin: Stream.never,
stdout: () => Sink.drain,
stderr: () => Sink.drain,
});
const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
stdio,
serverRequestMethods: new Set(),
onOutgoingResponseFailure: (requestId) => Queue.offer(failures, requestId),
testHooks: {
onOutgoingWriteAdmitted: () =>
Deferred.succeed(admitted, undefined).pipe(
Effect.andThen(Deferred.await(releaseAdmission)),
),
},
}).pipe(Effect.provideService(Scope.Scope, protocolScope));
const send = (requestId: string) =>
transport.serverProtocol
.send(0, {
_tag: "Exit",
requestId,
exit: { _tag: "Success", value: { ok: true } },
})
.pipe(Effect.exit);
const admittedSend = yield* send("admitted").pipe(Effect.forkScoped);
yield* Deferred.await(admitted);
yield* Scope.close(protocolScope, Exit.void);
yield* Deferred.succeed(releaseAdmission, undefined);
yield* Fiber.join(admittedSend);
yield* send("future");
assert.deepEqual(yield* Queue.takeN(failures, 2), ["admitted", "future"]);
}),
);
it.effect("cleans up interrupted extension requests before a late response arrives", () =>
Effect.gen(function* () {
const { stdio, input, output } = yield* makeInMemoryStdio();
@@ -596,6 +771,31 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => {
}),
);
it.effect("does not treat intentional serverProtocol.end as a transport failure", () =>
Effect.gen(function* () {
const { stdio, input } = yield* makeInMemoryStdio();
const terminations = yield* Ref.make(0);
const writerExit = yield* Deferred.make<{ readonly intentionalEnd: boolean }>();
const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
stdio,
serverRequestMethods: new Set(),
onTermination: () => Ref.update(terminations, (count) => count + 1),
testHooks: {
onOutgoingWriterExit: (detail) =>
Deferred.succeed(writerExit, detail).pipe(Effect.asVoid),
},
});
yield* transport.serverProtocol.end(0);
const exitDetail = yield* Deferred.await(writerExit);
assert.isTrue(exitDetail.intentionalEnd);
assert.equal(yield* Ref.get(terminations), 0);
// Tear down the forever input reader so the scoped test can finish.
yield* Queue.end(input);
}),
);
it.effect("does not emit a second process-exit error after a decode failure", () =>
Effect.gen(function* () {
const handle = yield* makeHandle({
+219 -8
View File
@@ -1,6 +1,7 @@
import * as Cause from "effect/Cause";
import * as Effect from "effect/Effect";
import * as Deferred from "effect/Deferred";
import * as Exit from "effect/Exit";
import * as Queue from "effect/Queue";
import * as Ref from "effect/Ref";
import * as Schema from "effect/Schema";
@@ -48,6 +49,11 @@ export interface AcpPatchedProtocolOptions {
readonly logIncoming?: boolean;
readonly logOutgoing?: boolean;
readonly logger?: (event: AcpProtocolLogEvent) => Effect.Effect<void, never>;
readonly onIncomingRequest?: (
requestId: string,
method: string,
payload: unknown,
) => Effect.Effect<void, never>;
readonly onNotification?: (
notification: AcpIncomingNotification,
) => Effect.Effect<void, AcpError.AcpError, never>;
@@ -56,6 +62,18 @@ export interface AcpPatchedProtocolOptions {
params: unknown,
) => Effect.Effect<unknown, AcpError.AcpError, never>;
readonly onTermination?: (error: AcpError.AcpError) => Effect.Effect<void, never, never>;
readonly onOutgoingResponseFailure?: (
requestId: string,
error: AcpError.AcpError,
) => Effect.Effect<void, never>;
readonly onOutgoingResponse?: (requestId: string) => Effect.Effect<void, never>;
readonly testHooks?: {
readonly onOutgoingWriteAdmitted?: () => Effect.Effect<void>;
/** Invoked from the stdout writer exit path (after intentional/unexpected handling). */
readonly onOutgoingWriterExit?: (input: {
readonly intentionalEnd: boolean;
}) => Effect.Effect<void>;
};
}
export interface AcpPatchedProtocol {
@@ -71,6 +89,17 @@ interface AcpPendingRequest {
readonly method: string;
}
interface AcpOutgoingWrite {
readonly acknowledgement?: Deferred.Deferred<void, AcpError.AcpError>;
readonly payload: string | Uint8Array;
}
interface AcpOutgoingWriterState {
readonly outstandingAcknowledgements: ReadonlySet<Deferred.Deferred<void, AcpError.AcpError>>;
readonly intentionalEnd: boolean;
readonly terminalError?: AcpError.AcpError;
}
const decodeSessionUpdate = Schema.decodeUnknownEffect(AcpSchema.SessionNotification);
const decodeElicitationComplete = Schema.decodeUnknownEffect(
AcpSchema.ElicitationCompleteNotification,
@@ -85,8 +114,12 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
const clientQueue = yield* Queue.unbounded<RpcMessage.FromServerEncoded>();
const notificationQueue = yield* Queue.unbounded<AcpIncomingNotification>();
const disconnects = yield* Queue.unbounded<number>();
const outgoing = yield* Queue.unbounded<string | Uint8Array, Cause.Done<void>>();
const nextRequestId = yield* Ref.make(1);
const outgoing = yield* Queue.unbounded<AcpOutgoingWrite, AcpError.AcpError | Cause.Done<void>>();
const outgoingWriterState = yield* Ref.make<AcpOutgoingWriterState>({
intentionalEnd: false,
outstandingAcknowledgements: new Set(),
});
const nextRequestId = yield* Ref.make(1n);
const terminationHandled = yield* Ref.make(false);
const extPending = yield* Ref.make(new Map<string, AcpPendingRequest>());
@@ -132,7 +165,66 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
payload: typeof encoded === "string" ? encoded : new TextDecoder().decode(encoded),
});
yield* Queue.offer(outgoing, encoded).pipe(Effect.asVoid);
const acknowledgement =
message._tag === "Exit" ? yield* Deferred.make<void, AcpError.AcpError>() : undefined;
const admissionError = yield* Ref.modify(outgoingWriterState, (state) => {
if (state.terminalError !== undefined) {
return [state.terminalError, state] as const;
}
if (acknowledgement === undefined) {
return [undefined, state] as const;
}
return [
undefined,
{
...state,
outstandingAcknowledgements: new Set(state.outstandingAcknowledgements).add(
acknowledgement,
),
},
] as const;
});
if (admissionError !== undefined) {
return yield* admissionError;
}
if (options.testHooks?.onOutgoingWriteAdmitted !== undefined) {
yield* options.testHooks.onOutgoingWriteAdmitted();
}
yield* Queue.offer(outgoing, {
payload: encoded,
...(acknowledgement === undefined ? {} : { acknowledgement }),
}).pipe(
Effect.mapError(
(cause) =>
new AcpError.AcpTransportError({
detail: "Failed to queue an outgoing ACP message",
cause,
}),
),
Effect.filterOrFail(
(accepted) => accepted,
() =>
new AcpError.AcpTransportError({
detail: "The ACP output queue was closed before accepting a message",
cause: "Output queue closed",
}),
),
Effect.tapError((error) =>
acknowledgement === undefined
? Effect.void
: Ref.update(outgoingWriterState, (state) => {
const updated = new Set(state.outstandingAcknowledgements);
updated.delete(acknowledgement);
return { ...state, outstandingAcknowledgements: updated };
}).pipe(Effect.andThen(Deferred.fail(acknowledgement, error)), Effect.asVoid),
),
);
if (acknowledgement !== undefined) {
yield* Deferred.await(acknowledgement);
}
if (message._tag === "Exit" && options.onOutgoingResponse !== undefined) {
yield* options.onOutgoingResponse(message.requestId);
}
}
});
@@ -310,8 +402,11 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
});
}
const observeIncoming =
options.onIncomingRequest?.(message.id, message.tag, message.payload) ?? Effect.void;
if (!options.serverRequestMethods.has(message.tag)) {
return handleExtRequest(message).pipe(
return observeIncoming.pipe(Effect.andThen(handleExtRequest(message))).pipe(
Effect.catchTags({
AcpProtocolParseError: (error) =>
Effect.logWarning(error).pipe(
@@ -336,7 +431,7 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
);
}
return Queue.offer(serverQueue, message).pipe(Effect.asVoid);
return observeIncoming.pipe(Effect.andThen(Queue.offer(serverQueue, message)), Effect.asVoid);
};
const handleExitEncoded = (message: RpcMessage.ResponseExitEncoded) =>
@@ -475,7 +570,112 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
Effect.forkScoped,
);
yield* Stream.fromQueue(outgoing).pipe(Stream.run(options.stdio.stdout()), Effect.forkScoped);
const failOutgoingWrites = (error: AcpError.AcpError) =>
Ref.modify(outgoingWriterState, (state) => {
const terminalError = state.terminalError ?? error;
return [
[terminalError, state.outstandingAcknowledgements] as const,
{
...state,
terminalError,
outstandingAcknowledgements: new Set<Deferred.Deferred<void, AcpError.AcpError>>(),
},
] as const;
}).pipe(
Effect.flatMap((acknowledgements) =>
Effect.forEach(
acknowledgements[1],
(acknowledgement) => Deferred.fail(acknowledgement, acknowledgements[0]),
{ concurrency: "unbounded", discard: true },
),
),
Effect.andThen(Queue.fail(outgoing, error)),
Effect.asVoid,
);
const completeOutgoingWrites = () =>
Ref.modify(outgoingWriterState, (state) => {
return [
state.outstandingAcknowledgements,
{
...state,
outstandingAcknowledgements: new Set<Deferred.Deferred<void, AcpError.AcpError>>(),
},
] as const;
}).pipe(
Effect.flatMap((acknowledgements) =>
Effect.forEach(
acknowledgements,
(acknowledgement) => Deferred.succeed(acknowledgement, undefined),
{ concurrency: "unbounded", discard: true },
),
),
Effect.asVoid,
);
const acknowledgeOutgoingWrite = (acknowledgement: Deferred.Deferred<void, AcpError.AcpError>) =>
Ref.update(outgoingWriterState, (state) => {
const updated = new Set(state.outstandingAcknowledgements);
updated.delete(acknowledgement);
return { ...state, outstandingAcknowledgements: updated };
}).pipe(Effect.andThen(Deferred.succeed(acknowledgement, undefined)), Effect.asVoid);
yield* Stream.fromQueue(outgoing).pipe(
Stream.flatMap((write) => {
const acknowledgement = write.acknowledgement;
const completion =
acknowledgement === undefined
? Stream.empty
: Stream.fromEffect(acknowledgeOutgoingWrite(acknowledgement)).pipe(Stream.drain);
return Stream.make(write.payload).pipe(Stream.concat(completion));
}),
Stream.run(options.stdio.stdout()),
Effect.onExit((exit) =>
Exit.match(exit, {
onFailure: (cause) => {
const error = new AcpError.AcpTransportError({
detail: Cause.hasInterruptsOnly(cause)
? "The ACP output writer was interrupted while closing"
: "Failed to write an outgoing ACP message",
cause,
});
return failOutgoingWrites(error).pipe(
Effect.andThen(
Cause.hasInterruptsOnly(cause)
? Effect.void
: handleTermination(() => Effect.succeed(error)),
),
);
},
onSuccess: () =>
Ref.get(outgoingWriterState).pipe(
Effect.flatMap((state) => {
// Intentional Queue.end (serverProtocol.end) completes the writer
// successfully. Do not invent a transport failure or client protocol
// error for a clean RPC shutdown.
const handled = state.intentionalEnd
? completeOutgoingWrites()
: (() => {
const error = new AcpError.AcpTransportError({
detail: "ACP output writer ended before the protocol closed",
cause: "Output writer ended",
});
return failOutgoingWrites(error).pipe(
Effect.andThen(handleTermination(() => Effect.succeed(error))),
);
})();
return handled.pipe(
Effect.andThen(
options.testHooks?.onOutgoingWriterExit === undefined
? Effect.void
: options.testHooks.onOutgoingWriterExit({
intentionalEnd: state.intentionalEnd,
}),
),
);
}),
),
}),
),
Effect.forkScoped,
);
const clientProtocol = RpcClient.Protocol.of({
run: (_clientId, f) =>
@@ -506,8 +706,19 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
Effect.forever,
),
disconnects,
send: (_clientId, response) => offerOutgoing(response).pipe(Effect.orDie),
end: (_clientId) => Queue.end(outgoing),
send: (_clientId, response) =>
offerOutgoing(response).pipe(
Effect.tapError((error) =>
response._tag === "Exit" && options.onOutgoingResponseFailure !== undefined
? options.onOutgoingResponseFailure(response.requestId, error)
: Effect.void,
),
Effect.orDie,
),
end: (_clientId) =>
Ref.update(outgoingWriterState, (state) => ({ ...state, intentionalEnd: true })).pipe(
Effect.andThen(Queue.end(outgoing)),
),
clientIds: Effect.succeed(new Set([0])),
initialMessage: Effect.succeedNone,
supportsAck: true,
@@ -56,4 +56,20 @@ describe("projectThreadAwarenessV2", () => {
}),
).toMatchObject({ phase: "waiting_for_input", headline: "Waiting for input" });
});
it("does not present authentication refreshes as user approvals", () => {
expect(
projectThreadAwarenessV2({
environmentId: "env-1" as EnvironmentId,
project,
thread: v2Thread({
pendingRuntimeRequest: {
id: RuntimeRequestId.make("request-auth-refresh"),
kind: "auth_refresh",
createdAt: updatedAt,
},
}),
}),
).toMatchObject({ phase: "running", headline: "Agent is working" });
});
});
+4 -1
View File
@@ -87,7 +87,10 @@ function resolveThreadAwarenessPhaseV2(
if (thread.pendingRuntimeRequest?.kind === "user_input") {
return "waiting_for_input";
}
if (thread.pendingRuntimeRequest !== null) {
if (
thread.pendingRuntimeRequest !== null &&
thread.pendingRuntimeRequest.kind !== "auth_refresh"
) {
return "waiting_for_approval";
}
switch (thread.status) {
@@ -7,22 +7,52 @@ const runId = RunId.make("run:timeline-visibility");
const nodeId = NodeId.make("node:timeline-visibility");
describe("isOrchestrationV2TurnItemVisible", () => {
it("hides interruption results from superseded attempts", () => {
it("hides unpaired interruption results from superseded attempts", () => {
expect(
isOrchestrationV2TurnItemVisible({
item: { type: "run_interrupt_result", runId, nodeId },
runs: [{ id: runId, status: "running" }],
attempts: [{ runId, rootNodeId: nodeId, status: "superseded" }],
items: [{ type: "run_interrupt_result", runId, nodeId }],
}),
).toBe(false);
});
it("keeps interruption results from terminal attempts", () => {
it("keeps paired interruption results from superseded attempts", () => {
expect(
isOrchestrationV2TurnItemVisible({
item: { type: "run_interrupt_result", runId, nodeId },
runs: [{ id: runId, status: "running" }],
attempts: [{ runId, rootNodeId: nodeId, status: "superseded" }],
items: [
{ type: "run_interrupt_request", runId, nodeId },
{ type: "run_interrupt_result", runId, nodeId },
],
}),
).toBe(true);
});
it("keeps interruption results from terminal attempts without a request", () => {
expect(
isOrchestrationV2TurnItemVisible({
item: { type: "run_interrupt_result", runId, nodeId },
runs: [{ id: runId, status: "interrupted" }],
attempts: [{ runId, rootNodeId: nodeId, status: "interrupted" }],
items: [{ type: "run_interrupt_result", runId, nodeId }],
}),
).toBe(true);
});
it("keeps interruption results from terminal attempts with a request", () => {
expect(
isOrchestrationV2TurnItemVisible({
item: { type: "run_interrupt_result", runId, nodeId },
runs: [{ id: runId, status: "interrupted" }],
attempts: [{ runId, rootNodeId: nodeId, status: "interrupted" }],
items: [
{ type: "run_interrupt_request", runId, nodeId },
{ type: "run_interrupt_result", runId, nodeId },
],
}),
).toBe(true);
});
@@ -40,6 +70,7 @@ describe("isOrchestrationV2TurnItemVisible", () => {
},
{ runId, rootNodeId: nodeId, status: "interrupted" },
],
items: [{ type: "run_interrupt_result", runId, nodeId }],
}),
).toBe(true);
});
+18 -2
View File
@@ -11,24 +11,36 @@ 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;
}
return input.attempts.some(
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 (
@@ -38,5 +50,9 @@ export function isOrchestrationV2TurnItemVisible(input: {
return false;
}
return !isOrchestrationV2SupersededInterrupt({ item, attempts: input.attempts });
return !isOrchestrationV2SupersededInterrupt({
item,
attempts: input.attempts,
items: input.items,
});
}