Skip to content

Commit 1011b41

Browse files
authored
fix(ui): restore custom page and session ordering (#123530)
* fix(ui): restore interleaved sidebar ordering Render pinned sessions at their persisted slots among page entries again instead of projecting them into a separate group. This restores custom page/session interleaving regressed by #121712 while preserving drag-to-pin behavior. * test: consolidate steering authority fixtures * test: isolate CLI commentary fixture * fix: dispatch tool-bound turns normally
1 parent d4b1e96 commit 1011b41

12 files changed

Lines changed: 204 additions & 199 deletions

‎src/auto-reply/reply/agent-runner-execution-cli-commentary.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function useScriptedClaudeCliBackend() {
9292

9393
function createClaudeCliFollowupRun() {
9494
const followupRun = createFollowupRun();
95+
followupRun.run.agentId = "agent";
9596
followupRun.run.provider = "claude-cli";
9697
followupRun.run.model = "claude-opus-4-6";
9798
followupRun.run.skillsSnapshot = { prompt: "", skills: [], version: 0 };

‎src/auto-reply/reply/agent-runner-execution.test-support.ts‎

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type RunEntryDelegate = (params: RunEntryParams) => Promise<RunEntryResult>;
2424
type RunCliAgent = typeof import("../../agents/cli-runner.js").runCliAgent;
2525

2626
export const PROVIDER_AUTHENTICATION_ERROR_USER_MESSAGE = `⚠️ ${AUTH_INVALID_TOKEN_USER_TEXT}`;
27+
export { createMockReplyOperation } from "./test-helpers.js";
2728
export const PROVIDER_RATE_LIMIT_OR_QUOTA_ERROR_USER_MESSAGE =
2829
"⚠️ The model provider returned HTTP 429 before replying. This can mean rate limiting, exhausted quota, or an account balance/billing issue. Check the selected provider/model, API key, and provider billing/quota dashboard, then try again.";
2930
export const PROVIDER_INTERNAL_ERROR_USER_MESSAGE =
@@ -489,61 +490,6 @@ export function createTestUserTurnRecorder(message: PersistedUserTurnMessage) {
489490
});
490491
}
491492

492-
export function createMockReplyOperation(options?: { abortSignal?: AbortSignal }): {
493-
replyOperation: ReplyOperation;
494-
failMock: ReturnType<typeof vi.fn>;
495-
freezeAbortMock: ReturnType<typeof vi.fn>;
496-
retainFailureUntilCompleteMock: ReturnType<typeof vi.fn>;
497-
updateSessionIdMock: ReturnType<typeof vi.fn>;
498-
} {
499-
const failMock = vi.fn();
500-
const freezeAbortMock = vi.fn();
501-
const retainFailureUntilCompleteMock = vi.fn();
502-
const updateSessionIdMock = vi.fn();
503-
return {
504-
failMock,
505-
freezeAbortMock,
506-
retainFailureUntilCompleteMock,
507-
updateSessionIdMock,
508-
replyOperation: {
509-
key: "main",
510-
sessionId: "session",
511-
abortSignal: options?.abortSignal ?? new AbortController().signal,
512-
staleExpiryReason: undefined,
513-
resetTriggered: false,
514-
terminalRecovery: false,
515-
acceptedSteeredInboundAudio: false,
516-
phase: "running",
517-
result: null,
518-
startedAtMs: Date.now(),
519-
lastActivityAtMs: Date.now(),
520-
hasOwnedSessionId: vi.fn((sessionId: string) => sessionId === "session"),
521-
recordActivity: vi.fn(),
522-
setPhase: vi.fn(),
523-
markWaitingForDeferredMaintenance: vi.fn(),
524-
markDeferredMaintenanceWaitEnded: vi.fn(),
525-
markWaitingForGlobalLane: vi.fn(),
526-
markGlobalLaneWaitEnded: vi.fn(),
527-
updateSessionId: updateSessionIdMock,
528-
updateSessionKey: vi.fn(),
529-
bindToolAuthorityFingerprint: vi.fn(),
530-
bindToolAuthorityRoute: vi.fn(),
531-
attachBackend: vi.fn(),
532-
detachBackend: vi.fn(),
533-
freezeAbort: freezeAbortMock,
534-
retainFailureUntilComplete: retainFailureUntilCompleteMock,
535-
complete: vi.fn(),
536-
completeThen: vi.fn((afterClear: () => void) => afterClear()),
537-
completeWithAfterClearBarrier: vi.fn(),
538-
fail: failMock,
539-
abortByUser: vi.fn(() => true),
540-
abortForRestart: vi.fn(() => true),
541-
markTerminalRecovery: vi.fn(),
542-
markAcceptedSteeredInboundAudio: vi.fn(),
543-
},
544-
};
545-
}
546-
547493
export function requireRecord(value: unknown, label: string): Record<string, unknown> {
548494
if (typeof value !== "object" || value === null) {
549495
throw new Error(`${label} was not an object`);

‎src/auto-reply/reply/agent-runner.final-media-runreplyagent.test.ts‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import path from "node:path";
33
import { beforeEach, describe, expect, it, vi } from "vitest";
44
import type { TemplateContext } from "../templating.js";
55
import type { FollowupRun, QueueSettings } from "./queue.js";
6-
import type { ReplyOperation } from "./reply-run-registry.js";
7-
import { createMockFollowupRun, createMockTypingController } from "./test-helpers.js";
6+
import {
7+
createMockFollowupRun,
8+
createMockReplyOperation,
9+
createMockTypingController,
10+
} from "./test-helpers.js";
811

912
const executeAgentTurnMock = vi.fn();
1013
const resolveOutboundAttachmentFromUrlMock = vi.fn();
@@ -109,21 +112,6 @@ type AgentTurnExecutionResult = Awaited<
109112
ReturnType<typeof import("./agent-runner-execution.js").executeAgentTurn>
110113
>;
111114

112-
function createReplyOperation(): ReplyOperation {
113-
return {
114-
result: undefined,
115-
startedAtMs: Date.now(),
116-
lastActivityAtMs: Date.now(),
117-
recordActivity: vi.fn(),
118-
setPhase: vi.fn(),
119-
bindToolAuthorityFingerprint: vi.fn(),
120-
freezeAbort: vi.fn(),
121-
fail: vi.fn(),
122-
complete: vi.fn(),
123-
completeThen: vi.fn(),
124-
} as unknown as ReplyOperation;
125-
}
126-
127115
function makeRunReplyAgentParams(
128116
overrides: Partial<Parameters<typeof runReplyAgent>[0]> = {},
129117
): Parameters<typeof runReplyAgent>[0] {
@@ -163,7 +151,7 @@ function makeRunReplyAgentParams(
163151
resolvedBlockStreamingBreak: "message_end",
164152
shouldInjectGroupIntro: false,
165153
typingMode: "instant",
166-
replyOperation: createReplyOperation(),
154+
replyOperation: createMockReplyOperation().replyOperation,
167155
...overrides,
168156
};
169157
}

‎src/auto-reply/reply/agent-runner.media-paths.test.ts‎

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import type { EmbeddedAgentQueueMessageOutcome } from "../../agents/embedded-age
77
import type { OpenClawConfig } from "../../config/types.openclaw.js";
88
import type { TemplateContext } from "../templating.js";
99
import type { FollowupRun, QueueSettings } from "./queue.js";
10+
import { createReplyOperation as createRegisteredReplyOperation } from "./reply-run-registry.js";
11+
import { resolveFollowupRunToolAuthorityFingerprint } from "./reply-tool-authority.js";
1012
import {
11-
createReplyOperation as createRegisteredReplyOperation,
12-
type ReplyOperation,
13-
} from "./reply-run-registry.js";
14-
import { createMockFollowupRun, createMockTypingController } from "./test-helpers.js";
13+
createMockFollowupRun,
14+
createMockReplyOperation,
15+
createMockTypingController,
16+
} from "./test-helpers.js";
1517

1618
const runEmbeddedAgentMock = vi.fn();
1719
const runWithModelFallbackMock = vi.fn();
@@ -51,12 +53,6 @@ const resolveOutboundAttachmentFromUrlMock = vi.fn();
5153
const createReplyMediaContextRuntimeMock = vi.fn();
5254
const EXPECTED_STEER_QUEUE_IDENTITY =
5355
"channel-user:v1:6f3f31084a7a2a6ff17176c0c16682e64d9f21301f64ff7e5bf1173b54fadc33";
54-
const TEST_TOOL_AUTHORITY_FINGERPRINT = "test-tool-authority";
55-
56-
vi.mock("./reply-tool-authority.js", () => ({
57-
resolveFollowupRunToolAuthorityFingerprint: () => "test-tool-authority",
58-
}));
59-
6056
vi.mock("../../agents/model-fallback-runner.js", () => ({
6157
runWithModelFallback: (params: {
6258
provider: string;
@@ -294,24 +290,6 @@ vi.mock("./reply-media-paths.runtime.js", async (importOriginal) => {
294290

295291
const { runReplyAgent } = await import("./agent-runner.js");
296292

297-
function createReplyOperation(): ReplyOperation {
298-
return {
299-
result: undefined,
300-
toolAuthorityFingerprint: TEST_TOOL_AUTHORITY_FINGERPRINT,
301-
abortSignal: new AbortController().signal,
302-
startedAtMs: Date.now(),
303-
lastActivityAtMs: Date.now(),
304-
recordActivity: vi.fn(),
305-
setPhase: vi.fn(),
306-
bindToolAuthorityFingerprint: vi.fn(),
307-
bindToolAuthorityRoute: vi.fn(),
308-
freezeAbort: vi.fn(),
309-
fail: vi.fn(),
310-
complete: vi.fn(),
311-
completeThen: vi.fn(),
312-
} as unknown as ReplyOperation;
313-
}
314-
315293
function makeRunReplyAgentParams(
316294
overrides: Partial<Parameters<typeof runReplyAgent>[0]> & {
317295
provider?: string;
@@ -322,18 +300,27 @@ function makeRunReplyAgentParams(
322300
const provider = overrides.provider ?? "whatsapp";
323301
const prompt = overrides.prompt ?? "generate chart";
324302
const workspaceDir = overrides.workspaceDir ?? "/tmp/workspace";
325-
326-
return {
327-
commandBody: prompt,
328-
followupRun: createMockFollowupRun({
303+
const followupRun =
304+
overrides.followupRun ??
305+
createMockFollowupRun({
329306
prompt,
330307
run: {
331308
agentId: "main",
332309
agentDir: "/tmp/agent",
333310
messageProvider: provider,
334311
workspaceDir,
335312
},
336-
}) as unknown as FollowupRun,
313+
});
314+
const replyOperation = overrides.replyOperation ?? createMockReplyOperation().replyOperation;
315+
if (overrides.isActive === true && !replyOperation.toolAuthorityFingerprint) {
316+
replyOperation.bindToolAuthorityFingerprint(
317+
resolveFollowupRunToolAuthorityFingerprint(followupRun),
318+
);
319+
}
320+
321+
return {
322+
commandBody: prompt,
323+
followupRun,
337324
queueKey: "main",
338325
resolvedQueue: { mode: "interrupt" } as QueueSettings,
339326
shouldSteer: false,
@@ -355,7 +342,7 @@ function makeRunReplyAgentParams(
355342
resolvedBlockStreamingBreak: "message_end",
356343
shouldInjectGroupIntro: false,
357344
typingMode: "instant",
358-
replyOperation: createReplyOperation(),
345+
replyOperation,
359346
...overrides,
360347
};
361348
}
@@ -495,7 +482,7 @@ describe("runReplyAgent media path normalization", () => {
495482
queueIdentity: EXPECTED_STEER_QUEUE_IDENTITY,
496483
onQueueAccepted: parkedSteerAcceptedMock,
497484
taskSuggestionDeliveryMode: "gateway",
498-
toolAuthorityFingerprint: TEST_TOOL_AUTHORITY_FINGERPRINT,
485+
toolAuthorityFingerprint: resolveFollowupRunToolAuthorityFingerprint(followupRun),
499486
},
500487
);
501488
expect(enqueueFollowupRunMock).not.toHaveBeenCalled();
@@ -544,7 +531,7 @@ describe("runReplyAgent media path normalization", () => {
544531
images,
545532
media: followupRun.media,
546533
taskSuggestionDeliveryMode: undefined,
547-
toolAuthorityFingerprint: TEST_TOOL_AUTHORITY_FINGERPRINT,
534+
toolAuthorityFingerprint: resolveFollowupRunToolAuthorityFingerprint(followupRun),
548535
},
549536
);
550537
expect(enqueueFollowupRunMock).not.toHaveBeenCalled();
@@ -585,13 +572,17 @@ describe("runReplyAgent media path normalization", () => {
585572
});
586573

587574
it("latches audio only after the active reply operation accepts the steer", async () => {
575+
const followupRun = {
576+
...createMockFollowupRun({ prompt: "summarize the audio" }),
577+
currentInboundAudio: true,
578+
} as unknown as FollowupRun;
588579
const operation = createRegisteredReplyOperation({
589580
sessionKey: "agent:main:whatsapp:direct:chat-1",
590581
sessionId: "session",
591582
resetTriggered: false,
592583
});
593584
operation.setPhase("running");
594-
operation.bindToolAuthorityFingerprint(TEST_TOOL_AUTHORITY_FINGERPRINT);
585+
operation.bindToolAuthorityFingerprint(resolveFollowupRunToolAuthorityFingerprint(followupRun));
595586
expect(operation.acceptedSteeredInboundAudio).toBe(false);
596587
queueEmbeddedAgentMessageWithOutcomeAsyncMock.mockImplementation(async (sessionId: string) => ({
597588
queued: true,
@@ -602,16 +593,13 @@ describe("runReplyAgent media path normalization", () => {
602593

603594
await runReplyAgent(
604595
makeRunReplyAgentParams({
596+
followupRun,
605597
replyOperation: operation,
606598
sessionKey: "agent:main:whatsapp:direct:chat-1",
607599
resolvedQueue: { mode: "steer" } as QueueSettings,
608600
shouldSteer: true,
609601
shouldFollowup: true,
610602
isActive: true,
611-
followupRun: {
612-
...createMockFollowupRun({ prompt: "summarize the audio" }),
613-
currentInboundAudio: true,
614-
} as unknown as FollowupRun,
615603
}),
616604
);
617605

@@ -627,7 +615,7 @@ describe("runReplyAgent media path normalization", () => {
627615
queueIdentity: EXPECTED_STEER_QUEUE_IDENTITY,
628616
onQueueAccepted: parkedSteerAcceptedMock,
629617
taskSuggestionDeliveryMode: undefined,
630-
toolAuthorityFingerprint: TEST_TOOL_AUTHORITY_FINGERPRINT,
618+
toolAuthorityFingerprint: operation.toolAuthorityFingerprint,
631619
},
632620
);
633621
expect(enqueueFollowupRunMock).not.toHaveBeenCalled();

‎src/auto-reply/reply/test-helpers.ts‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,80 @@
11
/** Shared test fixtures for reply queue and typing-controller tests. */
22
import { vi } from "vitest";
33
import type { FollowupRun } from "./queue.js";
4+
import type { ReplyOperation } from "./reply-run-registry.js";
45
import type { TypingController } from "./typing.js";
56

7+
/** Creates a stateful reply-operation double without registering global run state. */
8+
export function createMockReplyOperation(
9+
overrides: {
10+
abortSignal?: AbortSignal;
11+
key?: string;
12+
sessionId?: string;
13+
toolAuthorityFingerprint?: string;
14+
} = {},
15+
) {
16+
const failMock = vi.fn();
17+
const freezeAbortMock = vi.fn();
18+
const retainFailureUntilCompleteMock = vi.fn();
19+
const updateSessionIdMock = vi.fn();
20+
const sessionId = overrides.sessionId ?? "session";
21+
let toolAuthorityFingerprint = overrides.toolAuthorityFingerprint;
22+
let toolAuthorityRoute: ReplyOperation["toolAuthorityRoute"];
23+
const replyOperation: ReplyOperation = {
24+
key: overrides.key ?? "main",
25+
sessionId,
26+
abortSignal: overrides.abortSignal ?? new AbortController().signal,
27+
resetTriggered: false,
28+
terminalRecovery: false,
29+
acceptedSteeredInboundAudio: false,
30+
get toolAuthorityFingerprint() {
31+
return toolAuthorityFingerprint;
32+
},
33+
get toolAuthorityRoute() {
34+
return toolAuthorityRoute;
35+
},
36+
phase: "running",
37+
result: null,
38+
staleExpiryReason: undefined,
39+
startedAtMs: Date.now(),
40+
lastActivityAtMs: Date.now(),
41+
hasOwnedSessionId: vi.fn((candidate: string) => candidate === sessionId),
42+
recordActivity: vi.fn(),
43+
setPhase: vi.fn(),
44+
markWaitingForDeferredMaintenance: vi.fn(),
45+
markDeferredMaintenanceWaitEnded: vi.fn(),
46+
markWaitingForGlobalLane: vi.fn(),
47+
markGlobalLaneWaitEnded: vi.fn(),
48+
markTerminalRecovery: vi.fn(),
49+
markAcceptedSteeredInboundAudio: vi.fn(),
50+
bindToolAuthorityFingerprint: vi.fn((fingerprint) => {
51+
toolAuthorityFingerprint = fingerprint;
52+
}),
53+
bindToolAuthorityRoute: vi.fn((route) => {
54+
toolAuthorityRoute = route;
55+
}),
56+
updateSessionId: updateSessionIdMock,
57+
updateSessionKey: vi.fn(),
58+
attachBackend: vi.fn(),
59+
detachBackend: vi.fn(),
60+
freezeAbort: freezeAbortMock,
61+
retainFailureUntilComplete: retainFailureUntilCompleteMock,
62+
complete: vi.fn(),
63+
completeThen: vi.fn((afterClear) => afterClear()),
64+
completeWithAfterClearBarrier: vi.fn(),
65+
fail: failMock,
66+
abortByUser: vi.fn(() => true),
67+
abortForRestart: vi.fn(() => true),
68+
};
69+
return {
70+
replyOperation,
71+
failMock,
72+
freezeAbortMock,
73+
retainFailureUntilCompleteMock,
74+
updateSessionIdMock,
75+
};
76+
}
77+
678
/** Creates a typed mock typing controller with optional method overrides. */
779
export function createMockTypingController(
880
overrides: Partial<TypingController> = {},
@@ -31,7 +103,7 @@ export function createMockFollowupRun(
31103
enqueuedAt: Date.now(),
32104
originatingTo: "channel:C1",
33105
run: {
34-
agentId: "agent",
106+
agentId: "main",
35107
agentDir: "/tmp/agent",
36108
sessionId: "session",
37109
sessionKey: "main",

‎src/gateway/server-methods/chat-send-message-injection.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function createChatSendMessageInjectionStarter(params: {
4242
const { cfg, entry } = params.session;
4343
const { ctx, isInternalTextSlashCommandTurn, replyOptionImages, replyOptionMedia } = params.turn;
4444
return (): ReplyMessageInjectionAttempt | undefined => {
45-
if (!params.target || isInternalTextSlashCommandTurn) {
45+
if (!params.target || isInternalTextSlashCommandTurn || toolBindings !== undefined) {
4646
return undefined;
4747
}
4848
const { debounceMs } = resolveQueueSettings({

0 commit comments

Comments
 (0)