Skip to content

Commit 4ba52f8

Browse files
committed
CR: error handling
1 parent fc7f667 commit 4ba52f8

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/AcpExtensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export type SessionSteerRequest = {
9090
}
9191

9292
export type SessionSteeringResponse = {
93-
outcome: "injected" | "startedNewTurn";
93+
outcome: "injected" | "startedNewTurn" | "failed";
9494
}
9595

9696
export type SessionSteeringExtRequest = {

src/CodexAcpServer.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,13 +888,20 @@ export class CodexAcpServer {
888888
* check guards against deleting a queue a later request has since reused).
889889
*
890890
* @param params The target session id and the prompt to steer with.
891-
* @returns Whether the prompt joined the active turn ("injected") or started
892-
* a new one ("startedNewTurn"); see {@link performSteeringRequest}.
891+
* @returns Whether the prompt joined the active turn ("injected"), started a
892+
* new one ("startedNewTurn"), or could not be applied ("failed"); see
893+
* {@link performSteeringRequest}.
893894
*/
894895
async executeOrQueueSteeringRequest(params: SessionSteerRequest): Promise<SessionSteeringResponse> {
895896
const queue = this.getSteeringQueue(params.sessionId);
896897
try {
897898
return await queue.enqueue(params);
899+
} catch (error) {
900+
if (error instanceof RequestError) {
901+
throw error;
902+
}
903+
logger.error(`Steering request for session ${params.sessionId} failed`, error);
904+
return {outcome: "failed"};
898905
} finally {
899906
if (queue.isIdle && this.steeringQueues.get(params.sessionId) === queue) {
900907
this.steeringQueues.delete(params.sessionId);

src/__tests__/CodexACPAgent/steer-events.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ describe('_session/steering', () => {
192192
});
193193
});
194194

195+
it('reports failed instead of throwing when steering hits an unexpected error', async () => {
196+
const mockFixture = createCodexMockTestFixture();
197+
vi.spyOn(mockFixture.getCodexAcpAgent(), "getSessionState").mockImplementation(() => {
198+
throw new Error("unexpected boom");
199+
});
200+
201+
await expect(mockFixture.getCodexAcpAgent().extMethod(SESSION_STEERING_METHOD, {
202+
sessionId: "session-id",
203+
prompt: [{type: "text", text: "keep the agent alive"}],
204+
})).resolves.toEqual({outcome: "failed"});
205+
});
206+
195207
it('rejects malformed steer params', async () => {
196208
const mockFixture = createCodexMockTestFixture();
197209

0 commit comments

Comments
 (0)