Skip to content

Commit 1ce3680

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-31617
2 parents e8f1359 + b18434e commit 1ce3680

20 files changed

Lines changed: 680 additions & 78 deletions

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,7 @@ export function useThreadListActions(): {
308308
if (!canSnooze(thread, { now: new Date().toISOString() })) {
309309
Dialog.alert(
310310
"Could not snooze thread",
311-
thread.hasPendingApprovals ||
312-
thread.hasPendingUserInput ||
313-
thread.pendingSubagentRequest != null
311+
thread.hasPendingApprovals || thread.pendingSubagentRequest != null
314312
? "This thread is waiting on you. Respond to the pending request before snoozing it."
315313
: "This thread is still starting a turn. Try again once it's running.",
316314
);

‎apps/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
type ThreadMoveAvailability,
1515
} from "./threadOrder";
1616
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
17-
import { resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
17+
import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
1818
import {
1919
CommandId,
2020
EnvironmentId,
@@ -23,6 +23,7 @@ import {
2323
ProjectId,
2424
ProviderInstanceId,
2525
RunId,
26+
RuntimeRequestId,
2627
ThreadId,
2728
} from "@t3tools/contracts";
2829
import type { MenuAction } from "@react-native-menu/menu";
@@ -37,6 +38,7 @@ import {
3738
getThreadListV2OrderedSection,
3839
layoutThreadListV2RowMenuActions,
3940
resolveThreadListV2SnoozeMenuSelection,
41+
resolveThreadListV2SwipeActions,
4042
resolveThreadListV2SnoozePresets,
4143
resolveThreadListV2Status,
4244
resolveThreadListV2WokeAt,
@@ -209,32 +211,35 @@ describe("resolveThreadListV2Status", () => {
209211
);
210212
});
211213

212-
describe("queued messages keep a settled thread active", () => {
213-
const threads = [
214-
makeThread({ id: ThreadId.make("active"), title: "Active" }),
215-
makeThread({ id: ThreadId.make("settled"), title: "Settled", settledOverride: "settled" }),
216-
makeThread({
217-
id: ThreadId.make("settled-queued"),
218-
title: "Settled with outbox",
219-
settledOverride: "settled",
220-
}),
221-
];
222-
const queuedThreadKeys = new Set([`${environmentId}:settled-queued`]);
214+
describe("resolveThreadListV2SwipeActions", () => {
215+
it("offers snooze for a presented input request and moves it onto the snoozed shelf", () => {
216+
const raw = makeRawThreadShell({
217+
pendingRuntimeRequest: {
218+
id: RuntimeRequestId.make("question"),
219+
kind: "user_input",
220+
createdAt: DateTime.makeUnsafe(NOW),
221+
},
222+
});
223+
const thread = presentThreadShell(environmentId, raw);
224+
expect(thread.pendingUserInputAt).toBe(NOW);
225+
expect(
226+
resolveThreadListV2SwipeActions({
227+
variant: "card",
228+
settlementSupported: true,
229+
snoozeSupported: true,
230+
snoozable: canSnooze(thread, { now: NOW }),
231+
}).secondary,
232+
).toBe("snooze");
223233

224-
it("lists the thread in the active block instead of the settled shelf", () => {
225234
const layout = buildThreadListV2Items({
226-
threads,
235+
threads: [{ ...thread, snoozedAt: NOW, snoozedUntil: "2026-06-03T00:00:00.000Z" }],
227236
environmentId: null,
228237
searchQuery: "",
229238
now: NOW,
230-
queuedThreadKeys,
239+
snoozedShelfExpanded: true,
240+
snoozeEnvironmentIds: new Set([environmentId]),
231241
});
232-
expect(layout.items.map((item) => [item.thread.id, item.variant] as const)).toEqual([
233-
["active", "card"],
234-
["settled-queued", "card"],
235-
["settled", "slim"],
236-
]);
237-
expect(layout.settledCount).toBe(1);
242+
expect(layout.snoozedCount).toBe(1);
238243
});
239244
});
240245

@@ -1768,3 +1773,32 @@ describe("Working section beta", () => {
17681773
]);
17691774
});
17701775
});
1776+
1777+
describe("queued messages keep a settled thread active", () => {
1778+
const threads = [
1779+
makeThread({ id: ThreadId.make("active"), title: "Active" }),
1780+
makeThread({ id: ThreadId.make("settled"), title: "Settled", settledOverride: "settled" }),
1781+
makeThread({
1782+
id: ThreadId.make("settled-queued"),
1783+
title: "Settled with outbox",
1784+
settledOverride: "settled",
1785+
}),
1786+
];
1787+
const queuedThreadKeys = new Set([`${environmentId}:settled-queued`]);
1788+
1789+
it("lists the thread in the active block instead of the settled shelf", () => {
1790+
const layout = buildThreadListV2Items({
1791+
threads,
1792+
environmentId: null,
1793+
searchQuery: "",
1794+
now: NOW,
1795+
queuedThreadKeys,
1796+
});
1797+
expect(layout.items.map((item) => [item.thread.id, item.variant] as const)).toEqual([
1798+
["active", "card"],
1799+
["settled-queued", "card"],
1800+
["settled", "slim"],
1801+
]);
1802+
expect(layout.settledCount).toBe(1);
1803+
});
1804+
});

‎apps/mobile/src/features/threads/threadListV2.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function resolveThreadListV2SnoozeGateExpiryMs(
183183
>,
184184
options: { readonly now: string },
185185
): number | null {
186-
if (thread.hasPendingApprovals || thread.hasPendingUserInput) return null;
186+
if (thread.hasPendingApprovals) return null;
187187
if (thread.pendingSubagentRequest != null) return null;
188188
if (!hasQueuedTurnStart(thread, options)) return null;
189189
const messageAtMs = Date.parse(thread.latestUserMessageAt ?? "");

‎apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ it.effect(
559559
assert.deepEqual(yield* outbox.listByCommandId(commandId), []);
560560
}
561561
}
562+
if (mode === "live") {
563+
yield* orchestrator.dispatch({
564+
type: "thread.snooze",
565+
commandId: CommandId.make("snooze-live-control"),
566+
threadId,
567+
snoozedUntil: "2099-07-25T09:00:00.000Z",
568+
});
569+
}
562570
yield* orchestrator.dispatch(
563571
mode === "live"
564572
? {
@@ -583,6 +591,8 @@ it.effect(
583591
assert.equal(response.node?.status, mode === "live" ? "completed" : "cancelled");
584592
assert.equal(response.item?.status, mode === "live" ? "completed" : "cancelled");
585593
if (mode === "live") {
594+
assert.isNull((yield* projections.getThread(threadId)).snoozedUntil);
595+
assert.isNull((yield* projections.getThread(threadId)).snoozedAt);
586596
assert.deepEqual(response.request?.answers, normalizedAnswers);
587597
assert.equal(response.item?.type, "user_input_request");
588598
if (response.item?.type === "user_input_request") {
@@ -1537,6 +1547,92 @@ it.effect("explicit settle clears snooze atomically and stays idempotent after r
15371547
}).pipe(Effect.provide(layerTest)),
15381548
);
15391549

1550+
it.effect("keeps a snooze when a live question is cancelled or an approval is answered", () =>
1551+
Effect.gen(function* () {
1552+
const orchestrator = yield* Orchestrator.OrchestratorV2;
1553+
const projections = yield* ProjectionStore.ProjectionStoreV2;
1554+
const outbox = yield* EffectOutbox.EffectOutboxV2;
1555+
const now = yield* DateTime.now;
1556+
for (const kind of ["user_input", "command"] as const) {
1557+
const threadId = ThreadId.make(`thread:snoozed-live-${kind}`);
1558+
const requestId = RuntimeRequestId.make(`request:snoozed-live-${kind}`);
1559+
const sessionId = ProviderSessionId.make(`session:snoozed-live-${kind}`);
1560+
yield* orchestrator.dispatch({
1561+
type: "thread.create",
1562+
commandId: CommandId.make(`create-snoozed-live-${kind}`),
1563+
threadId,
1564+
projectId: ProjectId.make("project:snoozed-live"),
1565+
title: "Deferred question",
1566+
modelSelection,
1567+
runtimeMode: "full-access",
1568+
interactionMode: "default",
1569+
branch: null,
1570+
worktreePath: null,
1571+
createdBy: "user",
1572+
creationSource: "web",
1573+
});
1574+
yield* orchestrator.dispatch({
1575+
type: "thread.snooze",
1576+
commandId: CommandId.make(`snooze-live-${kind}`),
1577+
threadId,
1578+
snoozedUntil: "2099-07-25T09:00:00.000Z",
1579+
});
1580+
const before = yield* projections.getThread(threadId);
1581+
yield* projections.apply({
1582+
id: EventId.make(`attach-snoozed-live-${kind}`),
1583+
type: "provider-session.attached",
1584+
threadId,
1585+
occurredAt: now,
1586+
payload: {
1587+
id: sessionId,
1588+
driver: adapter.driver,
1589+
providerInstanceId: instanceId,
1590+
status: "ready",
1591+
cwd: "/repo",
1592+
model: modelSelection.model,
1593+
capabilities: CodexProviderCapabilitiesV2,
1594+
createdAt: now,
1595+
updatedAt: now,
1596+
lastError: null,
1597+
},
1598+
});
1599+
yield* projections.apply({
1600+
id: EventId.make(`request-snoozed-live-${kind}`),
1601+
type: "runtime-request.updated",
1602+
threadId,
1603+
occurredAt: now,
1604+
payload: {
1605+
id: requestId,
1606+
nodeId: NodeId.make(`node:snoozed-live-${kind}`),
1607+
providerTurnId: null,
1608+
nativeRequestRef: null,
1609+
kind,
1610+
status: "pending",
1611+
responseCapability: { type: "live", providerSessionId: sessionId },
1612+
createdAt: now,
1613+
resolvedAt: null,
1614+
},
1615+
});
1616+
const commandId = CommandId.make(`respond-snoozed-live-${kind}`);
1617+
yield* orchestrator.dispatch({
1618+
type: "runtime-request.respond",
1619+
commandId,
1620+
threadId,
1621+
requestId,
1622+
decision: kind === "user_input" ? "cancel" : "accept",
1623+
});
1624+
const after = yield* projections.getThread(threadId);
1625+
assert.deepEqual(after.snoozedUntil, before.snoozedUntil);
1626+
assert.deepEqual(after.snoozedAt, before.snoozedAt);
1627+
assert.equal((yield* projections.getRuntimeRequest(threadId, requestId))?.status, "resolved");
1628+
assert.equal(
1629+
(yield* outbox.listByCommandId(commandId))[0]?.request.type,
1630+
"runtime-request.respond",
1631+
);
1632+
}
1633+
}).pipe(Effect.provide(layerTest)),
1634+
);
1635+
15401636
it.effect("dispatch records the command outcome and its duration", () =>
15411637
Effect.gen(function* () {
15421638
const orchestrator = yield* Orchestrator.OrchestratorV2;

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

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,11 +3526,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
35263526
cause: `Thread ${command.threadId} snooze wake time ${command.snoozedUntil} is not in the future.`,
35273527
});
35283528
}
3529-
if (projection.runtimeRequests.some((request) => request.status === "pending")) {
3529+
if (
3530+
projection.runtimeRequests.some(
3531+
(request) => request.status === "pending" && request.kind !== "user_input",
3532+
)
3533+
) {
35303534
return yield* new OrchestratorDispatchError({
35313535
commandId: command.commandId,
35323536
commandType: command.type,
3533-
cause: `Thread ${command.threadId} has a pending approval or user-input request and cannot be snoozed.`,
3537+
cause: `Thread ${command.threadId} has a pending approval and cannot be snoozed.`,
35343538
});
35353539
}
35363540
const queuedRuns = projection.runs.filter((run) => run.status === "queued");
@@ -8854,6 +8858,22 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
88548858
...(command.delivery === undefined ? {} : { delivery: command.delivery }),
88558859
secretStatus: command.secretStatus,
88568860
};
8861+
if (
8862+
!unchanged &&
8863+
command.secretStatus === "saved" &&
8864+
projection.thread.snoozedUntil != null
8865+
) {
8866+
yield* emit(
8867+
events,
8868+
command,
8869+
)({
8870+
type: "thread.unsnoozed",
8871+
threadId: command.threadId,
8872+
providerInstanceId: projection.thread.providerInstanceId,
8873+
occurredAt: now,
8874+
payload: { ...projection.thread, snoozedUntil: null, snoozedAt: null, updatedAt: now },
8875+
});
8876+
}
88578877
yield* emit(
88588878
events,
88598879
command,
@@ -8980,6 +9000,18 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
89809000
updatedAt: now,
89819001
type: "link_request",
89829002
};
9003+
if (!unchanged && command.linkStatus === "linked" && projection.thread.snoozedUntil != null) {
9004+
yield* emit(
9005+
events,
9006+
command,
9007+
)({
9008+
type: "thread.unsnoozed",
9009+
threadId: command.threadId,
9010+
providerInstanceId: projection.thread.providerInstanceId,
9011+
occurredAt: now,
9012+
payload: { ...projection.thread, snoozedUntil: null, snoozedAt: null, updatedAt: now },
9013+
});
9014+
}
89839015
yield* emit(
89849016
events,
89859017
command,
@@ -9401,6 +9433,20 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
94019433
return yield* recordSubagentFollowup(answer, events).pipe(mapDispatchError(answer));
94029434
}
94039435
if (providerSessionId === null) return;
9436+
if (runtimeRequest.kind === "user_input" && resolvedNodeStatus === "completed") {
9437+
const thread = yield* projectionStore
9438+
.getThread(command.threadId)
9439+
.pipe(mapDispatchError(command));
9440+
if (thread.snoozedUntil != null) {
9441+
yield* emitEvent({
9442+
type: "thread.unsnoozed",
9443+
threadId: command.threadId,
9444+
providerInstanceId: thread.providerInstanceId,
9445+
occurredAt: now,
9446+
payload: { ...thread, snoozedUntil: null, snoozedAt: null, updatedAt: now },
9447+
});
9448+
}
9449+
}
94049450
yield* Ref.update(effects, (existing) => [
94059451
...existing,
94069452
{

0 commit comments

Comments
 (0)