Skip to content

Commit a1fe611

Browse files
committed
fix(ui): replace startup hourglasses with capacity-aware rings
Show one activity ring from accepted startup through execution. Pause only for exact command-lane or Swarm capacity waits, resume on admission, and preserve terminal and hidden-run ownership. Fixes #133464.
1 parent 52eed80 commit a1fe611

38 files changed

Lines changed: 777 additions & 177 deletions

‎docs/web/control-ui.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ Chat error banners, including cloud runner failures, show short messages in full
591591
- Live `chat` events are delivery state, while `chat.history` is rebuilt from the durable session transcript. After tool-final events the Control UI reloads history and merges only a small optimistic tail; the transcript boundary is documented in [WebChat](/web/webchat). After an in-place `/clear` or `/reset`, fresh turns keep their user-before-reply order across live updates, incremental history catch-up, and reload.
592592
- `chat.inject` appends an assistant note to the session transcript and broadcasts a `chat` event for UI-only updates (no agent run, no channel delivery).
593593
- The sidebar lists every loaded active session by agent section and pinned/channel/work/custom/Chats buckets with a single New Session action that opens the draft dialog. Opening a visible row moves only the highlight. Sessions can be dropped onto Pinned to pin them, or onto a custom group or Chats to move them; custom groups are collapsible and drag-reorderable, group names and order sync through the gateway, and collapsed state stays in the browser. A new dashboard session asynchronously gets a concise generated title from its first non-command message; explicit names and authenticated sender identity remain separate, so account names are never used as generated titles. When New Session creates a worktree without an explicit worktree name, OpenClaw also uses the session label or generated title for its branch name, falling back to a readable crustacean-themed name. Set `agents.defaults.utilityModel` (or `agents.entries.*.utilityModel`) to route this separate model call to a lower-cost model; if that distinct model fails, title generation retries once with the primary model. Expanding another agent section browses that agent's sessions without leaving the open chat.
594+
- Session activity uses a ring as soon as work is accepted. It spins during startup and execution, pauses while waiting for a scheduler concurrency slot, and resumes when a slot is granted. With reduced motion enabled, rings remain still.
594595
- Thread search lives in the command palette (⌘K, or the search button in the top-left control cluster): typing a query follows a bounded number of matching pages across agents, filters internal child/cron rows, and lists visible matches next to navigation commands. The Threads page keeps the exhaustive searchable list with filters.
595596
- Each sidebar row keeps direct pin access plus a full context menu for unread state, rename, fork, grouping, archive, and delete. Cmd/Ctrl-click opens the session in a new browser tab. Multi-selected rows (Alt/Option-click, Shift-click for ranges) get a batch menu covering unread state, grouping, archive, and delete; batch Archive reports per-session failures while archiving eligible rows, whereas batch Delete keeps its separate idle-or-already-archived eligibility. Archive stays disabled for agent main sessions (including `global` in global scope) and the `unknown` sentinel. For any other session, including one with active work, the Gateway stops and fully drains that session's work before archiving it. The selected archived session stays open with an archived notice and **Unarchive** action; deleting the selected session switches Chat back to that agent's main session.
596597
- In the macOS app, the OpenClaw mark uses the otherwise-empty native titlebar strip next to the window controls instead of consuming a sidebar row.

