Skip to content
TypeScript

fix(web): Steer no longer does nothing while a compaction runs (#25837)

Theo Brownead068d7c9374
diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts
index d64763aa278..0961ccc2380 100644
--- a/apps/mobile/src/lib/threadActivity.test.ts
+++ b/apps/mobile/src/lib/threadActivity.test.ts
@@ -116,6 +116,77 @@ it("shows a compact command as one mobile divider before, during, and after comp
}
});
+it("shows a skipped compaction as one stopped row, without a separate interrupted row", () => {
+ const prompt = projected({ ...userMessage(), text: "/compact", idleCompaction: "onReturn" }, 0);
+ const compaction = projected(
+ {
+ ...base("compaction", "2026-06-20T00:00:02.000Z", 1),
+ type: "compaction",
+ driver: ProviderDriverKind.make("claude"),
+ status: "interrupted",
+ },
+ 1,
+ );
+ const interrupted = projected(
+ {
+ ...base("interrupt-result", "2026-06-20T00:00:03.000Z", 2),
+ type: "run_interrupt_result",
+ status: "interrupted",
+ message: "Skipped compaction to send a queued message",
+ },
+ 2,
+ );
+ const rows = deriveThreadFeedPresentation(
+ buildThreadFeed([prompt, compaction, interrupted]),
+ {
+ runId,
+ status: "interrupted",
+ startedAt: "2026-06-20T00:00:01.000Z",
+ completedAt: "2026-06-20T00:00:03.000Z",
+ },
+ new Set(),
+ );
+
+ expect(rows.map((entry) => entry.type)).toEqual(["activity-group"]);
+ expect(
+ rows[0]?.type === "activity-group"
+ ? rows[0].activities.map((a) => a.projectedItem.item.type)
+ : null,
+ ).toEqual(["compaction"]);
+});
+
+it("keeps the interrupted row for a compaction stopped before its provider started", () => {
+ const rows = deriveThreadFeedPresentation(
+ buildThreadFeed([
+ projected({ ...userMessage(), text: "/compact" }, 0),
+ projected(
+ {
+ ...base("interrupt-result", "2026-06-20T00:00:03.000Z", 1),
+ type: "run_interrupt_result",
+ status: "interrupted",
+ message: "Run interrupted before provider start",
+ },
+ 1,
+ ),
+ ]),
+ {
+ runId,
+ status: "interrupted",
+ startedAt: "2026-06-20T00:00:01.000Z",
+ completedAt: "2026-06-20T00:00:03.000Z",
+ },
+ new Set(),
+ );
+
+ expect(
+ rows.flatMap((entry) =>
+ entry.type === "activity-group"
+ ? entry.activities.map((activity) => activity.projectedItem.item.type)
+ : [],
+ ),
+ ).toContain("run_interrupt_result");
+});
+
it.each(["/compact", "Continue"])(
"keeps a completed compaction divider visible while other settled work folds for %s",
(promptText) => {
diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts
index 4b92927ae91..0038bc9bf4c 100644
--- a/apps/mobile/src/lib/threadActivity.ts
+++ b/apps/mobile/src/lib/threadActivity.ts
@@ -2175,13 +2175,31 @@ export function buildThreadFeed(
const entries: RawThreadFeedEntry[] = [];
const entryRows: number[] = [];
+ // A stopped compaction's own row already says it stopped. A `/compact` run stopped
+ // before its provider started has no such row, so it keeps the interrupted one.
+ const compactPromptRunIds = new Set<RunId>();
+ const compactedRunIds = new Set<RunId>();
+ for (const { item } of visibleTurnItems) {
+ if (item.runId === null) continue;
+ if (item.type === "user_message" && isCompactionCommandMessage({ role: "user", ...item })) {
+ compactPromptRunIds.add(item.runId);
+ } else if (item.type === "compaction") {
+ compactedRunIds.add(item.runId);
+ }
+ }
for (let index = restart?.row ?? 0; index < visibleTurnItems.length; index += 1) {
const row = visibleTurnItems[index]!;
const item = row.item;
if (turnItemIsWorkspacePreparation(item)) continue;
if (item.type === "todo_list" || item.type === "checkpoint") continue;
if (item.type === "user_message" && foldedAnswerMessageIds.has(item.messageId)) continue;
- if (item.type === "run_interrupt_request") {
+ if (
+ item.type === "run_interrupt_request" ||
+ (item.type === "run_interrupt_result" &&
+ item.runId !== null &&
+ compactPromptRunIds.has(item.runId) &&
+ compactedRunIds.has(item.runId))
+ ) {
continue;
}
const attemptId = resolveAttemptId(item);
diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts
index 716bdc5f9df..e27f32ef844 100644
--- a/apps/server/src/orchestration-v2/Orchestrator.ts
+++ b/apps/server/src/orchestration-v2/Orchestrator.ts
@@ -23,6 +23,7 @@ import {
type ChatAttachment,
CommandId,
type GuestMessageId,
+ isCompactionCommandMessage,
isOrchestrationV2WorkActive,
isProviderNativeSubagentThread,
MessageId,
@@ -5774,13 +5775,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
});
}
if (goalStopRunId !== undefined) {
- return yield* stopRunForGoalCommand({
+ return yield* stopRunForQueuedCommand({
command,
events,
effects,
projection: yield* getProjectionWithPendingEvents(command.threadId, events),
queuedRunId: runId,
targetRunId: goalStopRunId,
+ reason: "Stopped to apply /goal",
now,
});
}
@@ -8355,15 +8357,46 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
(yield* goalDriverFor(command, queuedRun.providerInstanceId)) === undefined
? null
: parsedGoalCommand;
+ const target = projection.runs.find((run) => run.id === command.targetRunId);
+ const targetMessage = projection.messages.find(
+ (message) => message.id === target?.userMessageId,
+ );
+ // A compacting turn cannot take steering input, so steering skips the compaction instead.
+ if (
+ target !== undefined &&
+ targetMessage !== undefined &&
+ isCompactionCommandMessage(targetMessage)
+ ) {
+ if (goalCommand !== null) {
+ yield* ensureGoalCommandSupported(command, queuedMessage, queuedRun.providerInstanceId);
+ }
+ yield* emitEvent({
+ type: "run.updated",
+ threadId: command.threadId,
+ runId: queuedRun.id,
+ nodeId: queuedRootNode.id,
+ providerInstanceId: queuedRun.providerInstanceId,
+ occurredAt: now,
+ payload: { ...queuedRun, queuePosition: 1 },
+ });
+ const stops =
+ isLiveRun(target) && !(yield* stopReachedRun(command, command.threadId, target.id));
+ return yield* stopRunForQueuedCommand({
+ command,
+ events,
+ effects,
+ projection,
+ queuedRunId: queuedRun.id,
+ targetRunId: stops ? target.id : undefined,
+ reason: "Skipped compaction to send a queued message",
+ now,
+ });
+ }
if (goalCommand !== null) {
yield* ensureGoalCommandSupported(command, queuedMessage, queuedRun.providerInstanceId);
- const target = projection.runs.find((run) => run.id === command.targetRunId);
const goal = projection.providerThreads.find(
(candidate) => candidate.id === target?.providerThreadId,
)?.goal;
- const targetMessage = projection.messages.find(
- (message) => message.id === target?.userMessageId,
- );
yield* emitEvent({
type: "run.updated",
threadId: command.threadId,
@@ -8379,13 +8412,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
goalCommandStopsActiveRun(goalCommand, goal?.status ?? null) &&
(targetMessage === undefined || !isNativeMaintenanceCommand(targetMessage)) &&
!(yield* stopReachedRun(command, command.threadId, target.id));
- return yield* stopRunForGoalCommand({
+ return yield* stopRunForQueuedCommand({
command,
events,
effects,
projection,
queuedRunId: queuedRun.id,
targetRunId: stops ? target.id : undefined,
+ reason: "Stopped to apply /goal",
now,
});
}
@@ -10496,71 +10530,74 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
);
/** Puts a queued goal command first and, given a target, stops the run in its way. */
- const stopRunForGoalCommand = Effect.fn("Orchestrator.stopRunForGoalCommand")(function* (input: {
- readonly command: Extract<
- OrchestrationV2Command,
- { readonly type: "message.dispatch" | "queued-message.promote-to-steer" }
- >;
- readonly events: Ref.Ref<Array<OrchestrationV2DomainEvent>>;
- readonly effects: Ref.Ref<Array<PendingOrchestrationEffectV2>>;
- readonly projection: Pick<OrchestrationV2ThreadProjection, "runs" | "messages">;
- readonly queuedRunId: RunId;
- readonly targetRunId: RunId | undefined;
- readonly now: DateTime.Utc;
- }) {
- const { command, events, effects, projection, now, targetRunId } = input;
- const others = queuedRunsInDeliveryOrder(projection).filter(
- (run) => run.id !== input.queuedRunId && !isAutomaticCompletionRun(projection, run),
- );
- for (const [index, run] of others.entries()) {
- const queuePosition = index + 2;
- if (run.queuePosition === queuePosition) continue;
- yield* emit(
- events,
- command,
- )({
- type: "run.updated",
- threadId: command.threadId,
- runId: run.id,
- ...(run.rootNodeId === null ? {} : { nodeId: run.rootNodeId }),
- providerInstanceId: run.providerInstanceId,
- occurredAt: now,
- payload: { ...run, queuePosition },
- });
- }
- if (targetRunId === undefined) return undefined;
- const interruptEvents = yield* Ref.make<Array<OrchestrationV2DomainEvent>>([]);
- const interruptEffects = yield* Ref.make<Array<PendingOrchestrationEffectV2>>([]);
- const interrupted = yield* Effect.exit(
- dispatchRunInterrupt(
- {
- type: "run.interrupt",
- commandId: command.commandId,
+ const stopRunForQueuedCommand = Effect.fn("Orchestrator.stopRunForQueuedCommand")(
+ function* (input: {
+ readonly command: Extract<
+ OrchestrationV2Command,
+ { readonly type: "message.dispatch" | "queued-message.promote-to-steer" }
+ >;
+ readonly events: Ref.Ref<Array<OrchestrationV2DomainEvent>>;
+ readonly effects: Ref.Ref<Array<PendingOrchestrationEffectV2>>;
+ readonly projection: Pick<OrchestrationV2ThreadProjection, "runs" | "messages">;
+ readonly queuedRunId: RunId;
+ readonly targetRunId: RunId | undefined;
+ readonly reason: string;
+ readonly now: DateTime.Utc;
+ }) {
+ const { command, events, effects, projection, now, targetRunId } = input;
+ const others = queuedRunsInDeliveryOrder(projection).filter(
+ (run) => run.id !== input.queuedRunId && !isAutomaticCompletionRun(projection, run),
+ );
+ for (const [index, run] of others.entries()) {
+ const queuePosition = index + 2;
+ if (run.queuePosition === queuePosition) continue;
+ yield* emit(
+ events,
+ command,
+ )({
+ type: "run.updated",
+ threadId: command.threadId,
+ runId: run.id,
+ ...(run.rootNodeId === null ? {} : { nodeId: run.rootNodeId }),
+ providerInstanceId: run.providerInstanceId,
+ occurredAt: now,
+ payload: { ...run, queuePosition },
+ });
+ }
+ if (targetRunId === undefined) return undefined;
+ const interruptEvents = yield* Ref.make<Array<OrchestrationV2DomainEvent>>([]);
+ const interruptEffects = yield* Ref.make<Array<PendingOrchestrationEffectV2>>([]);
+ const interrupted = yield* Effect.exit(
+ dispatchRunInterrupt(
+ {
+ type: "run.interrupt",
+ commandId: command.commandId,
+ threadId: command.threadId,
+ runId: targetRunId,
+ reason: input.reason,
+ },
+ interruptEvents,
+ interruptEffects,
+ ),
+ );
+ // A failed interrupt may have written part of its events, so they are kept apart.
+ // The queued command then waits for the turn to end.
+ if (Exit.isFailure(interrupted)) {
+ yield* Effect.logWarning("queued command could not stop the running turn", {
threadId: command.threadId,
runId: targetRunId,
- reason: "Stopped to apply /goal",
- },
- interruptEvents,
- interruptEffects,
- ),
- );
- // A failed interrupt may have written part of its events, so they are kept apart.
- // The goal command then waits for the turn to end.
- if (Exit.isFailure(interrupted)) {
- yield* Effect.logWarning("goal command could not stop the running turn", {
- threadId: command.threadId,
- runId: targetRunId,
- cause: interrupted.cause,
- });
- return undefined;
- }
- const written = yield* Ref.get(interruptEvents);
- const enqueued = yield* Ref.get(interruptEffects);
- yield* Ref.update(events, (existing) => [...existing, ...written]);
- yield* Ref.update(effects, (existing) => [...existing, ...enqueued]);
- // Like Stop: a run stopped before its provider started also abandons that start.
- return interrupted.value;
- });
+ cause: interrupted.cause,
+ });
+ return undefined;
+ }
+ const written = yield* Ref.get(interruptEvents);
+ const enqueued = yield* Ref.get(interruptEffects);
+ yield* Ref.update(events, (existing) => [...existing, ...written]);
+ yield* Ref.update(effects, (existing) => [...existing, ...enqueued]);
+ // Like Stop: a run stopped before its provider started also abandons that start.
+ return interrupted.value;
+ },
+ );
const dispatchThreadStop = Effect.fn("Orchestrator.dispatchThreadStop")(function* (
command: Extract<OrchestrationV2ServerCommand, { readonly type: "thread.stop" }>,
diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
index 2cc6ee6f825..4c2d6712c5a 100644
--- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
@@ -429,6 +429,29 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
openSession: (input) =>
Effect.gen(function* () {
const now = yield* DateTime.now;
+ const startTurn = (turn: ProviderAdapter.ProviderAdapterV2TurnInput) =>
+ Effect.gen(function* () {
+ started.push(turn);
+ yield* Queue.offer(events, {
+ type: "provider_turn.updated",
+ driver,
+ providerTurn: {
+ id: ProviderTurnId.make(`provider-turn:${turn.attemptId}`),
+ providerThreadId: turn.providerThread.id,
+ nodeId: turn.rootNodeId,
+ runAttemptId: turn.attemptId,
+ nativeTurnRef: {
+ driver,
+ nativeId: `native:${turn.attemptId}`,
+ strength: "strong",
+ },
+ ordinal: turn.providerTurnOrdinal,
+ status: "running",
+ startedAt: now,
+ completedAt: null,
+ },
+ });
+ });
return {
instanceId,
driver,
@@ -465,29 +488,8 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
updatedAt: now,
}),
resumeThread: ({ providerThread }) => Effect.succeed(providerThread),
- startTurn: (turn) =>
- Effect.gen(function* () {
- started.push(turn);
- yield* Queue.offer(events, {
- type: "provider_turn.updated",
- driver,
- providerTurn: {
- id: ProviderTurnId.make(`provider-turn:${turn.attemptId}`),
- providerThreadId: turn.providerThread.id,
- nodeId: turn.rootNodeId,
- runAttemptId: turn.attemptId,
- nativeTurnRef: {
- driver,
- nativeId: `native:${turn.attemptId}`,
- strength: "strong",
- },
- ordinal: turn.providerTurnOrdinal,
- status: "running",
- startedAt: now,
- completedAt: null,
- },
- });
- }),
+ startTurn,
+ compactThread: startTurn,
steerTurn: (turn) =>
Effect.sync(() => {
steered.push(turn.message.text);
@@ -1167,6 +1169,96 @@ it.effect("promotes a queued goal by stopping the running turn", () =>
),
);
+it.effect.each(["next", "/goal ship it"])(
+ "promoting %s into a compaction stops it and sends it next",
+ (promoted) =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ const { events, layer, send, read, started, steered, startFirstTurn } = yield* goalHarness(
+ `compaction-promote-${promoted.length}`,
+ );
+ yield* Effect.gen(function* () {
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
+ const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
+ const threadId = yield* startFirstTurn;
+ yield* send("compact", "/compact", "queue");
+ yield* send("queued", "queued", "queue");
+ yield* send("next", promoted, "queue");
+ const settled = yield* orchestrator.streamDomainEvents.pipe(
+ Stream.filter(
+ (event) =>
+ event.type === "run.updated" &&
+ event.payload.id === started[0]!.runId &&
+ event.payload.status === "waiting",
+ ),
+ Stream.take(1),
+ Stream.runDrain,
+ Effect.forkScoped,
+ );
+ const compacting = yield* orchestrator.streamDomainEvents.pipe(
+ Stream.filter(
+ (event) =>
+ event.type === "provider-turn.updated" &&
+ event.payload.status === "running" &&
+ event.payload.runAttemptId !== started[0]!.attemptId,
+ ),
+ Stream.take(1),
+ Stream.runDrain,
+ Effect.forkScoped,
+ );
+ const turn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns[0]!;
+ yield* Queue.offer(events, {
+ type: "provider_turn.updated",
+ driver,
+ providerTurn: { ...turn, status: "completed", completedAt: yield* DateTime.now },
+ });
+ yield* Queue.offer(events, {
+ type: "turn.terminal",
+ driver,
+ providerThreadId: turn.providerThreadId,
+ providerTurnId: turn.id,
+ runOrdinal: started[0]!.runOrdinal,
+ status: "completed",
+ failure: null,
+ threadDisposition: "reusable",
+ });
+ yield* Fiber.join(settled);
+ yield* worker.drain();
+ yield* orchestrator.resumeQueuedRuns;
+ yield* worker.drain();
+ yield* Fiber.join(compacting);
+ const compactRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
+ (run) => run.userMessageId === MessageId.make("message:compact"),
+ )!;
+ const nextRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
+ (run) => run.userMessageId === MessageId.make("message:next"),
+ )!;
+ yield* orchestrator.dispatch({
+ type: "queued-message.promote-to-steer",
+ commandId: CommandId.make("promote"),
+ threadId,
+ queuedRunId: nextRun.id,
+ targetRunId: compactRun.id,
+ });
+ yield* worker.drain();
+
+ const projection = yield* orchestrator.getThreadProjection(threadId);
+ assert.deepEqual(steered, []);
+ assert.isTrue(
+ projection.turnItems.some(
+ (item) => item.type === "run_interrupt_request" && item.runId === compactRun.id,
+ ),
+ );
+ assert.deepEqual((yield* read(threadId)).queue, ["queued"]);
+ assert.deepEqual(
+ started.map((turn) => turn.message.text),
+ ["first", "/compact", promoted],
+ );
+ }).pipe(Effect.provide(layer));
+ }),
+ ),
+);
+
it.effect("stops a turn that is still starting when a goal is sent into it", () =>
Effect.scoped(
Effect.gen(function* () {
diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
index 2fae89baadc..169acd8630d 100644
--- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
@@ -800,6 +800,62 @@ describe("deriveMessagesTimelineRows", () => {
);
});
+ it("shows a skipped compaction as stopped, without a separate interrupted divider", () => {
+ const fixture = makeStreamingTimelineFixture();
+ const [history0, history1, history2, liveUser, , liveAssistant] = fixture.visibleTurnItems;
+ if (liveUser?.item.type !== "user_message" || liveAssistant?.item.type !== "assistant_message")
+ throw new Error("Expected live fixture items");
+ const prompt = {
+ ...liveUser,
+ item: { ...liveUser.item, text: "/compact", idleCompaction: "onReturn" as const },
+ };
+ const compaction = {
+ ...liveAssistant,
+ item: {
+ ...liveAssistant.item,
+ type: "compaction" as const,
+ status: "interrupted" as const,
+ driver: null,
+ },
+ };
+ const interruptResult = {
+ ...liveAssistant,
+ item: {
+ ...liveAssistant.item,
+ id: TurnItemId.make("interrupt-result"),
+ type: "run_interrupt_result" as const,
+ status: "interrupted" as const,
+ message: "Skipped compaction to send a queued message",
+ },
+ };
+ const liveRowsFor = (visibleTurnItems: OrchestrationV2ProjectedTurnItem[]) => {
+ const rows = deriveMessagesTimelineRows({
+ timelineEntries: deriveTimelineEntriesFromVisibleTurnItems({
+ visibleTurnItems: [history0!, history1!, history2!, ...visibleTurnItems],
+ optimisticMessages: [],
+ }),
+ isWorking: false,
+ latestRun: {
+ runId: fixture.runId,
+ status: "interrupted",
+ startedAt: fixture.time(5),
+ completedAt: fixture.time(9),
+ },
+ turnDiffSummaries: [],
+ supportsConversationRollback: false,
+ });
+ return rows.slice(rows.findIndex((row) => row.id.includes("history-assistant")) + 1);
+ };
+
+ expect(liveRowsFor([prompt, compaction, interruptResult])).toMatchObject([
+ { kind: "context-compaction", label: "Context compaction stopped" },
+ ]);
+ // Stopped before the provider started: no compaction row says so, so the interrupt stays.
+ expect(liveRowsFor([prompt, interruptResult]).map((row) => row.id)).toContain(
+ "interrupt-result",
+ );
+ });
+
it("only enables assistant copy for the terminal assistant message in a turn", () => {
const rows = deriveMessagesTimelineRows({
timelineEntries: [
diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts
index 3780d6b05eb..0648d1832f0 100644
--- a/apps/web/src/components/chat/MessagesTimeline.logic.ts
+++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts
@@ -1664,9 +1664,14 @@ export function deriveMessagesTimelineRows(input: {
appendActiveWorkRows();
}
+ // A stopped compaction's own divider already says it stopped.
if (
timelineEntry.kind === "event" &&
- timelineEntry.projectedItem.item.type === "run_interrupt_request"
+ (timelineEntry.projectedItem.item.type === "run_interrupt_request" ||
+ (timelineEntry.projectedItem.item.type === "run_interrupt_result" &&
+ timelineEntry.projectedItem.item.runId !== null &&
+ compactionRuns.has(timelineEntry.projectedItem.item.runId) &&
+ compactedRunIds.has(timelineEntry.projectedItem.item.runId)))
) {
continue;
}
diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx
index 7dff9b19b59..763d3ab435e 100644
--- a/apps/web/src/components/chat/QueuedRunsControl.tsx
+++ b/apps/web/src/components/chat/QueuedRunsControl.tsx
@@ -297,7 +297,7 @@ export function QueuedRunsControl({
</Button>
</TooltipTrigger>
<TooltipPopup>
- {`${workflow?.canSendNow ? "Start a turn with this message" : "Send into the current turn"}${item.serverIndex === 0 && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`}
+ {`${workflow?.canSendNow ? "Start a turn with this message" : workflow?.promoteSkipsCompaction ? "Skip compaction and send this message" : "Send into the current turn"}${item.serverIndex === 0 && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`}
</TooltipPopup>
</Tooltip>
<Separator orientation="vertical" className="mx-2 h-4" />
diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts
index d22b4c97b38..51f4d5a9e46 100644
--- a/packages/client-runtime/src/state/threadWorkflows.test.ts
+++ b/packages/client-runtime/src/state/threadWorkflows.test.ts
@@ -174,6 +174,26 @@ describe("thread workflows", () => {
},
);
+ it("offers to skip a running compaction even when the provider cannot steer", () => {
+ const state = deriveThreadQueueWorkflowState({
+ thread: { id: "thread", activeProviderThreadId: null },
+ runs: [
+ { id: "compact", status: "running", userMessageId: "message-compact", ordinal: 1 },
+ { id: "queued", status: "queued", userMessageId: "message-queued", ordinal: 2 },
+ ],
+ messages: [
+ { id: "message-compact", role: "user", text: "/compact", attachments: [] },
+ { id: "message-queued", role: "user", text: "Next", attachments: [] },
+ ],
+ providerThreads: [],
+ providerTurns: [],
+ providerSessions: [],
+ } as never);
+
+ expect(state.canPromoteToSteer).toBe(true);
+ expect(state.promoteSkipsCompaction).toBe(true);
+ });
+
it("keeps held messages visible and clears the hold when they leave the queue", () => {
for (const status of ["queued", "cancelled", "starting"] as const) {
const state = deriveThreadQueueWorkflowState({
diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts
index 1a47d134bf5..33bad92dab2 100644
--- a/packages/client-runtime/src/state/threadWorkflows.ts
+++ b/packages/client-runtime/src/state/threadWorkflows.ts
@@ -1,7 +1,8 @@
-import type {
- ChatAttachment,
- OrchestrationV2ProjectedTurnItem,
- OrchestrationV2ProviderCapabilities,
+import {
+ type ChatAttachment,
+ isCompactionCommandMessage,
+ type OrchestrationV2ProjectedTurnItem,
+ type OrchestrationV2ProviderCapabilities,
} from "@t3tools/contracts";
import { copySorted } from "@t3tools/shared/Array";
@@ -33,6 +34,8 @@ export interface ThreadQueueWorkflowState {
readonly queuedRuns: ReadonlyArray<QueuedThreadRun>;
readonly isHeld: boolean;
readonly canPromoteToSteer: boolean;
+ /** The active run is a compaction, so promoting a queued message stops it instead of steering. */
+ readonly promoteSkipsCompaction: boolean;
readonly canSendNow: boolean;
}
@@ -127,6 +130,11 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu
const activeRun = resolveActiveThreadRun(projection);
const session = resolveThreadProviderSession(projection);
const capabilities = session?.capabilities.turns;
+ const activeMessage = projection.messages.find(
+ (message) => message.id === activeRun?.userMessageId,
+ );
+ const promoteSkipsCompaction =
+ activeMessage !== undefined && isCompactionCommandMessage(activeMessage);
const hasSteerableProviderTurn =
activeRun?.status === "running" &&
activeRun.activeAttemptId !== null &&
@@ -159,9 +167,11 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu
projection.thread.archivedAt == null &&
projection.thread.deletedAt == null,
canPromoteToSteer:
- hasSteerableProviderTurn &&
- (capabilities?.supportsActiveSteering === true ||
- capabilities?.supportsSteeringByInterruptRestart === true),
+ promoteSkipsCompaction ||
+ (hasSteerableProviderTurn &&
+ (capabilities?.supportsActiveSteering === true ||
+ capabilities?.supportsSteeringByInterruptRestart === true)),
+ promoteSkipsCompaction,
};
}