Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agents): allow consecutive optimistic force-sends of queued prompts (#8974)

Wolf Mermelstein0e59890ef38d
diff --git a/apps/web/src/features/agents-view/components/ChatComposer.tsx b/apps/web/src/features/agents-view/components/ChatComposer.tsx
index c20d219b44..c6e96674bc 100644
--- a/apps/web/src/features/agents-view/components/ChatComposer.tsx
+++ b/apps/web/src/features/agents-view/components/ChatComposer.tsx
@@ -114,7 +114,6 @@ export function ChatComposer(props: {
const disabled = () => !!props.blockedReason || props.session?.disabled;
const canSendNext = () =>
!hasContent() &&
- !props.session?.sendNextHeld &&
props.session?.hasQueuedMessages &&
props.session.onStop &&
!disabled();
diff --git a/apps/web/src/features/block-agent/agent-session-provider.tsx b/apps/web/src/features/block-agent/agent-session-provider.tsx
index 097fcb6950..7ba6684933 100644
--- a/apps/web/src/features/block-agent/agent-session-provider.tsx
+++ b/apps/web/src/features/block-agent/agent-session-provider.tsx
@@ -28,8 +28,7 @@ import {
type QueueController,
} from './context/create-queue-controller';
import { resolveSessionId } from './context/resolve-session-id';
-import { createSendNext } from './context/send-next';
-import { createSteer } from './context/steer';
+import { createSteering } from './context/steer';
import { createToolApprovalController } from './primitives/create-tool-approval-controller';
import type { QuoteInsert } from './ui';
@@ -97,7 +96,7 @@ export function AgentSessionProvider(
sessionId: () => (userId() ? sessionId() : undefined),
messages: live.messages,
});
- // A row the user removes may be one `sendNext` already showed as sent;
+ // A row the user removes may be one a force-send already showed as sent;
// the fold has to forget it too, or it stays a bubble the log never fills.
const queue: QueueController = {
...served,
@@ -106,16 +105,9 @@ export function AgentSessionProvider(
return served.remove(actionId);
},
};
- const sendNext = createSendNext({
- currentTurn: live.currentTurn,
- entries: queue.entries,
- issue: live.issue,
- expect: live.expect,
- retract: live.retract,
- });
- const steer = createSteer({
- currentTurn: live.currentTurn,
+ const steering = createSteering({
entries: queue.entries,
+ waiting: queue.waiting,
steer: queue.steer,
expect: live.expect,
retract: live.retract,
@@ -189,8 +181,9 @@ export function AgentSessionProvider(
turn,
issue: live.issue,
selectModel: live.selectModel,
- sendNext,
- steer,
+ sendNext: steering.sendNext,
+ steer: steering.steer,
+ steerFailed: steering.failed,
interactions,
toolApprovals,
queue,
diff --git a/apps/web/src/features/block-agent/component/AgentComposer.test.tsx b/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
index ff87ad55af..2ca638a9aa 100644
--- a/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
+++ b/apps/web/src/features/block-agent/component/AgentComposer.test.tsx
@@ -63,6 +63,7 @@ vi.mock('../context/AgentSessionContext', () => ({
},
sendNext: mocks.sendNext,
steer: mocks.steer,
+ steerFailed: () => new Set(),
turn: () => mocks.turn(),
sessionId: () => 'session-1',
registerQuoteInsert: vi.fn(),
@@ -178,7 +179,7 @@ describe('view-only session controls', () => {
);
});
-it('explicitly sends the queue head and disables it while the turn transitions', () => {
+it('keeps force-sending the queue head while the turn transitions', () => {
const [turn, setTurn] = createSignal<TurnState>('running');
mocks.turn = turn;
mocks.session = () => ({ canEdit: true });
@@ -191,11 +192,10 @@ it('explicitly sends the queue head and disables it while the turn transitions',
expect(mocks.sendNext).toHaveBeenCalledTimes(1);
for (const next of ['stopping', 'starting'] as const) {
setTurn(next);
- expect(sendNext.hasAttribute('disabled')).toBe(true);
- expect(mocks.queued?.onSteer).toBeUndefined();
+ expect(mocks.queued?.onSteer).toEqual(expect.any(Function));
fireEvent.click(sendNext);
}
- expect(mocks.sendNext).toHaveBeenCalledTimes(1);
+ expect(mocks.sendNext).toHaveBeenCalledTimes(3);
});
it('retains an unsent draft when speed configuration is rejected', async () => {
diff --git a/apps/web/src/features/block-agent/component/AgentComposer.tsx b/apps/web/src/features/block-agent/component/AgentComposer.tsx
index 891f1f5360..bdcbc626d2 100644
--- a/apps/web/src/features/block-agent/component/AgentComposer.tsx
+++ b/apps/web/src/features/block-agent/component/AgentComposer.tsx
@@ -80,6 +80,7 @@ export function AgentComposer(props: {
queue,
sendNext,
steer,
+ steerFailed,
turn,
registerQuoteInsert,
initialInput,
@@ -236,6 +237,7 @@ export function AgentComposer(props: {
prompt: entry.prompt ?? undefined,
attachments: entry.attachments,
queuedBy: actor && actor !== userId() ? displayName(actor) : undefined,
+ sendFailed: steerFailed().has(entry.actionId),
};
});
@@ -252,13 +254,7 @@ export function AgentComposer(props: {
size="sm"
class="touch:min-h-11"
aria-label="Send next queued message now"
- disabled={
- readOnly() ||
- loadFailed() ||
- pending() ||
- turn() === 'stopping' ||
- turn() === 'starting'
- }
+ disabled={readOnly() || loadFailed() || pending()}
onClick={() => {
if (!readOnly()) sendNext();
}}
@@ -280,10 +276,7 @@ export function AgentComposer(props: {
fireAndForget(queue.remove(actionId), 'agent-composer');
}}
onSteer={
- busy() &&
- !readOnly() &&
- turn() !== 'stopping' &&
- turn() !== 'starting'
+ (busy() || turn() === 'stopping') && !readOnly()
? (actionId) => steer(actionId)
: undefined
}
@@ -334,16 +327,6 @@ export function AgentComposer(props: {
autofocus={props.autofocus}
busy={busy()}
hasQueuedMessages={queuedItems().length > 0}
- // Read off the fold's turn discriminant, never `pending`, which
- // clears as soon as the log confirms a cancel - well before the
- // runtime winds the turn down, and every Enter in that gap posted
- // another cancel. `stopping` is a stop already working on this turn.
- // `starting` is the prompt the last advance showed as sent, still
- // unconfirmed: the server has not dispatched it, so a stop now would
- // end the turn already ending and the server would dispatch *that*
- // head - the next one would sit as a sent-looking bubble while it
- // waits. Enter is admitted again once the log confirms the head.
- sendNextHeld={turn() === 'stopping' || turn() === 'starting'}
// Prompts go straight to the service, so sending needs a session to
// post to — a block whose create is still on the wire can be typed
// into, but not sent from, until the id lands.
diff --git a/apps/web/src/features/block-agent/context/AgentSessionContext.tsx b/apps/web/src/features/block-agent/context/AgentSessionContext.tsx
index 8cbd3be2aa..4d4ac70c23 100644
--- a/apps/web/src/features/block-agent/context/AgentSessionContext.tsx
+++ b/apps/web/src/features/block-agent/context/AgentSessionContext.tsx
@@ -74,21 +74,18 @@ export type AgentSessionState = {
/** Resolve only after the runtime confirms the selected model and effort. */
selectModel: (model: string, effort?: EffortSelection) => Promise<void>;
/**
- * Send the next queued message now: stop the running turn, and show the
- * queue head as sent under the id the server already holds it by. The
- * server dispatches it when the turn actually ends, and that row promotes
- * the speculation in place. No-op with nothing queued, and while the head
- * a previous call showed as sent is still unconfirmed (`turn` reads
- * `starting`): a stop posted then would end the turn already ending, and
- * the server would dispatch that head, not the next one.
+ * Force-send the oldest queued message: the same as {@link steer} on the
+ * queue head. No-op with nothing queued.
*/
sendNext: () => void;
/**
- * Steer one queued message: show it as sent, move it to the front of the
- * queue, and cancel the turn in flight so it runs next. No-op while the
- * prompt a previous steer or send-next showed as sent is still unconfirmed.
+ * Force-send one queued message: show it as sent at once, move it to the
+ * front of the queue, and cancel the turn in flight so it runs next.
+ * Consecutive presses all apply at once and steer in press order.
*/
steer: (actionId: string) => void;
+ /** Queued messages whose force-send the server refused; still queued. */
+ steerFailed: Accessor<ReadonlySet<string>>;
/** The live requests, and the action that answers each one. */
interactions: InteractionController;
/**
diff --git a/apps/web/src/features/block-agent/context/create-queue-controller.ts b/apps/web/src/features/block-agent/context/create-queue-controller.ts
index 9dfdcb0b44..1a7bcf71f3 100644
--- a/apps/web/src/features/block-agent/context/create-queue-controller.ts
+++ b/apps/web/src/features/block-agent/context/create-queue-controller.ts
@@ -39,6 +39,8 @@ export type QueueController = {
* so the queue must not.
*/
entries: Accessor<QueuedActionDto[]>;
+ /** Whether the server queue still holds this action, shown or not. */
+ waiting: (actionId: string) => boolean;
/** Replace a queued prompt's text. A 404 means it already dispatched —
* the gateway's snapshot reconciles it, not an error. */
edit: (actionId: string, prompt: string) => Promise<void>;
@@ -47,7 +49,7 @@ export type QueueController = {
/**
* Run this queued action next: the server moves it to the front and
* cancels the turn in flight. `false` when it was not waiting anymore or
- * the request failed.
+ * the request failed; the caller reports the failure.
*/
steer: (actionId: string) => Promise<boolean>;
};
@@ -113,8 +115,8 @@ export function createQueueController(options: {
})
);
- // A pending message retires a row too. `sendNext` speculates the queue
- // head under the id this list knows it by, and the whole point is that it
+ // A pending message retires a row too. A force-send speculates the entry
+ // under the id this list knows it by, and the whole point is that it
// reads as sent; a prompt the server queued after the client speculated
// it is retracted by the response, so its row comes back on its own.
const dispatchedIds = createMemo(() => {
@@ -161,18 +163,14 @@ export function createQueueController(options: {
const result = await agentHarnessServiceClient
.steerQueued(sessionId, actionId)
.catch(() => undefined);
- if (result === undefined || result.isErr()) {
- if (result === undefined || !isDispatched(result)) {
- toast.failure('The queued message could not be steered');
- }
- return false;
- }
- return true;
+ return result !== undefined && result.isOk();
};
return {
entries: () =>
queued().filter((entry) => !dispatchedIds().has(entry.actionId)),
+ waiting: (actionId) =>
+ queued().some((entry) => entry.actionId === actionId),
edit,
remove,
steer,
diff --git a/apps/web/src/features/block-agent/context/send-next.ts b/apps/web/src/features/block-agent/context/send-next.ts
deleted file mode 100644
index d929a7dd32..0000000000
--- a/apps/web/src/features/block-agent/context/send-next.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * "Send the next queued message now": stop the running turn, and show the
- * queue head as sent under the id the server already holds it by. The
- * server dispatches the head when the turn actually ends, and that row
- * promotes the speculation in place.
- */
-
-import type { IssueResult } from '@core/agent-session/AgentSession';
-import { fireAndForget } from '@core/util/fireAndForget';
-import type { TurnState } from '@service-agent-fold/generated/types';
-import type {
- AgentAction,
- QueuedActionDto,
-} from '@service-agent-harness/generated/schemas';
-
-/** The action a queued entry will run as, when the composer can show it sent. */
-export function actionForQueuedEntry(
- entry: QueuedActionDto
-): AgentAction | undefined {
- if (entry.kind === 'prompt' && entry.prompt != null) {
- return { type: 'prompt', prompt: entry.prompt };
- }
- if (entry.kind === 'compact') return { type: 'compact' };
- return undefined;
-}
-
-export function createSendNext(session: {
- /**
- * The session's turn as it stands at call time, including what it has
- * just speculated: the fold's reactive report lags by the worker round
- * trip, and two presses inside it must not both pass.
- */
- currentTurn: () => TurnState;
- /** The queue as the composer shows it: the server's entries minus any the fold already shows. */
- entries: () => QueuedActionDto[];
- issue: (action: AgentAction) => Promise<IssueResult> | undefined;
- expect: (actionId: string, action: AgentAction) => void;
- retract: (actionId: string) => void;
-}): () => void {
- return () => {
- // The head a previous send-next showed as sent is still on its way: the
- // server has not dispatched it, so a stop posted now lands on the turn
- // that is already ending and the server dispatches *that* head when it
- // does - not this one. Speculating this one anyway would show it as sent
- // while it waits in the queue, behind a turn the server is only now
- // starting. The next press is admitted once the log confirms the head.
- if (session.currentTurn() === 'starting') return;
- const head = session.entries()[0];
- if (!head) return;
- const action = actionForQueuedEntry(head);
- fireAndForget(
- session.issue({ type: 'stop' })?.then((result) => {
- if (result.isErr()) session.retract(head.actionId);
- }),
- 'agent-queue'
- );
- if (action) session.expect(head.actionId, action);
- };
-}
diff --git a/apps/web/src/features/block-agent/context/steer.test.ts b/apps/web/src/features/block-agent/context/steer.test.ts
index ac19d02267..cf221a1ca5 100644
--- a/apps/web/src/features/block-agent/context/steer.test.ts
+++ b/apps/web/src/features/block-agent/context/steer.test.ts
@@ -1,52 +1,140 @@
import type { QueuedActionDto } from '@service-agent-harness/generated/schemas';
+import { createRoot, createSignal } from 'solid-js';
import { describe, expect, it, vi } from 'vitest';
-import { createSteer } from './steer';
+import { createSteering } from './steer';
-const waiting: QueuedActionDto = {
- actionId: 'later',
+const first: QueuedActionDto = {
+ actionId: 'first',
kind: 'prompt',
- prompt: 'Steer this',
+ prompt: 'First',
attachments: [],
actorUserId: null,
createdAt: '2026-10-02T00:00:00Z',
};
+const second: QueuedActionDto = {
+ actionId: 'second',
+ kind: 'prompt',
+ prompt: 'Second',
+ attachments: [],
+ actorUserId: null,
+ createdAt: '2026-10-02T00:00:01Z',
+};
+const third: QueuedActionDto = {
+ actionId: 'third',
+ kind: 'prompt',
+ prompt: 'Third',
+ attachments: [],
+ actorUserId: null,
+ createdAt: '2026-10-02T00:00:02Z',
+};
+const fourth: QueuedActionDto = {
+ actionId: 'fourth',
+ kind: 'prompt',
+ prompt: 'Fourth',
+ attachments: [],
+ actorUserId: null,
+ createdAt: '2026-10-02T00:00:03Z',
+};
+
+describe('createSteering', () => {
+ it('shows three consecutive force-sends at once and steers each exactly once, in press order', async () => {
+ const [serverQueue, setServerQueue] = createSignal([
+ first,
+ second,
+ third,
+ fourth,
+ ]);
+ const [speculated, setSpeculated] = createSignal<string[]>([]);
+ const firstSteer = Promise.resolve(true);
+ const secondSteer = Promise.resolve(true);
+ const thirdSteer = Promise.resolve(true);
+ const steer = vi
+ .fn<(actionId: string) => Promise<boolean>>()
+ .mockReturnValueOnce(firstSteer)
+ .mockReturnValueOnce(secondSteer)
+ .mockReturnValueOnce(thirdSteer);
+ const expectAction = vi.fn((actionId: string) =>
+ setSpeculated((current) => [...current, actionId])
+ );
+ const entries = () =>
+ serverQueue().filter((entry) => !speculated().includes(entry.actionId));
+ const steering = createRoot(() =>
+ createSteering({
+ entries,
+ waiting: (actionId) =>
+ serverQueue().some((entry) => entry.actionId === actionId),
+ steer,
+ expect: expectAction,
+ retract: vi.fn(),
+ })
+ );
+
+ steering.steer('first');
+ steering.steer('second');
+ steering.sendNext();
+ steering.steer('first');
+
+ expect(expectAction.mock.calls).toEqual([
+ ['first', { type: 'prompt', prompt: 'First' }],
+ ['second', { type: 'prompt', prompt: 'Second' }],
+ ['third', { type: 'prompt', prompt: 'Third' }],
+ ]);
+ expect(entries()).toEqual([fourth]);
+ expect(steer.mock.calls).toEqual([['first']]);
+
+ await firstSteer;
+ expect(steer.mock.calls).toEqual([['first']]);
+ setServerQueue([second, third, fourth]);
+ expect(steer.mock.calls).toEqual([['first'], ['second']]);
-describe('createSteer', () => {
- it('shows the chosen prompt as sent and takes it back when the server refuses', async () => {
- const expectAction = vi.fn();
- const retract = vi.fn();
- const steer = vi.fn(async () => false);
- const send = createSteer({
- currentTurn: () => 'running',
- entries: () => [waiting],
- steer,
- expect: expectAction,
- retract,
- });
-
- send('later');
-
- expect(expectAction).toHaveBeenCalledWith('later', {
- type: 'prompt',
- prompt: 'Steer this',
- });
- await vi.waitFor(() => expect(retract).toHaveBeenCalledWith('later'));
+ await secondSteer;
+ setServerQueue([third, fourth]);
+ expect(steer.mock.calls).toEqual([['first'], ['second'], ['third']]);
+
+ await thirdSteer;
+ setServerQueue([fourth]);
+ expect(steer.mock.calls).toEqual([['first'], ['second'], ['third']]);
+ expect(steering.failed().size).toBe(0);
});
- it('does not jump another entry while a steer is still unconfirmed', () => {
- const expectAction = vi.fn();
- const steer = vi.fn(async () => true);
- const send = createSteer({
- currentTurn: () => 'starting',
- entries: () => [waiting],
- steer,
- expect: expectAction,
- retract: vi.fn(),
- });
-
- send('later');
-
- expect(expectAction).not.toHaveBeenCalled();
- expect(steer).not.toHaveBeenCalled();
+ it('keeps a refused force-send queued with an error and steers the next one', async () => {
+ const [serverQueue] = createSignal([first, second]);
+ const [speculated, setSpeculated] = createSignal<string[]>([]);
+ const refused = Promise.resolve(false);
+ const accepted = Promise.resolve(true);
+ const steer = vi
+ .fn<(actionId: string) => Promise<boolean>>()
+ .mockReturnValueOnce(refused)
+ .mockReturnValueOnce(accepted);
+ const retract = vi.fn((actionId: string) =>
+ setSpeculated((current) => current.filter((id) => id !== actionId))
+ );
+ const entries = () =>
+ serverQueue().filter((entry) => !speculated().includes(entry.actionId));
+ const steering = createRoot(() =>
+ createSteering({
+ entries,
+ waiting: (actionId) =>
+ serverQueue().some((entry) => entry.actionId === actionId),
+ steer,
+ expect: (actionId) =>
+ setSpeculated((current) => [...current, actionId]),
+ retract,
+ })
+ );
+
+ steering.steer('first');
+ steering.steer('second');
+ expect(entries()).toEqual([]);
+
+ await refused;
+
+ expect(retract).toHaveBeenCalledWith('first');
+ expect(entries()).toEqual([first]);
+ expect([...steering.failed()]).toEqual(['first']);
+ expect(steer.mock.calls).toEqual([['first'], ['second']]);
+
+ steering.steer('first');
+ expect(steering.failed().size).toBe(0);
});
});
diff --git a/apps/web/src/features/block-agent/context/steer.ts b/apps/web/src/features/block-agent/context/steer.ts
index e1636e607f..b10f071bfa 100644
--- a/apps/web/src/features/block-agent/context/steer.ts
+++ b/apps/web/src/features/block-agent/context/steer.ts
@@ -1,44 +1,112 @@
/**
- * "Steer" a queued message: show it as sent now, and ask the server to run
- * it next. The server moves that entry to the front and cancels the turn in
- * flight, so it flushes ahead of anything queued before it. The dispatched
- * row arrives under the same id and promotes this speculation in place.
+ * Force-sending queued messages: Steer on a row, and Send next for the
+ * oldest one. Each press shows its message as sent at once and asks the
+ * server to run it next - the server moves that entry to the front and
+ * cancels the turn in flight. The dispatched row arrives under the same id
+ * and promotes the speculation in place.
+ *
+ * Presses never wait on each other in the UI, but their steers go out one
+ * at a time, in press order: the next is sent only once the previous entry
+ * has left the server queue. Sent sooner, it would jump in front of the one
+ * still waiting and the transcript would run in the reverse order.
*/
import { fireAndForget } from '@core/util/fireAndForget';
-import type { TurnState } from '@service-agent-fold/generated/types';
import type {
AgentAction,
QueuedActionDto,
} from '@service-agent-harness/generated/schemas';
-import { actionForQueuedEntry } from './send-next';
+import { type Accessor, createEffect, createSignal } from 'solid-js';
-export function createSteer(session: {
+/** The action a queued entry will run as, when the composer can show it sent. */
+export function actionForQueuedEntry(
+ entry: QueuedActionDto
+): AgentAction | undefined {
+ if (entry.kind === 'prompt' && entry.prompt != null) {
+ return { type: 'prompt', prompt: entry.prompt };
+ }
+ if (entry.kind === 'compact') return { type: 'compact' };
+ return undefined;
+}
+
+export type Steering = {
+ /** Force-send this queued entry. */
+ steer: (actionId: string) => void;
+ /** Force-send the oldest entry the composer still shows as queued. */
+ sendNext: () => void;
+ /** Entries whose last force-send the server refused; they stay queued. */
+ failed: Accessor<ReadonlySet<string>>;
+};
+
+export function createSteering(session: {
/**
- * The session's turn as it stands at call time. A steer that already
- * showed its prompt as sent reads `starting` here, and a second press
- * inside that window must not jump another entry in front of it.
+ * The queue as the composer shows it. A force-sent entry is speculated,
+ * so it drops out of here at once and cannot be force-sent twice.
*/
- currentTurn: () => TurnState;
- /** The queue as the composer shows it. */
entries: () => QueuedActionDto[];
+ /** Whether the server queue still holds this entry. Reactive. */
+ waiting: (actionId: string) => boolean;
/** Move `actionId` to the front and cancel the turn in flight. */
steer: (actionId: string) => Promise<boolean>;
expect: (actionId: string, action: AgentAction) => void;
retract: (actionId: string) => void;
-}): (actionId: string) => void {
- return (actionId) => {
- if (session.currentTurn() === 'starting') return;
+}): Steering {
+ // Pressed, shown as sent, and not steered yet, in press order.
+ const [backlog, setBacklog] = createSignal<string[]>([]);
+ // The last entry steered, until it leaves the server queue.
+ const [ahead, setAhead] = createSignal<string>();
+ const [failed, setFailed] = createSignal<ReadonlySet<string>>(new Set());
+
+ const markFailed = (actionId: string, isFailed: boolean) =>
+ setFailed((current) => {
+ if (current.has(actionId) === isFailed) return current;
+ const next = new Set(current);
+ if (isFailed) next.add(actionId);
+ else next.delete(actionId);
+ return next;
+ });
+
+ const send = async (actionId: string) => {
+ const accepted = await session.steer(actionId);
+ if (accepted) return;
+ setAhead((current) => (current === actionId ? undefined : current));
+ session.retract(actionId);
+ // Refused for an entry the server no longer holds means it dispatched
+ // or was removed meanwhile; only one still waiting failed.
+ if (session.waiting(actionId)) markFailed(actionId, true);
+ };
+
+ createEffect(() => {
+ const actionId = ahead();
+ if (actionId !== undefined && !session.waiting(actionId)) {
+ setAhead(undefined);
+ }
+ });
+
+ createEffect(() => {
+ if (ahead() !== undefined) return;
+ const [next, ...rest] = backlog();
+ if (next === undefined) return;
+ setBacklog(rest);
+ setAhead(next);
+ fireAndForget(send(next), 'agent-queue');
+ });
+
+ const steer = (actionId: string) => {
const entry = session.entries().find((item) => item.actionId === actionId);
const action = entry ? actionForQueuedEntry(entry) : undefined;
if (!action) return;
+ markFailed(actionId, false);
session.expect(actionId, action);
- fireAndForget(
- (async () => {
- const accepted = await session.steer(actionId);
- if (!accepted) session.retract(actionId);
- })(),
- 'agent-queue'
- );
+ setBacklog((current) => [...current, actionId]);
+ };
+
+ return {
+ steer,
+ sendNext: () => {
+ const head = session.entries()[0];
+ if (head) steer(head.actionId);
+ },
+ failed,
};
}
diff --git a/apps/web/src/features/block-agent/debug/Gallery.tsx b/apps/web/src/features/block-agent/debug/Gallery.tsx
index 9f01bfd784..07d7a22bd4 100644
--- a/apps/web/src/features/block-agent/debug/Gallery.tsx
+++ b/apps/web/src/features/block-agent/debug/Gallery.tsx
@@ -211,6 +211,12 @@ function QueuedInFlightDemo() {
kind: 'prompt',
prompt: 'Also mention the flush control',
},
+ {
+ actionId: 'refused',
+ kind: 'prompt',
+ prompt: 'This steer was refused, so it stays queued',
+ sendFailed: true,
+ },
]);
const [note, setNote] = createSignal(
'Steer jumps that message ahead. With the box empty, the ringed arrow flushes the queue.'
diff --git a/apps/web/src/features/block-agent/ui/AgentInput.tsx b/apps/web/src/features/block-agent/ui/AgentInput.tsx
index 404d065811..293b42776a 100644
--- a/apps/web/src/features/block-agent/ui/AgentInput.tsx
+++ b/apps/web/src/features/block-agent/ui/AgentInput.tsx
@@ -73,15 +73,6 @@ export interface AgentInputProps {
* stays a send arrow, ringed so it reads as flush rather than a new message.
*/
hasQueuedMessages?: boolean;
- /**
- * Advancing the queue would not advance it right now, so Enter and the
- * button stay inert (the control reads Stop). Either a stop is already on
- * its way - the queue advances when the turn it ends actually ends, so a
- * second stop does nothing but post again - or the prompt that last
- * advanced is still unconfirmed, so there is no turn the server has opened
- * for a stop to end.
- */
- sendNextHeld?: boolean;
/**
* Enter or the send button with an empty input and a queued message. Falls
* back to `onStop`, which is the mechanism: the queue advances when the
@@ -210,23 +201,21 @@ export function AgentInput(props: AgentInputProps) {
// Deliberately not gated on `busy`. A speculated stop reads as done
// everywhere else, so `busy` is already false while the runtime is still
// winding the turn down - and that is exactly when a waiting message is
- // most worth advancing. What does gate it is `sendNextHeld`: a stop already
- // in flight, or a previous advance the log has not confirmed yet. Attached
- // files are something to send in their own right, so they hold it back too.
+ // most worth advancing. Attached files are something to send in their own
+ // right, so they hold it back.
const canSendNext = () =>
!dictation.active() &&
markdown().trim().length === 0 &&
attachments().length === 0 &&
props.hasQueuedMessages === true &&
- !props.sendNextHeld &&
!props.disabled &&
!props.readOnly &&
props.onStop !== undefined;
const sendNext = () => {
if (!canSendNext()) return;
- // Stop bypasses the server queue: the fold shows it at once as a pending
- // Stopped line, and when the runtime ends the cancelled turn the server
+ // Without `onSendNext`, Stop is the mechanism: it bypasses the server
+ // queue, the fold shows it at once as a pending Stopped line, and when the runtime ends the cancelled turn the server
// dispatches the oldest waiting action, so the queue remains FIFO. How
// soon that is depends on the runtime - a booting sandbox cannot be
// interrupted until it is up.
diff --git a/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx b/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx
index fbfae606aa..28e7a8abec 100644
--- a/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx
+++ b/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx
@@ -12,7 +12,8 @@
* are no save/cancel affordances. Non-prompt entries (compact) are
* read-only text but keep their remove affordance, which is always visible.
* While a turn is in flight, each row offers Steer: that message jumps the
- * queue and the current turn is cancelled so it runs next.
+ * queue and the current turn is cancelled so it runs next. A row whose
+ * steer the server refused stays queued and says it was not sent.
*/
import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
@@ -42,6 +43,8 @@ export type QueuedPromptItem = {
attachments?: { name: string; mimeType?: string | null }[];
/** Who queued it, when it was somebody other than the current user. */
queuedBy?: string;
+ /** A force-send of it was refused; it is still queued and can be retried. */
+ sendFailed?: boolean;
};
export interface QueuedPromptsProps {
@@ -218,12 +221,25 @@ function QueuedRow(props: QueuedRowProps) {
/>
<span class="truncate">{preview()}</span>
</button>
- <span class="shrink-0 text-xs text-ink-extra-muted">
- Queued
- <Show when={props.item.queuedBy}>
- {(name) => <> by {name()}</>}
- </Show>
- </span>
+ <Show
+ when={props.item.sendFailed}
+ fallback={
+ <span class="shrink-0 text-xs text-ink-extra-muted">
+ Queued
+ <Show when={props.item.queuedBy}>
+ {(name) => <> by {name()}</>}
+ </Show>
+ </span>
+ }
+ >
+ <span
+ class="shrink-0 text-xs text-failure-ink"
+ role="status"
+ title="This message could not be sent. It is still queued."
+ >
+ Not sent
+ </span>
+ </Show>
<Show when={props.onSteer}>
<Button
variant="ghost"
diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.md
index dce8bbcc79..a3aaa5d56e 100644
--- a/docs/agent-guide/ai-chat.md
+++ b/docs/agent-guide/ai-chat.md
@@ -194,8 +194,8 @@ While an agent works, a draft can be sent to its queue. Above the queue,
message. The empty composer offers the same action as **Flush queued messages**
with a ringed send arrow; with a draft it offers **Send**. Each queued row offers
**Steer** while a turn is running, to interrupt it and send that row next. With no
-draft or queue, the busy composer offers **Stop**. Send-next actions disable and
-Steer is hidden during stopping/starting and for read-only sessions.
+draft or queue, the busy composer offers **Stop**. Send next and Steer stay
+available while a previous one is starting; read-only sessions get neither.
Phone verification: check portrait and landscape with touch emulation. In the
Agents composer, enter multiple lines and tap Send, attach, or the model control;
@@ -1802,12 +1802,12 @@ must stay hidden; subsequent live messages must still appear.
with a ring so it reads as flushing the queue rather than sending a new message);
pressing Enter or clicking that button cancels the current turn so the queue drains
in order, oldest first. Steer on a queued row is the interrupt for that one message;
- flush sends whatever is already next. The advance is held — the flush control is
- disabled and Enter is inert — while a stop is already in flight or while the prompt the last
- advance sent is still unconfirmed (it shows as a pending bubble); once the server
- confirms that prompt as the running turn, Enter advances the queue again. Two rapid
- Enters therefore advance one entry, not two: each advance ends the turn the server is
- actually running. Typed composer text still takes priority and Enter
+ flush sends whatever is already next. Each advance or Steer shows its message as a
+ pending bubble at once and drops its row; consecutive ones never wait on each other in
+ the UI. Their steer requests go out one at a time in press order, each after the
+ previous message leaves the server queue, so three rapid presses send three messages,
+ each once, in that order. A refused steer brings its row back labelled `Not sent`; it
+ stays queued and can be steered again. Typed composer text still takes priority and Enter
queues that new prompt normally.
- The stop button cancels only the **current** turn. The queue keeps draining: the next
queued prompt starts a new turn. To fully quiesce a session, remove the queued