From 89573025fce64c8f20e9729de0a5fffe08f2125e Mon Sep 17 00:00:00 2001 From: Jinhui Zheng Date: Sun, 22 Nov 2026 17:16:23 +0800 Subject: [PATCH 1/2] fix(web): show Queue for running sessions that cannot steer --- .../src/components/ChatView.browser.test.tsx | 41 +++++++++++++++++++ apps/web/src/components/ChatView.tsx | 11 ++--- apps/web/test/fakeEnvironment.ts | 35 ++++++++++++++++ .../src/state/threadWorkflows.test.ts | 35 +++++++++++++++- .../src/state/threadWorkflows.ts | 37 ++++++++++++++--- 5 files changed, 145 insertions(+), 14 deletions(-) diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx index 60c3c24ce5c2d..b4ec8cd4f279a 100644 --- a/apps/web/src/components/ChatView.browser.test.tsx +++ b/apps/web/src/components/ChatView.browser.test.tsx @@ -41,6 +41,7 @@ import { ENVIRONMENT_ID, PROJECT_ID, answerAssetUrls, + attachCodexSession, answerRpc, assistantItem, dispatchedCommands, @@ -706,6 +707,46 @@ it("a rejected send leaves the timeline when a new draft was typed meanwhile", a expect(editor.element().textContent).toContain("Next draft"); }); +it("queues the opposite-action shortcut when the running session cannot steer", async () => { + const history = threadWithHistory("queue-only", 1); + const run = { ...history.runs[0]!, status: "running" as const, completedAt: null }; + using _environment = installFakeEnvironment([{ ...history, runs: [run] }], { + acceptCommands: true, + }); + __setClientSettingsForTests({ + ...DEFAULT_CLIENT_SETTINGS, + followUpBehavior: "queue", + onboardingCompletedAt: "2026-01-01T00:00:00.000Z", + }); + const router = getRouter( + createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${history.id}`] }), + ); + await router.load(); + await using _app = await render(, { + // AppRoot brings its own router. + router: false, + }); + await expect.element(page.getByRole("button", { name: "Stop generation" })).toBeVisible(); + await attachCodexSession(history, { + supportsQueuedMessages: true, + supportsInterrupt: true, + supportsActiveSteering: false, + supportsSteeringByInterruptRestart: false, + }); + await userEvent.click(page.getByTestId("composer-editor")); + await insertText("Queue this follow-up"); + await userEvent.keyboard("{ControlOrMeta>}{Enter}{/ControlOrMeta}"); + await vi.waitFor(() => + expect(dispatchedCommands()).toContainEqual( + expect.objectContaining({ + type: "message.dispatch", + text: "Queue this follow-up", + dispatchMode: { type: "queue_after_active" }, + }), + ), + ); +}); + it("Enter on an empty prompt resumes an interrupted thread", async () => { const history = threadWithHistory("interrupted", 1); const interruptedRun = { ...history.runs[0]!, status: "interrupted" as const }; diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 254bbd4eb9e42..d17af4f620755 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -106,10 +106,9 @@ import { } from "@t3tools/client-runtime/state/subagentRuntime"; import { getUserQueuedThreadRuns, - threadSteersDuringCompaction, + threadCanSteer, threadSupportsProviderHandoff, } from "@t3tools/client-runtime/state/thread-workflows"; -import { compactionBlocksSteering } from "@t3tools/client-runtime/state/composer-dispatch"; import { resolvePendingHandoff } from "@t3tools/client-runtime/handoff"; import { HandoffRow } from "./chat/V2LifecycleRow"; import { @@ -1545,12 +1544,10 @@ export default function ChatView(props: ChatViewProps) { const isCompacting = (isSendBusy || phase === "connecting" || phase === "running") && (compactionRunning || compactCommandIsActive); - const compactionBlocksSteer = compactionBlocksSteering({ + const canSteer = threadCanSteer(serverProjection, { compactCommandIsActive, compactionRunning, - steersDuringCompaction: threadSteersDuringCompaction(serverProjection), - run: serverProjection?.runs.find((run) => run.id === activeRuntime?.activeRunId), - messages: serverProjection?.messages, + activeRunId: activeRuntime?.activeRunId, }); const isWorking = deriveTimelineWorking({ phase, @@ -3822,7 +3819,7 @@ export default function ChatView(props: ChatViewProps) { isLocalDraftThread && activeProject === null } phase={phase} - canSteer={!compactionBlocksSteer} + canSteer={canSteer} canInterrupt={canInterruptRunningThread} isSendBusy={ (isSendBusy && !sendQueuesBehindSetup) || diff --git a/apps/web/test/fakeEnvironment.ts b/apps/web/test/fakeEnvironment.ts index 71e8875bb56db..13a91f37ce91b 100644 --- a/apps/web/test/fakeEnvironment.ts +++ b/apps/web/test/fakeEnvironment.ts @@ -12,8 +12,11 @@ import { OrchestrationV2DispatchCommandError, ORCHESTRATION_PROTOCOL_VERSION, ORCHESTRATION_V2_WS_METHODS, + OrchestrationV2ProviderCapabilities, ProjectId, ProviderInstanceId, + ProviderDriverKind, + ProviderSessionId, RunId, RuntimeRequestId, ServerConfig, @@ -45,6 +48,7 @@ import type { import type { WsRpcProtocolClient } from "@t3tools/client-runtime/rpc"; import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings"; import { APP_VERSION } from "~/branding"; +import * as Arbitrary from "effect/Arbitrary"; import * as DateTime from "effect/DateTime"; import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; @@ -745,6 +749,37 @@ export function runningRun(threadId: ThreadId, id: string, ordinal: number, user }; } +export async function attachCodexSession( + thread: FakeThread, + turns: Partial, +) { + const capabilities = ( + await Effect.runPromise( + Arbitrary.sampleEffect(Arbitrary.schema(OrchestrationV2ProviderCapabilities), { + count: 1, + seed: 1, + }), + ) + )[0]!; + const model = thread.modelSelection ?? MODEL; + await emitThreadEvent(thread.id, { + type: "provider-session.attached", + payload: { + id: ProviderSessionId.make(`${thread.id}-session`), + providerInstanceId: model.instanceId, + driver: ProviderDriverKind.make("codex"), + status: "running", + cwd: project.workspaceRoot, + model: model.model, + capabilities: { ...capabilities, turns: { ...capabilities.turns, ...turns } }, + extensionStatuses: [], + createdAt: AT, + updatedAt: AT, + lastError: null, + }, + }); +} + export { userItem }; export async function emitVcsStatus(event: VcsStatusStreamEvent): Promise { diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts index a4049c7169163..c1c75d347e945 100644 --- a/packages/client-runtime/src/state/threadWorkflows.test.ts +++ b/packages/client-runtime/src/state/threadWorkflows.test.ts @@ -6,6 +6,7 @@ import { deriveThreadQueueWorkflowState, getUserQueuedThreadRuns, resolveLatestMergeBackRun, + threadCanSteer, threadSupportsProviderHandoff, } from "./threadWorkflows.ts"; @@ -13,6 +14,7 @@ const capabilities = (input?: { readonly queued?: boolean; readonly steer?: boolean; readonly restartSteer?: boolean; + readonly interrupt?: boolean; readonly nativeFork?: boolean; readonly portableFork?: boolean; }) => @@ -21,6 +23,7 @@ const capabilities = (input?: { supportsQueuedMessages: input?.queued ?? false, supportsActiveSteering: input?.steer ?? false, supportsSteeringByInterruptRestart: input?.restartSteer ?? false, + supportsInterrupt: input?.interrupt ?? false, }, threads: { canForkThread: input?.nativeFork ?? false, @@ -31,6 +34,36 @@ const capabilities = (input?: { }) as never; describe("thread workflows", () => { + it.each([ + ["queue only", { queued: true }, false, false], + ["session still attaching", undefined, false, true], + ["native steering", { steer: true }, false, true], + ["interrupt and restart", { interrupt: true, restartSteer: true }, false, true], + ["restart without interrupt", { restartSteer: true }, false, false], + ["interrupt without restart", { interrupt: true }, false, false], + ["explicit compaction", { steer: true }, true, false], + ] as const)("gates composer steering for %s", (_, turns, compactCommandIsActive, expected) => { + const projection = { + thread: { id: "thread", activeProviderThreadId: "provider-thread" }, + runs: [{ id: "active", status: "running", providerThreadId: "provider-thread" }], + providerThreads: [{ id: "provider-thread", providerSessionId: "session" }], + providerSessions: [ + ...(turns === undefined + ? [] + : [{ id: "session", status: "running", capabilities: capabilities(turns) }]), + { id: "other", status: "ready", capabilities: capabilities({ steer: true }) }, + ], + messages: [], + } as unknown as OrchestrationV2ThreadProjection; + expect( + threadCanSteer(projection, { + compactCommandIsActive, + compactionRunning: false, + activeRunId: projection.runs[0]!.id, + }), + ).toBe(expected); + }); + it("skips message history classification when no runs are queued", () => { let metadataReads = 0; const message = { @@ -139,7 +172,7 @@ describe("thread workflows", () => { { id: "provider-session", status: "running", - capabilities: capabilities({ queued: true, restartSteer: true }), + capabilities: capabilities({ queued: true, interrupt: true, restartSteer: true }), }, ], } as never); diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts index 7dbbcf1e80c57..9e3d1eb4512b2 100644 --- a/packages/client-runtime/src/state/threadWorkflows.ts +++ b/packages/client-runtime/src/state/threadWorkflows.ts @@ -8,6 +8,7 @@ import { copySorted } from "@t3tools/shared/Array"; import { mFallback, msg } from "gt-i18n"; import type { MFunctionType } from "gt-i18n/types"; +import { compactionBlocksSteering } from "./composerDispatch.ts"; import type { ThreadStructure } from "./models.ts"; type Projection = ThreadStructure; @@ -102,6 +103,33 @@ export function threadSteersDuringCompaction(projection: Projection | null | und ); } +function supportsSteering(turns: OrchestrationV2ProviderCapabilities["turns"]): boolean { + return ( + turns.supportsActiveSteering || + (turns.supportsInterrupt && turns.supportsSteeringByInterruptRestart) + ); +} + +export function threadCanSteer( + projection: Projection | null, + input: { + readonly compactCommandIsActive: boolean; + readonly compactionRunning: boolean; + readonly activeRunId: Run["id"] | null | undefined; + }, +): boolean { + const turns = projection && resolveThreadProviderSession(projection)?.capabilities.turns; + // A steer submitted before the session attaches can wait for its provider turn. + if (turns && !supportsSteering(turns)) return false; + return !compactionBlocksSteering({ + compactCommandIsActive: input.compactCommandIsActive, + compactionRunning: input.compactionRunning, + steersDuringCompaction: turns?.activeSteeringDuringCompaction === true, + run: projection?.runs.find((run) => run.id === input.activeRunId), + messages: projection?.messages, + }); +} + export function threadSupportsProviderHandoff(projection: Projection | null | undefined): boolean { if (projection == null) return false; const session = resolveThreadProviderSession(projection); @@ -147,6 +175,7 @@ export function deriveThreadQueueWorkflowState( const activeRun = resolveActiveThreadRun(projection); const session = resolveThreadProviderSession(projection); const capabilities = session?.capabilities.turns; + const canSteer = capabilities !== undefined && supportsSteering(capabilities); const activeMessage = projection.messages.find( (message) => message.id === activeRun?.userMessageId, ); @@ -187,12 +216,8 @@ export function deriveThreadQueueWorkflowState( canPromoteToSteer: promoteSkipsCompaction || ((activeRun?.status === "preparing" || activeRun?.status === "starting") && - (capabilities === undefined || - capabilities.supportsActiveSteering || - capabilities.supportsSteeringByInterruptRestart)) || - (hasSteerableProviderTurn && - (capabilities?.supportsActiveSteering === true || - capabilities?.supportsSteeringByInterruptRestart === true)), + (capabilities === undefined || canSteer)) || + (hasSteerableProviderTurn && canSteer), promoteSkipsCompaction, }; } From 4ba38ca2e320b8908c55c25e27e716e9a1131a6e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 09:37:43 +0000 Subject: [PATCH 2/2] test: keep steering capability coverage in the client-runtime unit table The browser test and its fake session helper repeated what the threadCanSteer table already proves at a lower layer. Co-Authored-By: Claude Opus 5.5 --- .../src/components/ChatView.browser.test.tsx | 41 ------------------- apps/web/test/fakeEnvironment.ts | 35 ---------------- .../src/state/threadWorkflows.test.ts | 1 - 3 files changed, 77 deletions(-) diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx index b4ec8cd4f279a..60c3c24ce5c2d 100644 --- a/apps/web/src/components/ChatView.browser.test.tsx +++ b/apps/web/src/components/ChatView.browser.test.tsx @@ -41,7 +41,6 @@ import { ENVIRONMENT_ID, PROJECT_ID, answerAssetUrls, - attachCodexSession, answerRpc, assistantItem, dispatchedCommands, @@ -707,46 +706,6 @@ it("a rejected send leaves the timeline when a new draft was typed meanwhile", a expect(editor.element().textContent).toContain("Next draft"); }); -it("queues the opposite-action shortcut when the running session cannot steer", async () => { - const history = threadWithHistory("queue-only", 1); - const run = { ...history.runs[0]!, status: "running" as const, completedAt: null }; - using _environment = installFakeEnvironment([{ ...history, runs: [run] }], { - acceptCommands: true, - }); - __setClientSettingsForTests({ - ...DEFAULT_CLIENT_SETTINGS, - followUpBehavior: "queue", - onboardingCompletedAt: "2026-01-01T00:00:00.000Z", - }); - const router = getRouter( - createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${history.id}`] }), - ); - await router.load(); - await using _app = await render(, { - // AppRoot brings its own router. - router: false, - }); - await expect.element(page.getByRole("button", { name: "Stop generation" })).toBeVisible(); - await attachCodexSession(history, { - supportsQueuedMessages: true, - supportsInterrupt: true, - supportsActiveSteering: false, - supportsSteeringByInterruptRestart: false, - }); - await userEvent.click(page.getByTestId("composer-editor")); - await insertText("Queue this follow-up"); - await userEvent.keyboard("{ControlOrMeta>}{Enter}{/ControlOrMeta}"); - await vi.waitFor(() => - expect(dispatchedCommands()).toContainEqual( - expect.objectContaining({ - type: "message.dispatch", - text: "Queue this follow-up", - dispatchMode: { type: "queue_after_active" }, - }), - ), - ); -}); - it("Enter on an empty prompt resumes an interrupted thread", async () => { const history = threadWithHistory("interrupted", 1); const interruptedRun = { ...history.runs[0]!, status: "interrupted" as const }; diff --git a/apps/web/test/fakeEnvironment.ts b/apps/web/test/fakeEnvironment.ts index 13a91f37ce91b..71e8875bb56db 100644 --- a/apps/web/test/fakeEnvironment.ts +++ b/apps/web/test/fakeEnvironment.ts @@ -12,11 +12,8 @@ import { OrchestrationV2DispatchCommandError, ORCHESTRATION_PROTOCOL_VERSION, ORCHESTRATION_V2_WS_METHODS, - OrchestrationV2ProviderCapabilities, ProjectId, ProviderInstanceId, - ProviderDriverKind, - ProviderSessionId, RunId, RuntimeRequestId, ServerConfig, @@ -48,7 +45,6 @@ import type { import type { WsRpcProtocolClient } from "@t3tools/client-runtime/rpc"; import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings"; import { APP_VERSION } from "~/branding"; -import * as Arbitrary from "effect/Arbitrary"; import * as DateTime from "effect/DateTime"; import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; @@ -749,37 +745,6 @@ export function runningRun(threadId: ThreadId, id: string, ordinal: number, user }; } -export async function attachCodexSession( - thread: FakeThread, - turns: Partial, -) { - const capabilities = ( - await Effect.runPromise( - Arbitrary.sampleEffect(Arbitrary.schema(OrchestrationV2ProviderCapabilities), { - count: 1, - seed: 1, - }), - ) - )[0]!; - const model = thread.modelSelection ?? MODEL; - await emitThreadEvent(thread.id, { - type: "provider-session.attached", - payload: { - id: ProviderSessionId.make(`${thread.id}-session`), - providerInstanceId: model.instanceId, - driver: ProviderDriverKind.make("codex"), - status: "running", - cwd: project.workspaceRoot, - model: model.model, - capabilities: { ...capabilities, turns: { ...capabilities.turns, ...turns } }, - extensionStatuses: [], - createdAt: AT, - updatedAt: AT, - lastError: null, - }, - }); -} - export { userItem }; export async function emitVcsStatus(event: VcsStatusStreamEvent): Promise { diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts index c1c75d347e945..fd8092a996a66 100644 --- a/packages/client-runtime/src/state/threadWorkflows.test.ts +++ b/packages/client-runtime/src/state/threadWorkflows.test.ts @@ -40,7 +40,6 @@ describe("thread workflows", () => { ["native steering", { steer: true }, false, true], ["interrupt and restart", { interrupt: true, restartSteer: true }, false, true], ["restart without interrupt", { restartSteer: true }, false, false], - ["interrupt without restart", { interrupt: true }, false, false], ["explicit compaction", { steer: true }, true, false], ] as const)("gates composer steering for %s", (_, turns, compactCommandIsActive, expected) => { const projection = {