Skip to content

Commit 5f43681

Browse files
only21milmaria-rcksjuliusmarminge
authored
fix(client): hide Resume while a pending request blocks continuing the run (#28810)
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 39ab6a2 commit 5f43681

7 files changed

Lines changed: 90 additions & 5 deletions

File tree

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,7 @@ function ThreadRouteContent(
10711071
onRemoveDraftImage={composer.onRemoveDraftImage}
10721072
serverConfig={serverConfig}
10731073
onStopThread={awaitingBootstrapTurn ? handleCancelWorktreeSetup : handleStopThread}
1074-
onResumeQueue={
1075-
composer.queueHeld || composer.resumableRunId !== null ? handleResumeQueue : null
1076-
}
1074+
onResumeQueue={composer.canResume ? handleResumeQueue : null}
10771075
onSendMessage={composer.onSendMessage}
10781076
offersSideChat={composer.sideChatUnavailableReason === null}
10791077
onReconnectEnvironment={handleReconnectEnvironment}

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
isDetailBehindShell,
1414
} from "@t3tools/client-runtime/state/thread-activity-announcement";
1515
import {
16+
canResumeThread,
1617
deriveProviderSubagentStatus,
1718
deriveProviderExtensionStatuses,
1819
deriveResumableRunId,
@@ -401,6 +402,9 @@ export function useThreadComposerState(input: {
401402
const resumableRunId = selectedThreadProjection
402403
? deriveResumableRunId(selectedThreadProjection.projection, selectedThreadRuntime)
403404
: null;
405+
const canResume = selectedThreadProjection
406+
? canResumeThread(selectedThreadProjection.projection, resumableRunId, queueHeld)
407+
: queueHeld;
404408

405409
const runlessWorkStartedAt = selectedThreadProjection
406410
? deriveRunlessWorkStartedAt(selectedThreadProjection.projection)
@@ -919,6 +923,7 @@ export function useThreadComposerState(input: {
919923
canSteerActiveTurn,
920924
queueHeld,
921925
resumableRunId,
926+
canResume,
922927
queuedRunEdit,
923928
isSavingQueuedEdit,
924929
cancelQueuedRunEdit,

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
RuntimeMode,
7979
} from "@t3tools/contracts";
8080
import {
81+
canResumeThread,
8182
deriveProviderSubagentStatus,
8283
deriveProviderExtensionStatuses,
8384
deriveReportedModelSelection,
@@ -840,6 +841,9 @@ export default function ChatView(props: ChatViewProps) {
840841
!isServerThread || serverProjection === null
841842
? null
842843
: deriveResumableRunId(serverProjection, serverRuntime);
844+
const canResume =
845+
serverProjection !== null &&
846+
canResumeThread(serverProjection, resumableRunId, hasHeldQueuedRuns);
843847
const parentSubagentThreadId =
844848
activeThread?.lineage.relationshipToParent === "subagent"
845849
? activeThread.lineage.parentThreadId
@@ -2882,6 +2886,7 @@ export default function ChatView(props: ChatViewProps) {
28822886
activeThread,
28832887
resumableRunId,
28842888
hasHeldQueuedRuns,
2889+
canResume,
28852890
isSendBusy,
28862891
isRevertingCheckpoint,
28872892
threadDetailLoading,
@@ -3626,7 +3631,7 @@ export default function ChatView(props: ChatViewProps) {
36263631
queuedRunEdit.isSaving ||
36273632
isResuming
36283633
}
3629-
canResume={resumableRunId !== null || hasHeldQueuedRuns}
3634+
canResume={canResume}
36303635
isRevertingCheckpoint={isRevertingCheckpoint}
36313636
sendDisabledReason={
36323637
!canOperateThread

‎apps/web/src/components/chat/useComposerResume.browser.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function ResumeButton(props: {
5252
activeThread: { id: threadA } as never,
5353
resumableRunId: RunId.make("run:interrupted"),
5454
hasHeldQueuedRuns: false,
55+
canResume: true,
5556
isSendBusy: false,
5657
isRevertingCheckpoint: false,
5758
threadDetailLoading: false,

‎apps/web/src/components/chat/useComposerResume.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface ComposerResumeInput {
2828
readonly activeThread: EnvironmentThreadShell | undefined;
2929
readonly resumableRunId: RunId | null;
3030
readonly hasHeldQueuedRuns: boolean;
31+
readonly canResume: boolean;
3132
readonly isSendBusy: boolean;
3233
readonly isRevertingCheckpoint: boolean;
3334
readonly threadDetailLoading: boolean;
@@ -59,6 +60,7 @@ export function useComposerResume(input: ComposerResumeInput) {
5960
activeThread,
6061
resumableRunId,
6162
hasHeldQueuedRuns,
63+
canResume,
6264
isSendBusy,
6365
isRevertingCheckpoint,
6466
threadDetailLoading,
@@ -86,7 +88,7 @@ export function useComposerResume(input: ComposerResumeInput) {
8688
const onResume = async () => {
8789
if (
8890
!activeThread ||
89-
(resumableRunId === null && !hasHeldQueuedRuns) ||
91+
!canResume ||
9092
isSendBusy ||
9193
isResuming ||
9294
isRevertingCheckpoint ||

‎packages/client-runtime/src/state/threadExecution.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {
99
ProviderTurnId,
1010
RunAttemptId,
1111
RunId,
12+
RuntimeRequestId,
1213
ThreadId,
1314
type OrchestrationV2ExecutionNode,
1415
type OrchestrationV2RunStatus,
16+
type OrchestrationV2RuntimeRequest,
1517
} from "@t3tools/contracts";
1618
import * as DateTime from "effect/DateTime";
1719
import { createModelCapabilities, createModelSelection } from "@t3tools/shared/model";
@@ -20,6 +22,7 @@ import { describe, expect, it } from "vite-plus/test";
2022

2123
import { v2Projection } from "./orchestrationV2TestFixtures.ts";
2224
import {
25+
canResumeThread,
2326
deriveReportedModelSelection,
2427
deriveLatestThreadRun,
2528
deriveProviderSubagentStatus,
@@ -38,6 +41,23 @@ import {
3841

3942
const now = DateTime.makeUnsafe("2026-07-28T10:00:00.000Z");
4043

44+
function request(
45+
id: string,
46+
status: OrchestrationV2RuntimeRequest["status"],
47+
): OrchestrationV2RuntimeRequest {
48+
return {
49+
id: RuntimeRequestId.make(id),
50+
nodeId: NodeId.make(`node-${id}`),
51+
providerTurnId: null,
52+
nativeRequestRef: null,
53+
kind: "command",
54+
status,
55+
responseCapability: { type: "not_resumable", reason: "Session ended." },
56+
createdAt: now,
57+
resolvedAt: status === "pending" ? null : now,
58+
};
59+
}
60+
4161
function run(id: string, ordinal: number, status: OrchestrationV2RunStatus) {
4262
return {
4363
id: RunId.make(id),
@@ -369,6 +389,47 @@ describe("thread execution presentation", () => {
369389
expect(deriveThreadRuntime(onlyHeld)).toBeNull();
370390
});
371391

392+
it.each([
393+
{ name: "no requests", requests: [], runId: "run-stopped", held: false, expected: true },
394+
{
395+
name: "a pending request",
396+
requests: [request("approval", "pending")],
397+
runId: "run-stopped",
398+
held: false,
399+
expected: false,
400+
},
401+
{
402+
name: "only a resolved request",
403+
requests: [request("approval", "resolved")],
404+
runId: "run-stopped",
405+
held: false,
406+
expected: true,
407+
},
408+
{
409+
name: "a held queue behind a blocked continuation",
410+
requests: [request("approval", "pending")],
411+
runId: "run-stopped",
412+
held: true,
413+
expected: false,
414+
},
415+
{
416+
name: "a held queue with no run to continue",
417+
requests: [request("approval", "pending")],
418+
runId: null,
419+
held: true,
420+
expected: true,
421+
},
422+
{ name: "nothing to resume", requests: [], runId: null, held: false, expected: false },
423+
])("decides whether Resume can start with $name", ({ requests, runId, held, expected }) => {
424+
expect(
425+
canResumeThread(
426+
{ runtimeRequests: requests },
427+
runId === null ? null : RunId.make(runId),
428+
held,
429+
),
430+
).toBe(expected);
431+
});
432+
372433
it("does not expose a queued-only run as interruptible", () => {
373434
const queuedRun = run("run-queued", 1, "queued");
374435
const projection = { ...v2Projection, runs: [queuedRun], updatedAt: now };

‎packages/client-runtime/src/state/threadExecution.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ export function deriveResumableRunId(
319319
: null;
320320
}
321321

322+
/**
323+
* Whether Resume can start: the run's continuation, else the held queue. The server refuses that
324+
* continuation while any request is pending, so the queue must not be released in its place.
325+
*/
326+
export function canResumeThread(
327+
projection: Pick<ThreadStructure, "runtimeRequests">,
328+
resumableRunId: RunId | null,
329+
queueHeld: boolean,
330+
): boolean {
331+
if (resumableRunId === null) return queueHeld;
332+
return !projection.runtimeRequests.some((request) => request.status === "pending");
333+
}
334+
322335
export function deriveThreadRuntime(
323336
projection: ThreadStructure & Pick<OrchestrationV2ThreadProjection, "updatedAt">,
324337
): ThreadRuntimeSummary | null {

0 commit comments

Comments
 (0)