‎src/agents/embedded-agent-runner/run/lane-controller.queue-liveness.test.ts‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import {
66
rotateAgentEventLifecycleGeneration,
77
} from "../../../infra/agent-events.js";
88
import {
9+
isAgentRunWaitingForCapacity,
10+
registerAgentRunCapacityWait,
11+
} from "../../../infra/agent-run-capacity-wait.js";
12+
import {
13+
claimAgentRunContext,
14+
clearAgentRunContext,
915
getAgentRunContext,
1016
readAgentRunIndexVersion,
1117
registerAgentRunContext,
@@ -17,6 +23,7 @@ import {
1723
setCommandLaneConcurrency,
1824
} from "../../../process/command-queue.js";
1925
import { resetCommandQueueStateForTest } from "../../../process/command-queue.test-support.js";
26+
import { onSessionLifecycleEvent } from "../../../sessions/session-lifecycle-events.js";
2027
import { createTestAdmittedRunContext } from "../../admitted-run-context.test-support.js";
2128
import { installSessionPlacementAdmissionProvider } from "../../session-placement-admission.js";
2229
import type { EmbeddedAgentRunResult } from "../types.js";
@@ -297,8 +304,10 @@ describe("queued embedded run context liveness", () => {
297304
await waitForQueuedLane(blockedLane);
298305
clock.mockReturnValue(registeredAt + CONTEXT_TTL_MS + 1);
299306
expect(sweepStaleRunContexts()).toBe(0);
307+
expect(isAgentRunWaitingForCapacity(params.runId)).toBe(true);
300308

301309
abort.abort(new Error("queued run canceled"));
310+
expect(isAgentRunWaitingForCapacity(params.runId)).toBe(false);
302311
expect(getCommandLaneSnapshot(blockedLane).queuedCount).toBe(1);
303312
expect(sweepStaleRunContexts()).toBe(1);
304313
expect(getAgentRunContext(params.runId)).toBeUndefined();
@@ -508,3 +517,100 @@ describe("queued embedded run context liveness", () => {
508517
}
509518
});
510519
});
520+
521+
describe("scheduler capacity wait projection", () => {
522+
test.each([SESSION_LANE, GLOBAL_LANE, undefined])(
523+
"publishes only actual %s queue waits and clears before placement setup",
524+
async (blockedLane) => {
525+
const sessionKey = "agent:main:capacity";
526+
const { controller, params } = createRunController({ sessionKey });
527+
registerAgentRunContext(params.runId, {
528+
sessionKey,
529+
sessionId: params.sessionId,
530+
lifecycleGeneration: params.lifecycleGeneration,
531+
});
532+
const events: boolean[] = [];
533+
const unsubscribe = onSessionLifecycleEvent((event) => {
534+
if (event.sessionKey === sessionKey && event.reason === "run-capacity") {
535+
events.push(isAgentRunWaitingForCapacity(params.runId));
536+
}
537+
});
538+
const placementEntered = createDeferred();
539+
const resumePlacement = createDeferred();
540+
const uninstallPlacement = installSessionPlacementAdmissionProvider({
541+
executeLocalTurn: async (_claim, runLocal) => await runLocal(),
542+
executeTurn: async (_claim, _params, runLocal) => {
543+
placementEntered.resolve();
544+
await resumePlacement.promise;
545+
return await runLocal();
546+
},
547+
});
548+
if (blockedLane) {
549+
setCommandLaneConcurrency(blockedLane, 0);
550+
}
551+
const run = controller.enqueueSession(() =>
552+
controller.enqueueGlobal(async () => ({}) as EmbeddedAgentRunResult),
553+
);
554+
try {
555+
if (blockedLane) {
556+
await waitForQueuedLane(blockedLane);
557+
expect(events).toEqual([true]);
558+
setCommandLaneConcurrency(blockedLane, 1);
559+
}
560+
await placementEntered.promise;
561+
expect(isAgentRunWaitingForCapacity(params.runId)).toBe(false);
562+
expect(events).toEqual(blockedLane ? [true, false] : []);
563+
} finally {
564+
if (blockedLane) {
565+
setCommandLaneConcurrency(blockedLane, 1);
566+
}
567+
resumePlacement.resolve();
568+
try {
569+
await run;
570+
} finally {
571+
uninstallPlacement();
572+
unsubscribe();
573+
}
574+
}
575+
},
576+
);
577+
578+
test("keeps custom queue setup spinning when it supplies no capacity evidence", async () => {
579+
const customQueue = createDeferred();
580+
const { controller, params } = createRunController({
581+
enqueue: async (task) => {
582+
await customQueue.promise;
583+
return await task();
584+
},
585+
});
586+
registerAgentRunContext(params.runId, { lifecycleGeneration: params.lifecycleGeneration });
587+
const run = controller.enqueueSession(() =>
588+
controller.enqueueGlobal(async () => ({}) as EmbeddedAgentRunResult),
589+
);
590+
try {
591+
expect(isAgentRunWaitingForCapacity(params.runId)).toBe(false);
592+
} finally {
593+
customQueue.resolve();
594+
await run;
595+
}
596+
});
597+
598+
test.each([
599+
{ name: "registration", replace: registerAgentRunContext },
600+
{ name: "claim", replace: claimAgentRunContext },
601+
])("old wait releases cannot clear a recycled run after $name", ({ replace }) => {
602+
const runId = "recycled-capacity-run";
603+
const lifecycleGeneration = getAgentEventLifecycleGeneration();
604+
registerAgentRunContext(runId, { lifecycleGeneration });
605+
const releaseOld = registerAgentRunCapacityWait(runId, lifecycleGeneration);
606+
const oldContext = getAgentRunContext(runId);
607+
clearAgentRunContext(runId);
608+
replace(runId, { ...oldContext, lifecycleGeneration });
609+
expect(isAgentRunWaitingForCapacity(runId)).toBe(false);
610+
const releaseNew = registerAgentRunCapacityWait(runId, lifecycleGeneration);
611+
releaseOld?.();
612+
expect(isAgentRunWaitingForCapacity(runId)).toBe(true);
613+
releaseNew?.();
614+
expect(isAgentRunWaitingForCapacity(runId)).toBe(false);
615+
});
616+
});

