Skip to content

Commit 07ad938

Browse files
committed
feat(web): send messages after a short delay
1 parent 70d60e0 commit 07ad938

34 files changed

Lines changed: 2028 additions & 77 deletions

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
235235
isEditing: editing?.runId === run.id,
236236
queuedCount: queuedRuns.length,
237237
text,
238+
releaseAt: run.releaseAt,
238239
});
239240
const title =
240241
controls.displayText || (attachments.length > 0 ? "Attachments" : "Queued message");
@@ -394,7 +395,12 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
394395
Editing
395396
</Text>
396397
) : null}
397-
{workflow?.canPromoteToSteer ? (
398+
{controls.releaseLabel !== null ? (
399+
<Text className="shrink-0 text-xs tabular-nums text-foreground-muted">
400+
{controls.releaseLabel}
401+
</Text>
402+
) : null}
403+
{workflow?.canPromoteToSteer && controls.releaseLabel === null ? (
398404
<Pressable
399405
accessibilityRole="button"
400406
accessibilityLabel={`Steer with message ${index + 1} now`}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ describe("threadQueueControlPresentation", () => {
5454
expect(busy.canSteer).toBe(false);
5555
});
5656

57+
it("shows when a delayed message sends and keeps it from being steered early", () => {
58+
const delayed = resolveThreadQueueRowControls({
59+
busy: false,
60+
canPromoteToSteer: true,
61+
canReorder: true,
62+
index: 0,
63+
queuedCount: 1,
64+
text: "Check the deploy",
65+
releaseAt: "2026-10-17T15:42:00.000Z",
66+
});
67+
const released = resolveThreadQueueRowControls({
68+
busy: false,
69+
canPromoteToSteer: true,
70+
canReorder: true,
71+
index: 0,
72+
queuedCount: 1,
73+
text: "Check the deploy",
74+
releaseAt: null,
75+
});
76+
77+
expect(delayed.releaseLabel).toMatch(/^Sends at /);
78+
expect(delayed.canSteer).toBe(false);
79+
expect(delayed.canEdit).toBe(true);
80+
expect(delayed.canDismiss).toBe(true);
81+
expect(released.releaseLabel).toBeNull();
82+
expect(released.canSteer).toBe(true);
83+
});
84+
5785
it("keeps the row already open in the composer from being reopened or steered", () => {
5886
const editing = resolveThreadQueueRowControls({
5987
busy: false,

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
2+
import * as DateTime from "effect/DateTime";
23

34
export const REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL = "Remove queued message";
45

@@ -11,6 +12,8 @@ export interface ThreadQueueRowControls {
1112
readonly dismissAccessibilityLabel: string;
1213
readonly displayText: string;
1314
readonly isEditing: boolean;
15+
/** "Sends at …" while a delayed message waits for its time, otherwise null. */
16+
readonly releaseLabel: string | null;
1417
}
1518

1619
export function resolveThreadQueueRowControls(input: {
@@ -21,9 +24,16 @@ export function resolveThreadQueueRowControls(input: {
2124
readonly isEditing?: boolean;
2225
readonly queuedCount: number;
2326
readonly text: string;
27+
readonly releaseAt?: DateTime.Utc | string | null | undefined;
2428
}): ThreadQueueRowControls {
2529
const mutationEnabled = !input.busy;
2630
const isEditing = input.isEditing === true;
31+
const releaseAt =
32+
input.releaseAt === null || input.releaseAt === undefined
33+
? null
34+
: typeof input.releaseAt === "string"
35+
? new Date(input.releaseAt)
36+
: DateTime.toDate(input.releaseAt);
2737

2838
return {
2939
canDismiss: !input.busy,
@@ -32,10 +42,15 @@ export function resolveThreadQueueRowControls(input: {
3242
canEdit: mutationEnabled && !isEditing,
3343
canMoveDown: mutationEnabled && input.canReorder && input.index < input.queuedCount - 1,
3444
canMoveUp: mutationEnabled && input.canReorder && input.index > 0,
35-
canSteer: mutationEnabled && input.canPromoteToSteer && !isEditing,
45+
// Steering would send a delayed message before the time it was scheduled for.
46+
canSteer: mutationEnabled && input.canPromoteToSteer && !isEditing && releaseAt === null,
3647
dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
3748
displayText: input.text,
3849
isEditing,
50+
releaseLabel:
51+
releaseAt === null || Number.isNaN(releaseAt.getTime())
52+
? null
53+
: `Sends at ${releaseAt.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" })}`,
3954
};
4055
}
4156

‎apps/server/src/environment/ServerEnvironment.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
229229
expect(second.capabilities.threadPullRequests).toBe(true);
230230
expect(second.capabilities.threadPullRequestLinking).toBe(true);
231231
expect(second.capabilities.serverResolvedCommandContext).toBe(true);
232+
expect(second.capabilities.delayedMessages).toBe(true);
232233
expect(second.capabilities.projectProviderInstanceOverrides).toBe(true);
233234
expect(second.capabilities.agentActivityPublishing).toBe(false);
234235
}),

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export const make = Effect.gen(function* () {
255255
pullRequestStackActions: true,
256256
threadPullRequestLinking: true,
257257
serverResolvedCommandContext: true,
258+
delayedMessages: true,
258259
environmentIcon: true,
259260
projectCloneTracking: true,
260261
...(serverSelfUpdate === null ? {} : { serverSelfUpdate }),

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,3 +2171,25 @@ describe("OrchestratorMcpService provider resolution", () => {
21712171
);
21722172
});
21732173
});
2174+
2175+
describe("hasPendingChildRuns", () => {
2176+
const delegatedRun = { id: RunId.make("run:delegated"), ordinal: 1, status: "completed" };
2177+
const pendingWith = (followup: Record<string, unknown>) =>
2178+
OrchestratorMcpService.hasPendingChildRuns(
2179+
{
2180+
runs: [delegatedRun, { id: RunId.make("run:followup"), ordinal: 2, ...followup }],
2181+
} as unknown as Pick<OrchestrationV2ThreadProjection, "runs">,
2182+
delegatedRun as unknown as OrchestrationV2ThreadProjection["runs"][number],
2183+
);
2184+
2185+
it("leaves a completed task settled while its follow-up waits to be sent", () => {
2186+
assert.isTrue(pendingWith({ status: "queued" }));
2187+
assert.isFalse(pendingWith({ status: "queued", queueHeld: true }));
2188+
assert.isFalse(
2189+
pendingWith({
2190+
status: "queued",
2191+
releaseAt: DateTime.makeUnsafe("2026-10-16T12:05:00.000Z"),
2192+
}),
2193+
);
2194+
});
2195+
});

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
type ServerProvider,
6060
ThreadId,
6161
} from "@t3tools/contracts";
62-
import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
62+
import { isWaitingQueuedRun, runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
6363
import * as Clock from "effect/Clock";
6464
import * as Context from "effect/Context";
6565
import * as Crypto from "effect/Crypto";
@@ -389,7 +389,7 @@ export function hasPendingChildRuns(
389389
return childProjection.runs.some(
390390
(run) =>
391391
!ThreadManagementService.isTerminalRunStatus(run.status) &&
392-
!(run.status === "queued" && run.queueHeld === true) &&
392+
!isWaitingQueuedRun(run) &&
393393
(delegatedRun === undefined || run.ordinal > delegatedRun.ordinal),
394394
);
395395
}

0 commit comments

Comments
 (0)