Skip to content

Commit 8cd175b

Browse files
Merge remote-tracking branch 'origin/main' into fix/composer-background-work-layout
2 parents 9f30416 + 1451e7c commit 8cd175b

29 files changed

Lines changed: 691 additions & 30 deletions

File tree

‎apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.text.Editable
77
import android.text.InputType
88
import android.text.TextWatcher
99
import android.view.KeyEvent
10+
import android.view.View
1011
import android.view.ViewGroup
1112
import android.view.inputmethod.EditorInfo
1213
import android.view.inputmethod.InputMethodManager
@@ -20,7 +21,12 @@ import kotlin.math.max
2021
class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
2122
private val container = FrameLayout(context)
2223
private val terminalCanvas = TerminalCanvasView(context)
23-
private val inputView = EditText(context)
24+
25+
// Newer Android can request autofill even with importantForAutofill=no.
26+
// Reporting no autofill type keeps terminal input out of credential autofill.
27+
private val inputView = object : EditText(context) {
28+
override fun getAutofillType(): Int = View.AUTOFILL_TYPE_NONE
29+
}
2430
private val onInput by EventDispatcher()
2531
private val onResize by EventDispatcher()
2632
private val onCapture by EventDispatcher()

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ export interface ThreadComposerProps {
162162
readonly onNativePasteText: (paste: ComposerTextPaste) => Promise<void>;
163163
readonly onRemoveDraftImage: (imageId: string) => void;
164164
readonly onStopThread: () => void;
165+
/** Present while the thread's queue is held. */
166+
readonly onResumeQueue: (() => Promise<void>) | null;
165167
readonly onSendMessage: (followUp?: ActiveTurnComposerAction) => Promise<MessageId | null>;
166168
readonly onShowUsageLimits: (report: UsageLimitsReport | null) => void;
167169
readonly canSwitchProvider: boolean;
@@ -357,6 +359,16 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
357359
(queuedEdit?.existingAttachments.length ?? 0) > 0;
358360
const stripAttachments = composerStripAttachments(draftAttachments);
359361
const showStopAction = !hasContent && props.canStopThread && queuedEdit === null;
362+
const onResumeQueue = props.onResumeQueue;
363+
const [resumingQueue, setResumingQueue] = useState(false);
364+
const showResumeAction =
365+
!hasContent && !showStopAction && queuedEdit === null && onResumeQueue !== null;
366+
const handleResumeQueue = async () => {
367+
if (resumingQueue || onResumeQueue === null) return;
368+
setResumingQueue(true);
369+
await onResumeQueue();
370+
setResumingQueue(false);
371+
};
360372

361373
const uploadStates = useAtomValue(composerAttachmentUploadsAtom);
362374
const attachmentsUploading =
@@ -955,6 +967,13 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
955967
disabled={!props.canOperateThread}
956968
onPress={props.onStopThread}
957969
/>
970+
) : showResumeAction ? (
971+
<ComposerActionButton
972+
accessibilityLabel="Resume queue"
973+
icon="play"
974+
disabled={!props.canOperateThread || resumingQueue}
975+
onPress={() => void handleResumeQueue()}
976+
/>
958977
) : (
959978
<SendActionButton
960979
accessibilityLabel={sendBlockedReason ?? sendLabel}
@@ -1050,6 +1069,13 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
10501069
disabled={!props.canOperateThread}
10511070
onPress={props.onStopThread}
10521071
/>
1072+
) : showResumeAction && voicePresentation.showsSend ? (
1073+
<ComposerActionButton
1074+
accessibilityLabel="Resume queue"
1075+
icon="play"
1076+
disabled={!props.canOperateThread || resumingQueue}
1077+
onPress={() => void handleResumeQueue()}
1078+
/>
10531079
) : voicePresentation.showsSend ? (
10541080
<SendActionButton
10551081
accessibilityLabel={sendBlockedReason ?? sendLabel}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ export interface ThreadDetailScreenProps {
217217
readonly onNativePasteText: (paste: ComposerTextPaste) => Promise<void>;
218218
readonly onRemoveDraftImage: (imageId: string) => void;
219219
readonly onStopThread: () => void;
220+
/** Present while the thread's queue is held. */
221+
readonly onResumeQueue: (() => Promise<void>) | null;
220222
readonly onSendMessage: (followUp?: ActiveTurnComposerAction) => Promise<MessageId | null>;
221223
readonly onReconnectEnvironment: () => void;
222224
readonly canSwitchThreadProvider: boolean;
@@ -1343,6 +1345,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
13431345
onNativePasteText={props.onNativePasteText}
13441346
onRemoveDraftImage={props.onRemoveDraftImage}
13451347
onStopThread={props.onStopThread}
1348+
onResumeQueue={props.onResumeQueue}
13461349
onSendMessage={handleSendMessage}
13471350
onShowUsageLimits={showUsageLimits}
13481351
canSwitchProvider={props.canSwitchThreadProvider}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
189189
>
190190
{workflow?.isHeld && queuedRuns.length > 0 ? (
191191
<View className="gap-2 py-3">
192-
<Text className="text-sm text-foreground-muted">Queue held after restart</Text>
192+
<Text className="text-sm text-foreground-muted">Queue paused</Text>
193193
<Button
194194
label="Resume queue"
195195
disabled={resuming || busyRunId !== null}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ function ThreadRouteContent(
291291
const gitActions = useSelectedThreadGitActions();
292292
const requests = useSelectedThreadRequests();
293293
const interruptThreadTurn = useAtomCommand(threadEnvironment.interruptTurn, "thread interrupt");
294+
const resumeThreadQueue = useAtomCommand(threadEnvironment.resumeThreadQueue, "resume queue");
294295
const loadEarlierHistory = useAtomCommand(threadEnvironment.loadEarlierHistory, {
295296
label: "load earlier thread history",
296297
reportFailure: false,
@@ -564,6 +565,14 @@ function ThreadRouteContent(
564565
});
565566
};
566567

568+
const handleResumeQueue = async () => {
569+
if (!selectedThread) return;
570+
await resumeThreadQueue({
571+
environmentId: selectedThread.environmentId,
572+
input: { threadId: selectedThread.id },
573+
});
574+
};
575+
567576
const handleOpenTerminal = (nextTerminalId?: string | null) => {
568577
terminalDebugLog("terminal-menu:open-existing", {
569578
terminalId: nextTerminalId ?? null,
@@ -956,6 +965,7 @@ function ThreadRouteContent(
956965
onRemoveDraftImage={composer.onRemoveDraftImage}
957966
serverConfig={serverConfig}
958967
onStopThread={awaitingBootstrapTurn ? handleCancelWorktreeSetup : handleStopThread}
968+
onResumeQueue={composer.queueHeld ? handleResumeQueue : null}
959969
onSendMessage={composer.onSendMessage}
960970
onReconnectEnvironment={handleReconnectEnvironment}
961971
canSwitchThreadProvider={composer.canSwitchThreadProvider}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ export function useThreadComposerState() {
351351
})();
352352
// A compacting turn cannot take steering input, so follow-ups queue meanwhile.
353353
const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !isCompacting;
354+
// A stop or a restart holds the queue, completion wakes included, until it
355+
// is resumed; the queue sheet lists only the user's own messages.
356+
const queueHeld = queueWorkflow?.isHeld === true;
354357

355358
const runlessWorkStartedAt = selectedThreadProjection
356359
? deriveRunlessWorkStartedAt(selectedThreadProjection.projection)
@@ -966,6 +969,7 @@ export function useThreadComposerState() {
966969
composerDraftKey,
967970
followUpBehavior,
968971
canSteerActiveTurn,
972+
queueHeld,
969973
queuedRunEdit,
970974
isSavingQueuedEdit,
971975
cancelQueuedRunEdit,

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,11 +4999,48 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
49994999
: undefined;
50005000
const queueBehindRun = activeRun ?? worktreeMissingRun;
50015001
const pendingMergeBackTransfers = pendingMergeBackTransfersForThread(projection);
5002-
const shouldQueue =
5003-
queueBehindRun !== undefined &&
5004-
(dispatchMode.type === "defer_start" ||
5005-
dispatchMode.type === "start_immediately" ||
5006-
dispatchMode.type === "queue_after_active");
5002+
const startsOrQueuesRun =
5003+
dispatchMode.type === "defer_start" ||
5004+
dispatchMode.type === "start_immediately" ||
5005+
dispatchMode.type === "queue_after_active";
5006+
const shouldQueue = queueBehindRun !== undefined && startsOrQueuesRun;
5007+
// A message the user sends from a client means they are back, so the
5008+
// queue a stop or a restart held runs again, in its order, rather than
5009+
// waiting for a Resume.
5010+
// Continuations and scheduled tasks the server sends for them are not
5011+
// them coming back. Starting the queue still re-holds it for a failed
5012+
// provider or a usage limit; a queue held after worktree setup failed
5013+
// keeps its hold until a worktree exists, even once later messages have
5014+
// run, since its messages would start in the project checkout.
5015+
const worktreeSetupUnresolved =
5016+
projection.thread.worktreePath === null &&
5017+
projection.runs.some(
5018+
(run) =>
5019+
(run.status === "failed" || run.status === "interrupted") &&
5020+
run.workspacePreparation?.type === "worktree",
5021+
);
5022+
const sentByUserFromClient =
5023+
command.createdBy === "user" &&
5024+
(command.creationSource === "web" || command.creationSource === "mobile") &&
5025+
command.scheduledTaskId === undefined;
5026+
const heldRunsToRelease =
5027+
sentByUserFromClient && startsOrQueuesRun && !worktreeSetupUnresolved
5028+
? projection.runs.filter((run) => run.status === "queued" && run.queueHeld === true)
5029+
: [];
5030+
const releasedAt = yield* DateTime.now;
5031+
for (const held of heldRunsToRelease) {
5032+
yield* emit(
5033+
events,
5034+
command,
5035+
)({
5036+
type: "run.updated",
5037+
threadId: command.threadId,
5038+
runId: held.id,
5039+
providerInstanceId: held.providerInstanceId,
5040+
occurredAt: releasedAt,
5041+
payload: { ...held, queueHeld: false },
5042+
});
5043+
}
50075044
if (shouldQueue) {
50085045
if (pendingMergeBackTransfers.length > 0) {
50095046
return yield* new OrchestratorDispatchError({
@@ -5113,9 +5150,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
51135150
activeAttemptId: attemptId,
51145151
status: "queued",
51155152
...(worktreeMissingRun !== undefined ||
5116-
projection.runs.some(
5117-
(candidate) => candidate.status === "queued" && candidate.queueHeld === true,
5118-
)
5153+
(heldRunsToRelease.length === 0 &&
5154+
projection.runs.some(
5155+
(candidate) => candidate.status === "queued" && candidate.queueHeld === true,
5156+
))
51195157
? { queueHeld: true }
51205158
: {}),
51215159
queuePosition:

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import * as ServerSettings from "../serverSettings.ts";
5353
import * as ScheduledTasks from "../scheduledTasks/ScheduledTaskService.ts";
5454
import * as SecretRequests from "../secrets/SecretRequests.ts";
5555
import * as TextGeneration from "../textGeneration/TextGeneration.ts";
56+
import { ClaudeProviderCapabilitiesV2 } from "./Adapters/ClaudeAdapterV2.ts";
5657
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
5758
import * as CommandReceiptStore from "./CommandReceiptStore.ts";
5859
import * as EffectOutbox from "./EffectOutbox.ts";
@@ -101,6 +102,18 @@ const adapter = {
101102
openSession: () => Effect.die("provider execution is disabled in launch tests"),
102103
} as ProviderAdapter.ProviderAdapterV2["Service"];
103104

105+
const claudeModelSelection = {
106+
instanceId: ProviderInstanceId.make("claudeAgent"),
107+
model: "claude-opus-5-5",
108+
} as const;
109+
const claudeAdapter = {
110+
instanceId: claudeModelSelection.instanceId,
111+
driver: ProviderDriverKind.make("claudeAgent"),
112+
getCapabilities: () => Effect.succeed(ClaudeProviderCapabilitiesV2),
113+
planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }),
114+
openSession: () => Effect.die("provider execution is disabled in launch tests"),
115+
} as ProviderAdapter.ProviderAdapterV2["Service"];
116+
104117
interface HarnessOptions {
105118
readonly closeTerminal?: TerminalManager.TerminalManager["Service"]["close"];
106119
readonly adapters?: ReadonlyArray<ProviderAdapter.ProviderAdapterV2["Service"]>;
@@ -374,6 +387,57 @@ it.effect.each(
374387
},
375388
);
376389

390+
it.effect("runs a thread-bound automation on the provider the thread uses now", () => {
391+
const harness = makeHarness({ adapters: [adapter, claudeAdapter] });
392+
const layerScheduledTasks = ScheduledTasks.layer.pipe(
393+
Layer.provide(
394+
Layer.mergeAll(
395+
harness.layer,
396+
NodeCrypto.layer,
397+
Scheduler.layer,
398+
Layer.mock(SecretRequests.SecretRequests)({}),
399+
),
400+
),
401+
);
402+
return Effect.gen(function* () {
403+
const tasks = yield* ScheduledTasks.ScheduledTaskService;
404+
const launches = yield* ThreadLaunch.ThreadLaunchService;
405+
const threads = yield* ThreadManagement.ThreadManagementService;
406+
const launched = yield* launches.launch(
407+
launchInput({ command: "command:switched", thread: "thread:switched" }),
408+
);
409+
const { task } = yield* tasks.upsert({
410+
id: ScheduledTaskId.make("scheduled-task:switched"),
411+
title: "Hourly check",
412+
prompt: "Check on the delegated workers.",
413+
enabled: false,
414+
schedule: { type: "interval", everyMs: 3_600_000 },
415+
projectId,
416+
threadId: launched.threadId,
417+
workspaceStrategy: { type: "root" },
418+
modelSelection,
419+
runtimeMode: "full-access",
420+
interactionMode: "default",
421+
createdBy: "agent",
422+
creationSource: "mcp",
423+
});
424+
yield* threads.dispatch({
425+
type: "thread.model-selection.set",
426+
commandId: CommandId.make("command:switch-selection"),
427+
threadId: launched.threadId,
428+
modelSelection: claudeModelSelection,
429+
});
430+
431+
const result = yield* tasks.runNow({ id: task.id });
432+
assert.equal(result.task.lastRunStatus, "succeeded");
433+
const projection = yield* threads.getThreadProjection(launched.threadId);
434+
const message = projection.messages.find((item) => item.scheduledTaskId === task.id);
435+
const run = projection.runs.find((item) => item.id === message?.runId);
436+
assert.deepStrictEqual(run?.modelSelection, claudeModelSelection);
437+
assert.deepStrictEqual(projection.thread.modelSelection, claudeModelSelection);
438+
}).pipe(Effect.provide(Layer.mergeAll(harness.layer, layerScheduledTasks)));
439+
});
440+
377441
it.effect("retains automation and sender attribution while a message waits in the queue", () => {
378442
const harness = makeHarness({ runSetup: () => Effect.never });
379443
return Effect.gen(function* () {
@@ -1751,8 +1815,38 @@ it.effect.each(["failed", "interrupted"] as const)(
17511815
});
17521816
assert.equal(queued.delivery, "queued");
17531817
const projection = yield* threads.getThreadProjection(launched.threadId);
1754-
assert.equal(projection.runs.at(-1)?.status, "queued");
1755-
assert.equal(projection.runs.at(-1)?.queueHeld, true);
1818+
const held = projection.runs.at(-1)!;
1819+
assert.equal(held.status, "queued");
1820+
assert.equal(held.queueHeld, true);
1821+
1822+
// A message the user starts does not release it: the held message would
1823+
// run after it in the project checkout.
1824+
yield* threads.sendToThread({
1825+
projectId,
1826+
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:start`),
1827+
threadId: launched.threadId,
1828+
messageId: MessageId.make(`message:launch:late-queued-follow-up-${ending}:start`),
1829+
text: "Sent after setup",
1830+
attachments: [],
1831+
mode: "auto",
1832+
createdBy: "user",
1833+
creationSource: "web",
1834+
});
1835+
// Nor does the next one, though the run that message started is now the
1836+
// latest and carries no workspace preparation.
1837+
yield* threads.sendToThread({
1838+
projectId,
1839+
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:again`),
1840+
threadId: launched.threadId,
1841+
messageId: MessageId.make(`message:launch:late-queued-follow-up-${ending}:again`),
1842+
text: "Sent after that",
1843+
attachments: [],
1844+
mode: "auto",
1845+
createdBy: "user",
1846+
creationSource: "web",
1847+
});
1848+
const after = yield* threads.getThreadProjection(launched.threadId);
1849+
assert.isTrue(after.runs.find((run) => run.id === held.id)?.queueHeld);
17561850
}).pipe(Effect.provide(harness.layer));
17571851
},
17581852
);

0 commit comments

Comments
 (0)