Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Keep accepted queue steers pending until the turn ends

Cursor Agentd1ca49e97078
diff --git a/apps/native/lib/prompt-queue-steer.test.ts b/apps/native/lib/prompt-queue-steer.test.ts
index b3b018e9..93d39317 100644
--- a/apps/native/lib/prompt-queue-steer.test.ts
+++ b/apps/native/lib/prompt-queue-steer.test.ts
@@ -79,16 +79,41 @@ describe("queue force steer", () => {
f.steerer.finish(1);
});
- it("surfaces an unconfirmed cancellation without losing the queue", async () => {
+ it("keeps an accepted steer pending when stream teardown exceeds the timer", async () => {
const f = fixture(5);
f.steerer.ready(1);
f.steerer.steer(1, 3, async () => {});
+ await Promise.resolve();
+ await new Promise(resolve => setTimeout(resolve, 20));
+ assert.equal(f.status().error, undefined);
+ assert.equal(f.status().pending, 3);
+ assert.deepEqual(f.queue().map(x => x.id), [3, 1, 2]);
+ f.steerer.finish(1);
+ });
+
+ it("surfaces an unconfirmed cancellation without losing the queue", async () => {
+ const f = fixture(5);
+ f.steerer.ready(1);
+ f.steerer.steer(1, 3, () => new Promise(() => {}));
await new Promise(resolve => setTimeout(resolve, 20));
assert.match(f.status().error!, /Could not confirm/);
assert.deepEqual(f.queue().map(x => x.id), [3, 1, 2]);
f.steerer.finish(1);
});
+ it("ignores repeated steer after the cancel request is accepted", async () => {
+ const f = fixture();
+ f.steerer.ready(1);
+ let calls = 0;
+ f.steerer.steer(1, 3, async () => { calls++; });
+ await Promise.resolve();
+ f.steerer.steer(1, 2, async () => { calls++; });
+ assert.equal(calls, 1);
+ assert.equal(f.status().pending, 3);
+ assert.equal(f.status().error, undefined);
+ f.steerer.finish(1);
+ });
+
it("ignores stale selections and leaves missing/head priorities unchanged", () => {
const f = fixture();
f.steerer.ready(1);
diff --git a/apps/native/lib/prompt-queue-steer.ts b/apps/native/lib/prompt-queue-steer.ts
index aaa9becf..27acd55e 100644
--- a/apps/native/lib/prompt-queue-steer.ts
+++ b/apps/native/lib/prompt-queue-steer.ts
@@ -8,7 +8,7 @@ export function steerOrInterrupt(next: { id: number } | undefined, running: bool
}
export type SteerStatus = { pending?: number; error?: string };
-type Turn = { ready: boolean; selected?: number; cancel?: () => Promise<void>; sent: boolean; attempt: number; timer?: ReturnType<typeof setTimeout> };
+type Turn = { ready: boolean; selected?: number; cancel?: () => Promise<void>; sent: boolean; accepted: boolean; attempt: number; timer?: ReturnType<typeof setTimeout> };
/** A turn-scoped guard: never send a deferred cancellation into the next turn. */
export function createQueueSteerer(options: {
@@ -23,14 +23,23 @@ export function createQueueSteerer(options: {
turn.sent = true;
const attempt = turn.attempt;
try {
- void turn.cancel().catch(() => failed(chat, turn, attempt));
+ void turn.cancel().then(
+ () => accepted(chat, turn, attempt),
+ () => failed(chat, turn, attempt),
+ );
} catch {
failed(chat, turn, attempt);
}
};
- const failed = (chat: number, turn: Turn, attempt: number) => {
+ const accepted = (chat: number, turn: Turn, attempt: number) => {
if (turns.get(chat) !== turn || turn.attempt !== attempt) return;
clearTimeout(turn.timer);
+ turn.accepted = true;
+ if (turn.selected !== undefined) options.status(chat, { pending: turn.selected });
+ };
+ const failed = (chat: number, turn: Turn, attempt: number) => {
+ if (turns.get(chat) !== turn || turn.attempt !== attempt || turn.accepted) return;
+ clearTimeout(turn.timer);
turn.attempt += 1;
turn.selected = undefined;
turn.cancel = undefined;
@@ -40,7 +49,7 @@ export function createQueueSteerer(options: {
return {
begin(chat: number) {
clearTimeout(turns.get(chat)?.timer);
- turns.set(chat, { ready: false, sent: false, attempt: 0 });
+ turns.set(chat, { ready: false, sent: false, accepted: false, attempt: 0 });
options.status(chat, {});
},
ready(chat: number) {
@@ -64,7 +73,9 @@ export function createQueueSteerer(options: {
options.setQueue(chat, prioritizeQueuedPrompt(queue, item));
options.status(chat, { pending: item });
const attempt = ++turn.attempt;
- turn.timer = setTimeout(() => failed(chat, turn, attempt), options.timeoutMs ?? 10_000);
+ turn.timer = setTimeout(() => {
+ if (!turn.accepted) failed(chat, turn, attempt);
+ }, options.timeoutMs ?? 10_000);
dispatch(chat, turn);
},
};