Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: Stop clears a message stuck on acceptance

ogsamrata6260c5b6520
diff --git a/apps/app/src/app/lib/opencode-interruption.ts b/apps/app/src/app/lib/opencode-interruption.ts
index 9bc59c42..5b12b6a2 100644
--- a/apps/app/src/app/lib/opencode-interruption.ts
+++ b/apps/app/src/app/lib/opencode-interruption.ts
@@ -1,5 +1,5 @@
import type { Client } from "../types";
-import { isPromptAdmissionUnknown, promptHeldForSandbox, stopHeldSend, unwrap } from "./opencode";
+import { promptHeldForSandbox, stopHeldSend, unwrap } from "./opencode";
type Submission = {
messageID?: string;
@@ -71,7 +71,7 @@ export function interruptSessionTurn(
client: Client,
sessionID: string,
directory?: string,
- options: { timeoutMs?: number; admissionUnknown?: boolean; onStopped?: () => void } = {},
+ options: { timeoutMs?: number; onStopped?: () => void } = {},
): Promise<void> {
const turn = turnFor(baseUrl, sessionID);
// Share the cancellation request, not permission for intervening sends to
@@ -92,7 +92,7 @@ export function interruptSessionTurn(
controller.signal.addEventListener("abort", () => reject(controller.signal.reason), { once: true });
});
const interruption = Promise.race([
- stopForegroundTree(client, sessionID, directory, pending, controller.signal, options.admissionUnknown === true),
+ stopForegroundTree(client, sessionID, directory, pending, controller.signal),
deadline,
]).then(() => {
// Reconcile the old admission before releasing waiting successor sends.
@@ -118,7 +118,6 @@ async function stopForegroundTree(
directory: string | undefined,
pending: readonly Submission[],
signal: AbortSignal,
- admissionUnknown: boolean,
) {
const options = { signal };
const children = async (sessionID: string) => {
@@ -179,7 +178,6 @@ async function stopForegroundTree(
}
};
const waiting = new Set(pending);
- const reconciled = new Set<Submission>();
while (waiting.size > 0) {
signal.throwIfAborted();
for (const submission of waiting) if (submission.settled) waiting.delete(submission);
@@ -200,7 +198,6 @@ async function stopForegroundTree(
// message or an idle snapshot on its own. Reject only the UI wait;
// never replay the request, and still stop/verify the child tree below.
if (admitted && terminal) {
- reconciled.add(submission);
submission.cancel();
waiting.delete(submission);
}
@@ -211,11 +208,9 @@ async function stopForegroundTree(
}
signal.throwIfAborted();
await stop(rootID, before);
- // A lost admission response is not proof that the old POST cannot arrive
- // later. Do not claim a clean handoff or replay that prompt.
- if (admissionUnknown || pending.some((submission) => !reconciled.has(submission) && isPromptAdmissionUnknown(submission.error))) {
- throw new Error("The previous message's acceptance is still unknown. Check acceptance, then retry Stop.");
- }
+ // An unknown admission no longer blocks: once every stopped turn is idle the
+ // user's Stop is confirmed and the hold clears. The old prompt is never resent;
+ // if its POST still lands later it shows as a new run the user can stop again.
while (true) {
signal.throwIfAborted();
const statuses = unwrap(await client.session.status({ directory }, options));
diff --git a/apps/app/src/react-app/domains/session/surface/queued-drain-machine.ts b/apps/app/src/react-app/domains/session/surface/queued-drain-machine.ts
index 94b2215d..641f2ade 100644
--- a/apps/app/src/react-app/domains/session/surface/queued-drain-machine.ts
+++ b/apps/app/src/react-app/domains/session/surface/queued-drain-machine.ts
@@ -108,7 +108,7 @@ export function reduceQueuedDrain(state: QueuedDrainState, event: QueuedDrainEve
// A replacement may already hold the send slot while awaiting Stop.
// Keep that claim, but discard activity belonging to its predecessor.
if (phase.kind === "sending") return { ...state, phase: { ...phase, busySeen: false } };
- if (phase.kind === "admission_unknown") return state;
+ // A confirmed Stop settles an unknown admission too: nothing is resent.
return { ...INITIAL_QUEUED_DRAIN_STATE, lastResolution: state.lastResolution };
case "send_started": {
if (phase.kind !== "ready") {
diff --git a/apps/app/src/react-app/domains/session/surface/session-surface.tsx b/apps/app/src/react-app/domains/session/surface/session-surface.tsx
index 95e13879..d9d9d051 100644
--- a/apps/app/src/react-app/domains/session/surface/session-surface.tsx
+++ b/apps/app/src/react-app/domains/session/surface/session-surface.tsx
@@ -2575,7 +2575,6 @@ export function SessionSurface(props: SessionSurfaceProps) {
try {
await interruptSessionTurn(props.opencodeBaseUrl, opencodeClient, props.sessionId,
props.workspaceRoot.trim() || undefined, {
- admissionUnknown: phase.kind === "admission_unknown",
onStopped: () => dispatchQueuedDrain(props.sessionId, { type: "stop_confirmed" }),
});
} catch (error) {
diff --git a/apps/app/tests/opencode-session-native.test.ts b/apps/app/tests/opencode-session-native.test.ts
index c349aacb..d4849d88 100644
--- a/apps/app/tests/opencode-session-native.test.ts
+++ b/apps/app/tests/opencode-session-native.test.ts
@@ -590,9 +590,10 @@ describe("native Stop and follow-up handoff", () => {
});
});
- test("unknown admission stays fenced even after the visible run stops", async () => {
+ test("a confirmed stop clears an unknown admission without resending it", async () => {
const root = { ...session, id: "ses_unknown_stop" };
let sends = 0;
+ let stopped = false;
await withSessionFetch((request) => {
const path = new URL(request.url).pathname;
if (path.endsWith(`/session/${root.id}`)) return Response.json(root);
@@ -602,13 +603,13 @@ describe("native Stop and follow-up handoff", () => {
throw new Error(`Unexpected request: ${request.method} ${path}`);
}, async (requests) => {
const client = createClient(endpoint.opencodeBaseUrl, root.directory);
- await expect(interruptSessionTurn(endpoint.opencodeBaseUrl, client, root.id, root.directory, { admissionUnknown: true }))
- .rejects.toThrow("acceptance is still unknown");
- await expect(submitAfterInterruption(endpoint.opencodeBaseUrl, root.id, async () => { sends += 1; }))
- .rejects.toThrow("acceptance is still unknown");
- expect(sends).toBe(0);
+ await interruptSessionTurn(endpoint.opencodeBaseUrl, client, root.id, root.directory, { onStopped: () => { stopped = true; } });
+ expect(stopped).toBe(true);
+ expect(sessionNeedsStop(endpoint.opencodeBaseUrl, root.id)).toBe(false);
+ // Only the two aborts; the unknown prompt is never replayed.
expect(requests.filter((request) => request.method === "POST")).toHaveLength(2);
- expect(sessionNeedsStop(endpoint.opencodeBaseUrl, root.id)).toBe(true);
+ await submitAfterInterruption(endpoint.opencodeBaseUrl, root.id, async () => { sends += 1; });
+ expect(sends).toBe(1);
});
});
diff --git a/apps/app/tests/queued-drain-admission-wedge.test.ts b/apps/app/tests/queued-drain-admission-wedge.test.ts
index d92aebae..42d9cede 100644
--- a/apps/app/tests/queued-drain-admission-wedge.test.ts
+++ b/apps/app/tests/queued-drain-admission-wedge.test.ts
@@ -300,3 +300,12 @@ test("blocked and cancelled sends classify as needs_input and rejected without w
const running = reduceQueuedDrain(live, { type: "busy_observed" });
expect(reduceQueuedDrain(running, { type: "queue_cleared" })).toBe(running);
});
+
+test("a confirmed stop releases an unknown admission", () => {
+ let state = reduceQueuedDrain(INITIAL_QUEUED_DRAIN_STATE, { type: "send_started", itemId: "lost" });
+ state = reduceQueuedDrain(state, { type: "send_unknown", itemId: "lost", messageID: "msg_lost", at: 1 });
+ expect(state.phase.kind).toBe("admission_unknown");
+ expect(reduceQueuedDrain(state, { type: "queue_cleared" })).toBe(state);
+ state = reduceQueuedDrain(state, { type: "stop_confirmed" });
+ expect(canAdmitNextQueuedItem(state)).toBe(true);
+});