‎src/agents/embedded-agent-runner/run/lane-controller.ts‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getAgentEventLifecycleGeneration,
44
withAgentRunLifecycleGeneration,
55
} from "../../../infra/agent-events.js";
6+
import { registerAgentRunCapacityWait } from "../../../infra/agent-run-capacity-wait.js";
67
import {
78
claimAgentRunContext,
89
getAgentRunContext,
@@ -46,8 +47,23 @@ export function createEmbeddedRunLaneController<TParams extends LaneParams>(opti
4647
let laneTaskProgressAtMs = Date.now();
4748
let releaseQueuedRunContext: ReturnType<typeof retainQueuedAgentRunContext>;
4849
let queuedRunAbortSignal: AbortSignal | undefined;
50+
let releaseCapacityWait: (() => void) | undefined;
51+
const endCapacityWait = () => {
52+
releaseCapacityWait?.();
53+
releaseCapacityWait = undefined;
54+
};
55+
const noteCapacityWait = () => {
56+
const params = options.getParams();
57+
if (!params.abortSignal?.aborted) {
58+
releaseCapacityWait = registerAgentRunCapacityWait(
59+
params.runId,
60+
options.getLifecycleGeneration(),
61+
);
62+
}
63+
};
4964

5065
const releaseQueuedContext = (outcome: "admitted" | "abandoned") => {
66+
endCapacityWait();
5167
queuedRunAbortSignal?.removeEventListener("abort", abandonQueuedContext);
5268
queuedRunAbortSignal = undefined;
5369
releaseQueuedRunContext?.(outcome);
@@ -123,8 +139,10 @@ export function createEmbeddedRunLaneController<TParams extends LaneParams>(opti
123139
const globalOpts: CommandQueueEnqueueOptions = {
124140
...opts,
125141
priority: sessionQueuePriority,
142+
onQueued: noteCapacityWait,
126143
};
127144
const taskWithCurrentLifecycle = async () => {
145+
endCapacityWait();
128146
let params = options.getParams();
129147
params.replyOperation?.markGlobalLaneWaitEnded();
130148
throwIfAborted();
@@ -204,7 +222,15 @@ export function createEmbeddedRunLaneController<TParams extends LaneParams>(opti
204222
);
205223
};
206224
const enqueueSession = <T>(task: () => Promise<T>, opts?: CommandQueueEnqueueOptions) => {
207-
const sessionOpts: CommandQueueEnqueueOptions = { ...opts, priority: sessionQueuePriority };
225+
const sessionOpts: CommandQueueEnqueueOptions = {
226+
...opts,
227+
priority: sessionQueuePriority,
228+
onQueued: noteCapacityWait,
229+
};
230+
const admittedTask = () => {
231+
endCapacityWait();
232+
return task();
233+
};
208234
const params = options.getParams();
209235
// Session admission, deferred maintenance, and global admission share one queue owner.
210236
releaseQueuedRunContext = retainQueuedAgentRunContext(
@@ -222,10 +248,14 @@ export function createEmbeddedRunLaneController<TParams extends LaneParams>(opti
222248
let queuedRun: Promise<T>;
223249
try {
224250
if (params.enqueue) {
225-
queuedRun = params.enqueue(task, withRunLaneWait(sessionOpts));
251+
queuedRun = params.enqueue(admittedTask, withRunLaneWait(sessionOpts));
226252
} else {
227253
noteLaneWaitIfBusy(options.sessionLane);
228-
queuedRun = enqueueCommandInLane(options.sessionLane, task, withRunLaneWait(sessionOpts));
254+
queuedRun = enqueueCommandInLane(
255+
options.sessionLane,
256+
admittedTask,
257+
withRunLaneWait(sessionOpts),
258+
);
229259
}
230260
} catch (error) {
231261
releaseQueuedContext("abandoned");

‎src/agents/embedded-agent-runner/runs.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,10 @@ export function resolveEmbeddedAgentRunProgressState(
799799
// A retained terminal owner must not hide a newer live owner for the session.
800800
if (
801801
handleInProgress ||
802-
(replyInProgress && replyOperation && hasReplyOperationExecutionStarted(replyOperation))
802+
(replyInProgress &&
803+
replyOperation &&
804+
replyPhase !== "waiting_for_global_lane" &&
805+
hasReplyOperationExecutionStarted(replyOperation))
803806
) {
804807
return "running";
805808
}

‎src/agents/subagents/registry/subagent-registry-restore.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,14 @@ export function createSubagentRegistryRestorer(config: {
290290
);
291291
},
292292
});
293-
bindSwarmRunReservation(entry.schedulerSlotId ?? runId, entry);
293+
bindSwarmRunReservation(entry.schedulerSlotId ?? runId, entry, () => {
294+
if (runs.get(entry.runId) === entry) {
295+
emitSessionLifecycleEvent({
296+
sessionKey: entry.childSessionKey,
297+
reason: "run-capacity",
298+
});
299+
}
300+
});
294301
continue;
295302
}
296303
// An aborted persisted session belongs to orphan recovery. Waiting on its

‎src/agents/subagents/registry/subagent-registry-run-launch.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "../../../infra/agent-events.js";
77
import { createSubsystemLogger } from "../../../logging/subsystem.js";
88
import { bindGatewayContextResolver } from "../../../plugins/runtime/gateway-request-scope.js";
9+
import { emitSessionLifecycleEvent } from "../../../sessions/session-lifecycle-events.js";
910
import {
1011
createQueuedTaskRun,
1112
createRunningTaskRun,
@@ -206,7 +207,11 @@ export class SubagentLaunchManager extends SubagentRecoveryManager {
206207
this.restoreKillReconciliationSnapshots(registeredKillReconciliationSnapshots);
207208
};
208209
const activateRegistrationLifecycle = () => {
209-
bindSwarmRunReservation(entry.schedulerSlotId ?? runId, entry);
210+
bindSwarmRunReservation(entry.schedulerSlotId ?? runId, entry, () => {
211+
if (this.options.runs.get(entry.runId) === entry) {
212+
emitSessionLifecycleEvent({ sessionKey: entry.childSessionKey, reason: "run-capacity" });
213+
}
214+
});
210215
subagentRuns.commitOwnership(entry);
211216
this.options.ensureListener();
212217
// Session-mode and persistence-recovery runs also need TTL cleanup.

‎src/agents/subagents/swarm/swarm-scheduler.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
import {
33
activateSwarmRun,
4+
bindSwarmRunReservation,
45
enqueueSwarmRun,
56
isSwarmRunActive,
7+
isSwarmRunWaitingForCapacity,
68
holdQueuedSwarmRun,
79
releaseSwarmRun,
810
removeQueuedSwarmRun,
@@ -60,10 +62,19 @@ describe("swarm scheduler", () => {
6062
start: start("three"),
6163
onStartFailure,
6264
});
65+
const owner = {};
66+
const waits: boolean[] = [];
67+
bindSwarmRunReservation("two", owner, () => {
68+
waits.push(isSwarmRunWaitingForCapacity("two", owner));
69+
});
6370

6471
await vi.waitFor(() => expect(started).toEqual(["one"]));
72+
expect(isSwarmRunWaitingForCapacity("two", owner)).toBe(true);
73+
expect(isSwarmRunWaitingForCapacity("two", {})).toBe(false);
6574
expect(releaseSwarmRun("one")).toBe(true);
75+
expect(isSwarmRunWaitingForCapacity("two", owner)).toBe(false);
6676
await vi.waitFor(() => expect(started).toEqual(["one", "two"]));
77+
expect(waits).toEqual([true, false]);
6778
expect(releaseSwarmRun("two")).toBe(true);
6879
await vi.waitFor(() => expect(started).toEqual(["one", "two", "three"]));
6980
expect(onStartFailure).not.toHaveBeenCalled();
@@ -90,12 +101,17 @@ describe("swarm scheduler", () => {
90101

91102
expect(reserve("one")).toBe(true);
92103
expect(reserve("two")).toBe(true);
104+
const owner = {};
105+
bindSwarmRunReservation("two", owner);
106+
expect(isSwarmRunWaitingForCapacity("two", owner)).toBe(false);
93107
activate("two");
94108
await Promise.resolve();
95109
expect(started).toEqual([]);
110+
expect(isSwarmRunWaitingForCapacity("two", owner)).toBe(false);
96111

97112
activate("one");
98113
await vi.waitFor(() => expect(started).toEqual(["one"]));
114+
expect(isSwarmRunWaitingForCapacity("two", owner)).toBe(true);
99115
expect(releaseSwarmRun("one")).toBe(true);
100116
await vi.waitFor(() => expect(started).toEqual(["one", "two"]));
101117
});
@@ -117,8 +133,18 @@ describe("swarm scheduler", () => {
117133
enqueue("one");
118134
enqueue("two");
119135
enqueue("three");
120-
expect(removeQueuedSwarmRun("two")).toBe(true);
136+
const owner = {};
137+
const waits: boolean[] = [];
138+
bindSwarmRunReservation("two", owner, () => {
139+
waits.push(isSwarmRunWaitingForCapacity("two", owner));
140+
});
121141
await vi.waitFor(() => expect(started).toEqual(["one"]));
142+
const hold = holdQueuedSwarmRun("two");
143+
expect(isSwarmRunWaitingForCapacity("two", owner)).toBe(false);
144+
hold?.release();
145+
expect(isSwarmRunWaitingForCapacity("two", owner)).toBe(true);
146+
expect(removeQueuedSwarmRun("two")).toBe(true);
147+
expect(waits).toEqual([true, false, true, false]);
122148
releaseSwarmRun("one");
123149
await vi.waitFor(() => expect(started).toEqual(["one", "three"]));
124150
});
@@ -324,14 +350,21 @@ describe("swarm scheduler", () => {
324350
enqueue("one", 2);
325351
enqueue("two", 2);
326352
enqueue("three", 2);
353+
const owner = {};
354+
const waits: boolean[] = [];
355+
bindSwarmRunReservation("three", owner, () => {
356+
waits.push(isSwarmRunWaitingForCapacity("three", owner));
357+
});
327358
await vi.waitFor(() => expect(started).toEqual(["one", "two"]));
328359
enqueue("four", 1);
329360

330361
releaseSwarmRun("one");
331362
await Promise.resolve();
332363
expect(started).toEqual(["one", "two"]);
364+
expect(waits).toEqual([true]);
333365
releaseSwarmRun("two");
334366
await vi.waitFor(() => expect(started).toEqual(["one", "two", "three"]));
367+
expect(waits).toEqual([true, false]);
335368
});
336369

337370
it("refreshes the lane limit before rejecting a duplicate reservation", async () => {

0 commit comments

Comments
 (0)