Skip to content

Commit 49d728f

Browse files
committed
fix(steering): preserve session steer call contract
1 parent 43fbbe8 commit 49d728f

4 files changed

Lines changed: 16 additions & 57 deletions

File tree

‎src/agents/embedded-agent-runner/run/attempt.queue-message.test.ts‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,7 @@ describe("embedded OpenClaw queued steering cancellation", () => {
4747
userTurnTranscriptRecorder: recorder,
4848
});
4949

50-
expect(steer).toHaveBeenCalledWith(
51-
"runtime prompt",
52-
undefined,
53-
recorder,
54-
undefined,
55-
undefined,
56-
undefined,
57-
undefined,
58-
expect.any(Function),
59-
);
50+
expect(steer).toHaveBeenCalledWith("runtime prompt", undefined, recorder);
6051
});
6152

6253
it("forwards ordered images with a queued steering message", async () => {
@@ -72,16 +63,7 @@ describe("embedded OpenClaw queued steering cancellation", () => {
7263

7364
await steerActiveSessionWithOptionalDeliveryWait(activeSession, "compare these", { images });
7465

75-
expect(steer).toHaveBeenCalledWith(
76-
"compare these",
77-
images,
78-
undefined,
79-
undefined,
80-
undefined,
81-
undefined,
82-
undefined,
83-
expect.any(Function),
84-
);
66+
expect(steer).toHaveBeenCalledWith("compare these", images);
8567
});
8668

8769
it("forwards ordered prompt facts with a queued steering message", async () => {
@@ -108,8 +90,6 @@ describe("embedded OpenClaw queued steering cancellation", () => {
10890
media,
10991
imageOrder,
11092
undefined,
111-
undefined,
112-
expect.any(Function),
11393
);
11494
});
11595

‎src/agents/embedded-agent-runner/run/attempt.queue-message.ts‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type EmbeddedAgentActiveSessionSteerTarget = {
3232
imageOrder?: PromptImageOrderEntry[],
3333
queueIdentity?: string,
3434
canInject?: () => boolean,
35-
onQueueAccepted?: (accepted: boolean) => void,
3635
): Promise<void>;
3736
subscribe(listener: (event: unknown) => void): () => void;
3837
};
@@ -56,9 +55,8 @@ function steerActiveSession(
5655
imageOrder?: PromptImageOrderEntry[],
5756
queueIdentity?: string,
5857
canInject?: () => boolean,
59-
onQueueAccepted?: (accepted: boolean) => void,
6058
): Promise<void> {
61-
if (media?.length || queueIdentity || canInject || onQueueAccepted) {
59+
if (canInject) {
6260
return activeSession.steer(
6361
text,
6462
images,
@@ -67,7 +65,16 @@ function steerActiveSession(
6765
imageOrder,
6866
queueIdentity,
6967
canInject,
70-
onQueueAccepted,
68+
);
69+
}
70+
if (media?.length || queueIdentity) {
71+
return activeSession.steer(
72+
text,
73+
images,
74+
userTurnTranscriptRecorder,
75+
media,
76+
imageOrder,
77+
queueIdentity,
7178
);
7279
}
7380
return userTurnTranscriptRecorder
@@ -331,7 +338,6 @@ async function steerAndWaitForTranscriptCommit(
331338
imageOrder,
332339
queueIdentity,
333340
() => acceptanceOpen && (canInject?.() ?? true),
334-
reportAcceptance,
335341
);
336342
void steer.then(
337343
() => {
@@ -393,14 +399,6 @@ export async function steerActiveSessionWithOptionalDeliveryWait(
393399
return;
394400
}
395401
if (options?.waitForTranscriptCommit !== true) {
396-
let acceptanceReported = false;
397-
const reportAcceptance = (accepted: boolean) => {
398-
if (acceptanceReported) {
399-
return;
400-
}
401-
acceptanceReported = true;
402-
options?.onQueueAccepted?.(accepted);
403-
};
404402
try {
405403
await steerActiveSession(
406404
activeSession,
@@ -411,11 +409,10 @@ export async function steerActiveSessionWithOptionalDeliveryWait(
411409
options?.imageOrder,
412410
options?.queueIdentity,
413411
canInject,
414-
reportAcceptance,
415412
);
416-
reportAcceptance(true);
413+
options?.onQueueAccepted?.(true);
417414
} catch (error) {
418-
reportAcceptance(false);
415+
options?.onQueueAccepted?.(false);
419416
throw error;
420417
}
421418
return;

‎src/agents/sessions/agent-session-prompting.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ export abstract class AgentSessionPrompting extends AgentSessionBase {
339339
imageOrder?: PromptImageOrderEntry[],
340340
queueIdentity?: string,
341341
canInject?: () => boolean,
342-
onQueueAccepted?: (accepted: boolean) => void,
343342
): Promise<void> {
344343
// Check for extension commands (cannot be queued)
345344
if (text.startsWith("/")) {
@@ -365,7 +364,6 @@ export abstract class AgentSessionPrompting extends AgentSessionBase {
365364
media,
366365
imageOrder,
367366
queueIdentity,
368-
onQueueAccepted,
369367
);
370368
}
371369

@@ -402,7 +400,6 @@ export abstract class AgentSessionPrompting extends AgentSessionBase {
402400
media?: MediaFact[],
403401
imageOrder?: PromptImageOrderEntry[],
404402
queueIdentity?: string,
405-
onQueueAccepted?: (accepted: boolean) => void,
406403
): Promise<void> {
407404
this.steeringMessages.push(text);
408405
this.emitQueueUpdate();
@@ -416,7 +413,6 @@ export abstract class AgentSessionPrompting extends AgentSessionBase {
416413
? attachRuntimeUserTurnTranscriptContext(promptMessage, transcriptContext)
417414
: promptMessage,
418415
);
419-
onQueueAccepted?.(true);
420416
}
421417

422418
/**

‎src/agents/sessions/sdk.test.ts‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -434,18 +434,8 @@ describe("AgentSession queued user turns", () => {
434434
target: createTestUserTurnTranscriptTarget(),
435435
});
436436
const steer = vi.spyOn(session.agent, "steer").mockImplementation(() => undefined);
437-
const onQueueAccepted = vi.fn();
438437

439-
await session.steer(
440-
"runtime group prompt",
441-
undefined,
442-
recorder,
443-
undefined,
444-
undefined,
445-
undefined,
446-
undefined,
447-
onQueueAccepted,
448-
);
438+
await session.steer("runtime group prompt", undefined, recorder);
449439

450440
const runtimeMessage = steer.mock.calls[0]?.[0];
451441
expect(runtimeMessage).toMatchObject({
@@ -463,10 +453,6 @@ describe("AgentSession queued user turns", () => {
463453
},
464454
recorder,
465455
});
466-
expect(onQueueAccepted).toHaveBeenCalledWith(true);
467-
expect(steer.mock.invocationCallOrder[0]!).toBeLessThan(
468-
onQueueAccepted.mock.invocationCallOrder[0]!,
469-
);
470456
});
471457

472458
it("carries prompt facts non-enumerably on the exact steered message", async () => {

0 commit comments

Comments
 (0)