Skip to content

Commit 8a8f178

Browse files
author
AskPlays
committed
fix(server): settle OpenCode interrupted turns in the projection
Upstream's reworked OpenCode interrupt path (pingdotgg#8480, merged in b99e491) ends an aborted turn with only the informational turn.aborted runtime event, which the orchestration lifecycle never consumes. The projected session stayed "running" after the agent had actually stopped, so web and mobile kept the turn looking active forever. Failed prompt submissions leaked the same stuck state. The adapter now pairs the abort marker with the terminal completion the other providers already emit: turn.completed state "interrupted" for user stops, and state "failed" with the error detail for failed prompt submissions. Ingestion folds that into the thread session (ready, active turn cleared), so clients settle the turn immediately. Model: glm-5.3-flash via opencode
1 parent 75004db commit 8a8f178

3 files changed

Lines changed: 288 additions & 60 deletions

File tree

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,117 @@ describe("ProviderRuntimeIngestion", () => {
741741
);
742742
});
743743

744+
it("settles a running turn's session when the provider reports the turn interrupted", async () => {
745+
const harness = await createHarness();
746+
const now = "2026-01-01T00:00:00.000Z";
747+
748+
harness.emit({
749+
type: "turn.started",
750+
eventId: asEventId("evt-turn-started-interrupted-settle"),
751+
provider: ProviderDriverKind.make("opencode"),
752+
createdAt: now,
753+
threadId: asThreadId("thread-1"),
754+
turnId: asTurnId("turn-interrupted-settle"),
755+
});
756+
757+
await waitForThread(
758+
harness.readModel,
759+
(thread) =>
760+
thread.session?.status === "running" &&
761+
thread.session?.activeTurnId === asTurnId("turn-interrupted-settle"),
762+
);
763+
764+
harness.emit({
765+
type: "turn.completed",
766+
eventId: asEventId("evt-turn-completed-interrupted-settle"),
767+
provider: ProviderDriverKind.make("opencode"),
768+
createdAt: "2026-01-01T00:00:01.000Z",
769+
threadId: asThreadId("thread-1"),
770+
turnId: asTurnId("turn-interrupted-settle"),
771+
status: "interrupted",
772+
});
773+
774+
const thread = await waitForThread(
775+
harness.readModel,
776+
(entry) =>
777+
entry.session?.status === "ready" &&
778+
entry.session?.activeTurnId === null &&
779+
entry.latestTurn?.state !== "running" &&
780+
entry.latestTurn?.completedAt !== null,
781+
);
782+
expect(thread.session?.status).toBe("ready");
783+
expect(thread.session?.activeTurnId).toBeNull();
784+
expect(thread.session?.lastError).toBeNull();
785+
expect(thread.latestTurn?.completedAt).not.toBeNull();
786+
});
787+
788+
it("settles a user-aborted OpenCode turn from its paired aborted + interrupted completion", async () => {
789+
const harness = await createHarness();
790+
const now = "2026-01-01T00:00:00.000Z";
791+
792+
harness.emit({
793+
type: "turn.started",
794+
eventId: asEventId("evt-turn-started-user-abort"),
795+
provider: ProviderDriverKind.make("opencode"),
796+
createdAt: now,
797+
threadId: asThreadId("thread-1"),
798+
turnId: asTurnId("turn-user-abort"),
799+
});
800+
801+
await waitForThread(
802+
harness.readModel,
803+
(thread) =>
804+
thread.session?.status === "running" &&
805+
thread.session?.activeTurnId === asTurnId("turn-user-abort"),
806+
);
807+
808+
// The user pressed stop: the orchestration interrupt request lands first
809+
// and marks the turn interrupted in the projection.
810+
await Effect.runPromise(
811+
harness.engine.dispatch({
812+
type: "thread.turn.interrupt",
813+
commandId: CommandId.make("cmd-turn-interrupt-user-abort"),
814+
threadId: asThreadId("thread-1"),
815+
turnId: asTurnId("turn-user-abort"),
816+
createdAt: "2026-01-01T00:00:01.000Z",
817+
}),
818+
);
819+
820+
// What the OpenCode adapter emits on a successful interrupt: the
821+
// informational abort marker, then the lifecycle terminal completion that
822+
// settles the projection.
823+
harness.emit({
824+
type: "turn.aborted",
825+
eventId: asEventId("evt-turn-aborted-user-abort"),
826+
provider: ProviderDriverKind.make("opencode"),
827+
createdAt: "2026-01-01T00:00:02.000Z",
828+
threadId: asThreadId("thread-1"),
829+
turnId: asTurnId("turn-user-abort"),
830+
payload: { reason: "Interrupted by user." },
831+
});
832+
harness.emit({
833+
type: "turn.completed",
834+
eventId: asEventId("evt-turn-completed-user-abort"),
835+
provider: ProviderDriverKind.make("opencode"),
836+
createdAt: "2026-01-01T00:00:03.000Z",
837+
threadId: asThreadId("thread-1"),
838+
turnId: asTurnId("turn-user-abort"),
839+
status: "interrupted",
840+
});
841+
842+
const thread = await waitForThread(
843+
harness.readModel,
844+
(entry) =>
845+
entry.session?.status === "ready" &&
846+
entry.session?.activeTurnId === null &&
847+
entry.latestTurn?.state === "interrupted" &&
848+
entry.latestTurn?.completedAt !== null,
849+
);
850+
expect(thread.session?.status).toBe("ready");
851+
expect(thread.session?.activeTurnId).toBeNull();
852+
expect(thread.latestTurn?.state).toBe("interrupted");
853+
});
854+
744855
it("accepts claude turn lifecycle when seeded thread id is a synthetic placeholder", async () => {
745856
const harness = await createHarness();
746857
const seededAt = "2026-01-01T00:00:00.000Z";

0 commit comments

Comments
 (0)