Skip to content

Commit bc1a4ae

Browse files
fix(web,mobile): resume a blocked goal from the goal line (#112)
* fix(web,mobile): resume a blocked goal from the goal line Web hid Resume while the agent worked, leaving only Clear. Resume now shows whenever the goal is paused or blocked; while working it queues /goal resume behind the current turn instead of stopping it. Mobile's goal row gains the same Resume action. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(mobile): keep goal resume available during active turns * fix: queue goal resume safely and persist mobile run modes * test(server): pin queued goal stop policy --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6d4d152 commit bc1a4ae

11 files changed

Lines changed: 221 additions & 88 deletions

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export interface ThreadDetailScreenProps {
298298
readonly onNativePasteText: (paste: ComposerTextPaste) => Promise<void>;
299299
readonly onRemoveDraftImage: (imageId: string) => void;
300300
readonly onStopThread: () => void;
301+
readonly onResumeGoal?: () => Promise<void>;
301302
/** Present while the thread's queue is held. */
302303
readonly onResumeQueue: (() => Promise<void>) | null;
303304
readonly offersSideChat: boolean;
@@ -840,8 +841,27 @@ function ThreadDetailBody(
840841
if (props.isCompacting && contentPresentationKind === "ready") {
841842
return { kind: "compacting" };
842843
}
844+
const goal =
845+
props.selectedThread.goal === null
846+
? null
847+
: presentProviderGoal(props.selectedThread.goal, props.activeWorkStartedAt !== null);
848+
const onResumeGoal = props.onResumeGoal;
849+
const goalAction =
850+
goal?.canResume && onResumeGoal !== undefined
851+
? {
852+
label: props.activeWorkStartedAt !== null ? "Resume after turn" : "Resume",
853+
accessibilityLabel:
854+
props.activeWorkStartedAt !== null ? "Resume goal after turn" : "Resume goal",
855+
disabled: !props.canOperateThread,
856+
onPress: () => void onResumeGoal(),
857+
}
858+
: null;
843859
if (props.activeWorkStartedAt !== null && contentPresentationKind === "ready") {
844-
return { kind: "working", startedAt: props.activeWorkStartedAt };
860+
return {
861+
kind: "working",
862+
startedAt: props.activeWorkStartedAt,
863+
action: goalAction,
864+
};
845865
}
846866
if (props.selectedThread.groupDiscussionOpen && contentPresentationKind === "ready") {
847867
return { kind: "preparing", label: "Group discussion" };
@@ -897,12 +917,12 @@ function ThreadDetailBody(
897917
},
898918
};
899919
}
900-
if (props.selectedThread.goal !== null && contentPresentationKind === "ready") {
901-
const goal = presentProviderGoal(props.selectedThread.goal, false);
920+
if (goal !== null && contentPresentationKind === "ready") {
902921
return {
903922
kind: "goal",
904923
label: goal.title,
905924
accessibilityLabel: `${goal.title}: ${goal.objective}`,
925+
action: goalAction,
906926
};
907927
}
908928
if (extensionStatus !== null && contentPresentationKind === "ready") {

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ import {
111111
threadRouteOpensDraft,
112112
} from "./thread-route-hydration";
113113
import { ThreadHeader } from "./ThreadHeader";
114-
import { resumeThread } from "./resume-thread";
114+
import { continueThread, resumeThread } from "./resume-thread";
115115
import {
116116
useAndroidWorkspaceBack,
117117
useWorkspaceBackNavigation,
@@ -707,6 +707,26 @@ function ThreadRouteContent(
707707
}
708708
};
709709

710+
const handleResumeGoal = async () => {
711+
if (!selectedThread) return;
712+
const result = await continueThread({
713+
thread: selectedThread,
714+
continuation: { kind: "goal" },
715+
runtimeMode: composer.runtimeMode ?? selectedThread.runtimeMode,
716+
interactionMode: composer.interactionMode ?? selectedThread.interactionMode,
717+
modelSelection: composer.modelSelection,
718+
messageId: MessageId.make(uuidv4()),
719+
createdAt: new Date().toISOString(),
720+
setRuntimeMode: setThreadRuntimeMode,
721+
setInteractionMode: setThreadInteractionMode,
722+
startTurn: continueThreadRun,
723+
});
724+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
725+
const error = squashAtomCommandFailure(result);
726+
Dialog.alert("Could not resume goal", error instanceof Error ? error.message : "Try again.");
727+
}
728+
};
729+
710730
const handleOpenTerminal = (nextTerminalId?: string | null) => {
711731
if (
712732
!selectedThread ||
@@ -1090,6 +1110,7 @@ function ThreadRouteContent(
10901110
onRemoveDraftImage={composer.onRemoveDraftImage}
10911111
serverConfig={serverConfig}
10921112
onStopThread={awaitingBootstrapTurn ? handleCancelWorktreeSetup : handleStopThread}
1113+
onResumeGoal={handleResumeGoal}
10931114
onResumeQueue={
10941115
composer.queueHeld || composer.resumableRunId !== null ? handleResumeQueue : null
10951116
}

‎apps/mobile/src/features/threads/floating-working-control.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ export function FloatingWorkingControl(props: {
9090
const extensionOnly = props.status?.kind === "extension";
9191
const useGlass = NATIVE_LIQUID_GLASS_SUPPORTED && !extensionOnly;
9292
const action =
93+
props.status?.kind === "working" ||
9394
props.status?.kind === "background" ||
9495
props.status?.kind === "lifecycle" ||
95-
props.status?.kind === "stop"
96+
props.status?.kind === "stop" ||
97+
props.status?.kind === "goal"
9698
? props.status.action
9799
: null;
98100
const [agentsWidth, setAgentsWidth] = useState(0);

‎apps/mobile/src/features/threads/floating-working-status.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export interface FloatingStatusAction {
88
}
99

1010
export type FloatingWorkingStatus =
11-
| { readonly kind: "working"; readonly startedAt: string }
11+
| {
12+
readonly kind: "working";
13+
readonly startedAt: string;
14+
readonly action: FloatingStatusAction | null;
15+
}
1216
| { readonly kind: "syncing"; readonly label: string }
1317
| { readonly kind: "compacting" }
1418
| {
@@ -37,7 +41,12 @@ export type FloatingWorkingStatus =
3741
readonly unresponsive: boolean;
3842
readonly action: FloatingStatusAction | null;
3943
}
40-
| { readonly kind: "goal"; readonly label: string; readonly accessibilityLabel: string }
44+
| {
45+
readonly kind: "goal";
46+
readonly label: string;
47+
readonly accessibilityLabel: string;
48+
readonly action: FloatingStatusAction | null;
49+
}
4150
| { readonly kind: "extension"; readonly label: string; readonly onPress: () => void }
4251
| { readonly kind: "preparing"; readonly label: string }
4352
| {

‎apps/mobile/src/features/threads/resume-thread.test.ts‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Cause from "effect/Cause";
33
import { AsyncResult } from "effect/reactivity";
44
import { describe, expect, it } from "vite-plus/test";
55

6-
import { resumeThread } from "./resume-thread";
6+
import { continueThread, resumeThread } from "./resume-thread";
77

88
const runId = RunId.make("run-limited");
99
const failure = AsyncResult.failure(Cause.fail(new Error("not connected")));
@@ -64,21 +64,24 @@ describe("resumeThread", () => {
6464
expect(calls.map((call) => call.command)).toEqual(["startTurn"]);
6565
});
6666

67-
it("saves changed modes to the thread before continuing", async () => {
67+
it.each(["run", "goal"] as const)("saves changed modes before continuing a %s", async (kind) => {
6868
const { calls, base } = setup();
69-
await resumeThread({
69+
await continueThread({
7070
...base,
7171
runtimeMode: "approval-required",
7272
interactionMode: "plan",
73-
resumableRunId: runId,
74-
queueHeld: false,
73+
continuation: kind === "run" ? { kind, runId } : { kind },
7574
});
7675

7776
expect(calls.map((call) => call.command)).toEqual([
7877
"setRuntimeMode",
7978
"setInteractionMode",
8079
"startTurn",
8180
]);
81+
expect(calls[2]?.input).toMatchObject({
82+
dispatchMode: kind === "goal" ? "queue" : "start",
83+
message: { text: kind === "goal" ? "/goal resume" : "Continue where you left off." },
84+
});
8285
});
8386

8487
it("resumes a held queue directly when no run needs continuing", async () => {
@@ -87,4 +90,20 @@ describe("resumeThread", () => {
8790

8891
expect(calls.map((call) => call.command)).toEqual(["resumeQueue"]);
8992
});
93+
94+
it.each(["run", "goal"] as const)(
95+
"does not continue a %s when saving modes fails",
96+
async (kind) => {
97+
const { calls, base } = setup();
98+
const result = await continueThread({
99+
...base,
100+
continuation: kind === "run" ? { kind, runId } : { kind },
101+
runtimeMode: "approval-required",
102+
setRuntimeMode: async () => failure,
103+
});
104+
105+
expect(result).toBe(failure);
106+
expect(calls).toEqual([]);
107+
},
108+
);
90109
});

‎apps/mobile/src/features/threads/resume-thread.ts‎

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ type Command<Input, E> = (request: {
2020
readonly input: Input;
2121
}) => Promise<AtomCommandResult<unknown, E>>;
2222

23-
/** Resolves to the first failed command's result, or the last successful one. */
24-
export async function resumeThread<E>(input: {
23+
interface ThreadContinuationInput<E> {
2524
readonly thread: {
2625
readonly environmentId: EnvironmentId;
2726
readonly id: ThreadId;
2827
readonly runtimeMode: RuntimeMode;
2928
readonly interactionMode: ProviderInteractionMode;
3029
};
31-
readonly resumableRunId: RunId | null;
32-
readonly queueHeld: boolean;
3330
readonly runtimeMode: RuntimeMode;
3431
readonly interactionMode: ProviderInteractionMode;
3532
readonly modelSelection: ModelSelection | null;
@@ -38,46 +35,70 @@ export async function resumeThread<E>(input: {
3835
readonly setRuntimeMode: Command<SetThreadRuntimeModeInput, E>;
3936
readonly setInteractionMode: Command<SetThreadInteractionModeInput, E>;
4037
readonly startTurn: Command<StartThreadTurnInput, E>;
41-
readonly resumeQueue: Command<ResumeThreadQueueInput, E>;
42-
}): Promise<AtomCommandResult<unknown, E>> {
38+
}
39+
40+
export async function continueThread<E>(
41+
input: ThreadContinuationInput<E> & {
42+
readonly continuation:
43+
| { readonly kind: "goal" }
44+
| { readonly kind: "run"; readonly runId: RunId };
45+
},
46+
): Promise<AtomCommandResult<unknown, E>> {
4347
const { thread, runtimeMode, interactionMode, createdAt } = input;
4448
const environmentId = thread.environmentId;
45-
// The server holds the queue behind a stopped or usage-limited run until that run is continued.
46-
if (input.resumableRunId !== null) {
47-
// A turn on an existing thread runs with the thread's saved modes, not the turn's.
48-
if (runtimeMode !== thread.runtimeMode) {
49-
const saved = await input.setRuntimeMode({
50-
environmentId,
51-
input: { threadId: thread.id, runtimeMode, createdAt },
52-
});
53-
if (saved._tag === "Failure") return saved;
54-
}
55-
if (interactionMode !== thread.interactionMode) {
56-
const saved = await input.setInteractionMode({
57-
environmentId,
58-
input: { threadId: thread.id, interactionMode, createdAt },
59-
});
60-
if (saved._tag === "Failure") return saved;
61-
}
62-
const continued = await input.startTurn({
49+
if (runtimeMode !== thread.runtimeMode) {
50+
const saved = await input.setRuntimeMode({
51+
environmentId,
52+
input: { threadId: thread.id, runtimeMode, createdAt },
53+
});
54+
if (saved._tag === "Failure") return saved;
55+
}
56+
if (interactionMode !== thread.interactionMode) {
57+
const saved = await input.setInteractionMode({
6358
environmentId,
64-
input: {
65-
creationSource: "mobile",
66-
threadId: thread.id,
67-
manualContinuationOfRunId: input.resumableRunId,
68-
...(input.modelSelection ? { modelSelection: input.modelSelection } : {}),
69-
message: {
70-
messageId: input.messageId,
71-
role: "user",
72-
text: "Continue where you left off.",
73-
attachments: [],
74-
},
75-
runtimeMode,
76-
interactionMode,
77-
dispatchMode: "start",
59+
input: { threadId: thread.id, interactionMode, createdAt },
60+
});
61+
if (saved._tag === "Failure") return saved;
62+
}
63+
return input.startTurn({
64+
environmentId,
65+
input: {
66+
creationSource: "mobile",
67+
threadId: thread.id,
68+
...(input.continuation.kind === "run"
69+
? { manualContinuationOfRunId: input.continuation.runId }
70+
: {}),
71+
...(input.modelSelection ? { modelSelection: input.modelSelection } : {}),
72+
message: {
73+
messageId: input.messageId,
74+
role: "user",
75+
text: input.continuation.kind === "goal" ? "/goal resume" : "Continue where you left off.",
76+
attachments: [],
7877
},
78+
runtimeMode,
79+
interactionMode,
80+
dispatchMode: input.continuation.kind === "goal" ? "queue" : "start",
81+
createdAt,
82+
},
83+
});
84+
}
85+
86+
export async function resumeThread<E>(
87+
input: ThreadContinuationInput<E> & {
88+
readonly resumableRunId: RunId | null;
89+
readonly queueHeld: boolean;
90+
readonly resumeQueue: Command<ResumeThreadQueueInput, E>;
91+
},
92+
): Promise<AtomCommandResult<unknown, E>> {
93+
if (input.resumableRunId !== null) {
94+
const continued = await continueThread({
95+
...input,
96+
continuation: { kind: "run", runId: input.resumableRunId },
7997
});
8098
if (continued._tag === "Failure" || !input.queueHeld) return continued;
8199
}
82-
return input.resumeQueue({ environmentId, input: { threadId: thread.id } });
100+
return input.resumeQueue({
101+
environmentId: input.thread.environmentId,
102+
input: { threadId: input.thread.id },
103+
});
83104
}

‎apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts‎

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,38 +2203,46 @@ it.effect("queues a goal clear without stopping work when no goal drives it", ()
22032203
),
22042204
);
22052205

2206-
it.effect("promotes a queued goal by stopping the running turn", () =>
2207-
Effect.scoped(
2208-
Effect.gen(function* () {
2209-
const { started, steered, layer, startFirstTurn, send, read } =
2210-
yield* goalHarness("goal-promote");
2211-
yield* Effect.gen(function* () {
2212-
const orchestrator = yield* Orchestrator.OrchestratorV2;
2213-
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
2214-
const threadId = yield* startFirstTurn;
2215-
yield* send("queued", "queued", "queue");
2216-
yield* send("goal", "/goal ship it", "queue");
2217-
const goalRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
2218-
(run) => run.userMessageId === MessageId.make("message:goal"),
2219-
)!;
2220-
yield* orchestrator.dispatch({
2221-
type: "queued-message.promote-to-steer",
2222-
commandId: CommandId.make("promote"),
2223-
threadId,
2224-
queuedRunId: goalRun.id,
2225-
targetRunId: started[0]!.runId,
2226-
});
2227-
yield* worker.drain();
2206+
it.effect.each(["/goal ship it", "/goal resume"])(
2207+
"queues %s until promoted by stopping the running turn",
2208+
(text) =>
2209+
Effect.scoped(
2210+
Effect.gen(function* () {
2211+
const { started, steered, layer, startFirstTurn, send, read } =
2212+
yield* goalHarness("goal-promote");
2213+
yield* Effect.gen(function* () {
2214+
const orchestrator = yield* Orchestrator.OrchestratorV2;
2215+
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
2216+
const threadId = yield* startFirstTurn;
2217+
yield* send("queued", "queued", "queue");
2218+
yield* send("goal", text, "queue");
2219+
yield* worker.drain();
2220+
assert.deepEqual(yield* read(threadId), {
2221+
queue: ["queued", text],
2222+
started: ["first"],
2223+
stopRequested: false,
2224+
});
2225+
const goalRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
2226+
(run) => run.userMessageId === MessageId.make("message:goal"),
2227+
)!;
2228+
yield* orchestrator.dispatch({
2229+
type: "queued-message.promote-to-steer",
2230+
commandId: CommandId.make("promote"),
2231+
threadId,
2232+
queuedRunId: goalRun.id,
2233+
targetRunId: started[0]!.runId,
2234+
});
2235+
yield* worker.drain();
22282236

2229-
assert.deepEqual(steered, []);
2230-
assert.deepEqual(yield* read(threadId), {
2231-
queue: ["queued"],
2232-
started: ["first", "/goal ship it"],
2233-
stopRequested: true,
2234-
});
2235-
}).pipe(Effect.provide(layer));
2236-
}),
2237-
),
2237+
assert.deepEqual(steered, []);
2238+
assert.deepEqual(yield* read(threadId), {
2239+
queue: ["queued"],
2240+
started: ["first", text],
2241+
stopRequested: true,
2242+
});
2243+
}).pipe(Effect.provide(layer));
2244+
}),
2245+
),
22382246
);
22392247

22402248
// A fresh message skips compaction as its own turn, which steering a running turn would not.

0 commit comments

Comments
 (0)