-
Notifications
You must be signed in to change notification settings - Fork 0
Handle Codex steer requests during turn finalization #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { acceptCodexSteer } from "../codex-steer.js"; | ||
| import type { QueuedMessage, QueuedMessageInput } from "../session-queue.js"; | ||
|
|
||
| function queued(id = "queued-1"): QueuedMessage { | ||
| return { | ||
| id, | ||
| text: "follow up", | ||
| visibleText: "follow up", | ||
| provider: "codex", | ||
| model: "gpt-5", | ||
| mode: "default", | ||
| attachmentIds: [], | ||
| createdAt: "2026-08-06T00:00:00.000Z", | ||
| }; | ||
| } | ||
|
|
||
| function options(outcome: "steered" | "turn-ended", queuedMessageId?: string) { | ||
| const calls = { enqueued: 0, removed: 0 }; | ||
| const item = queued(queuedMessageId); | ||
| return { | ||
| calls, | ||
| input: { | ||
| queuedMessageId, | ||
| steer: async () => outcome, | ||
| getQueuedMessage: async () => item, | ||
| removeQueuedMessage: async () => { calls.removed += 1; }, | ||
| buildFollowUp: async (): Promise<QueuedMessageInput> => item, | ||
| enqueueFollowUp: async () => { calls.enqueued += 1; return item; }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| test("accepted native steer does not enqueue and removes a promoted item once", async () => { | ||
| const fixture = options("steered", "queued-1"); | ||
| assert.deepEqual(await acceptCodexSteer(fixture.input), { disposition: "steered" }); | ||
| assert.deepEqual(fixture.calls, { enqueued: 0, removed: 1 }); | ||
| }); | ||
|
|
||
| test("turn-finalization race preserves typed text as a queued follow-up", async () => { | ||
| const fixture = options("turn-ended"); | ||
| const result = await acceptCodexSteer(fixture.input); | ||
| assert.equal(result.disposition, "queued"); | ||
| assert.deepEqual(fixture.calls, { enqueued: 1, removed: 0 }); | ||
| }); | ||
|
|
||
| test("turn-finalization race leaves a promoted queue item exactly once", async () => { | ||
| const fixture = options("turn-ended", "queued-1"); | ||
| const result = await acceptCodexSteer(fixture.input); | ||
| assert.equal(result.disposition, "queued"); | ||
| assert.deepEqual(fixture.calls, { enqueued: 0, removed: 0 }); | ||
| }); | ||
|
|
||
| test("genuine native steer failure does not enqueue or remove queue state", async () => { | ||
| const fixture = options("steered"); | ||
| fixture.input.steer = async () => { throw new Error("protocol failure"); }; | ||
| await assert.rejects(() => acceptCodexSteer(fixture.input), /protocol failure/); | ||
| assert.deepEqual(fixture.calls, { enqueued: 0, removed: 0 }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { QueuedMessage, QueuedMessageInput } from "./session-queue.js"; | ||
|
|
||
| export type CodexSteerResult = | ||
| | { disposition: "steered" } | ||
| | { disposition: "queued"; message?: QueuedMessage }; | ||
|
|
||
| interface AcceptCodexSteerOptions { | ||
| queuedMessageId?: string; | ||
| steer: () => Promise<"steered" | "turn-ended">; | ||
| getQueuedMessage: (id: string) => Promise<QueuedMessage | undefined>; | ||
| removeQueuedMessage: (id: string) => Promise<void>; | ||
| buildFollowUp: () => Promise<QueuedMessageInput>; | ||
| enqueueFollowUp: (input: QueuedMessageInput) => Promise<QueuedMessage>; | ||
| } | ||
|
|
||
| /* | ||
| * Transfer ownership of a Codex composer submission exactly once. A terminal | ||
| * event can win while turn/steer is in flight; in that case a typed message is | ||
| * made durable, while a promoted queue item simply remains owned by the queue. | ||
| */ | ||
| export async function acceptCodexSteer( | ||
| options: AcceptCodexSteerOptions | ||
| ): Promise<CodexSteerResult> { | ||
| const outcome = await options.steer(); | ||
| if (outcome === "steered") { | ||
| if (options.queuedMessageId) { | ||
| await options.removeQueuedMessage(options.queuedMessageId); | ||
|
Comment on lines
+25
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
| return { disposition: "steered" }; | ||
| } | ||
|
|
||
| if (options.queuedMessageId) { | ||
| return { | ||
| disposition: "queued", | ||
| message: await options.getQueuedMessage(options.queuedMessageId), | ||
| }; | ||
| } | ||
|
|
||
| const queued = await options.enqueueFollowUp(await options.buildFollowUp()); | ||
| return { disposition: "queued", message: queued }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this view is opened during an already-running Codex turn, or when the server starts a queued turn headlessly, the component receives activity through the runtime/event pollers rather than its own SSE, so
nativeSteerAvailableRefnever becomes true. Cmd/Ctrl+Enter therefore callshandleEnqueue()here and silently converts the requested steer into a later follow-up; with an empty composer and a queued item, it does nothing at all. The server already determines whetherturn/steerraced finalization, so the client should still send the steer request for these active polled turns.Useful? React with 👍 / 👎.