Skip to content

Commit 30efc88

Browse files
feat(sidebar): settle a running thread once the agent finishes
Settle on a working thread arms a one-shot settle-when-idle intent instead of failing. The row files with the settled threads while the agent keeps running, and ThreadSettlementReactor settles it through thread.auto-settle once the thread is idle, background work included. A new message, un-settle, pin, drag back, request, or failure cancels it. The quiet finish skips completion notifications. Implements #13630. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent bd89c13 commit 30efc88

41 files changed

Lines changed: 849 additions & 81 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { ThreadMoveDestination } from "../threads/threadOrder";
22
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
3-
import { canSnooze, effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled";
3+
import {
4+
canSnooze,
5+
effectiveSnoozed,
6+
isFiledAsSettled,
7+
} from "@t3tools/client-runtime/state/thread-settled";
48
import * as Cause from "effect/Cause";
59
import * as Haptics from "expo-haptics";
610
import { useCallback, useRef } from "react";
@@ -642,8 +646,7 @@ export function useThreadListActions(): {
642646
crossSection &&
643647
(((section === "pinned" || thread.pinnedAt != null) &&
644648
!environmentSupportsPinning(thread.environmentId)) ||
645-
(thread.settledOverride === "settled" &&
646-
!environmentSupportsSettlement(thread.environmentId)) ||
649+
(isFiledAsSettled(thread) && !environmentSupportsSettlement(thread.environmentId)) ||
647650
(effectiveSnoozed(thread, { now: new Date().toISOString() }) &&
648651
!environmentSupportsSnooze(thread.environmentId)))
649652
)

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11971197
onSwipeableWillOpen={props.onSwipeableWillOpen}
11981198
primaryAction={primaryAction}
11991199
secondaryAction={secondaryAction}
1200-
resetKey={`${thread.environmentId}:${thread.id}:${variant}:${snoozedRow}:${thread.settledAt}:${thread.unsettledAt}:${thread.snoozedUntil}`}
1200+
resetKey={`${thread.environmentId}:${thread.id}:${variant}:${snoozedRow}:${thread.settledAt}:${thread.settleWhenIdleAt}:${thread.unsettledAt}:${thread.snoozedUntil}`}
12011201
simultaneousWithExternalGesture={props.simultaneousSwipeGesture}
12021202
threadTitle={thread.title}
12031203
>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,25 @@ describe("buildThreadListV2Items", () => {
393393
expect(layout.items[0]?.variant).toBe("slim");
394394
});
395395

396+
it("files a thread waiting to settle when idle with the settled threads", () => {
397+
const thread = makeThread({
398+
id: ThreadId.make("settles-when-idle"),
399+
title: "Still working",
400+
settleWhenIdleAt: NOW,
401+
});
402+
const layout = buildThreadListV2Items({
403+
threads: [thread],
404+
environmentId: null,
405+
searchQuery: "",
406+
now: NOW,
407+
});
408+
409+
expect(layout.settledCount).toBe(1);
410+
expect(
411+
getThreadListV2OrderedSection({ threads: [thread], section: "active", now: NOW }),
412+
).toEqual([]);
413+
});
414+
396415
it("hides snoozed threads and counts them — visibility parity with web", () => {
397416
const layout = buildThreadListV2Items({
398417
threads: [

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
canSnooze,
44
effectiveSnoozed,
55
hasQueuedTurnStart,
6+
isFiledAsSettled,
67
QUEUED_TURN_START_GRACE_MS,
78
resolveSnoozePresets,
89
snoozeWakeLabel,
@@ -170,7 +171,7 @@ export function getThreadListV2OrderedSection(input: {
170171
if (thread.archivedAt !== null) return false;
171172
if (
172173
(input.settlementEnvironmentIds?.has(thread.environmentId) ?? true) &&
173-
thread.settledOverride === "settled" &&
174+
isFiledAsSettled(thread) &&
174175
input.queuedThreadKeys?.has(`${thread.environmentId}:${thread.id}`) !== true
175176
) {
176177
return false;
@@ -586,7 +587,7 @@ export function buildThreadListV2Items(input: {
586587
}
587588
const hasQueuedMessages =
588589
input.queuedThreadKeys?.has(`${thread.environmentId}:${thread.id}`) === true;
589-
if (supportsSettlement && thread.settledOverride === "settled" && !hasQueuedMessages) {
590+
if (supportsSettlement && isFiledAsSettled(thread) && !hasQueuedMessages) {
590591
settled.push(thread);
591592
} else if (thread.pinnedAt != null) {
592593
pinned.push(thread);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
pinOrderKeyBetween,
55
planPinnedReorder,
66
} from "@t3tools/client-runtime/state/thread-sort";
7-
import { effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled";
7+
import { effectiveSnoozed, isFiledAsSettled } from "@t3tools/client-runtime/state/thread-settled";
88
import type { EnvironmentId } from "@t3tools/contracts";
99

1010
export type ThreadMoveDestination =
@@ -311,7 +311,7 @@ export function threadDropLifecycle(
311311
return {
312312
pin: false,
313313
unpin: thread.pinnedAt != null,
314-
unsettle: thread.settledOverride === "settled",
314+
unsettle: isFiledAsSettled(thread),
315315
unsnooze: effectiveSnoozed(thread, { now }),
316316
};
317317
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function threadDetailToShell(
7575
unsettledAt: thread.unsettledAt,
7676
activeOrderKey: thread.activeOrderKey,
7777
autoSettleDisabledAt: thread.autoSettleDisabledAt,
78+
settleWhenIdleAt: thread.settleWhenIdleAt,
7879
pinnedAt: thread.pinnedAt,
7980
pinOrderKey: thread.pinOrderKey,
8081
snoozedUntil: thread.snoozedUntil ?? null,

‎apps/server/src/orchestration/Layers/ProjectionPipeline.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
634634
pinOrderKey: null,
635635
activeOrderKey: null,
636636
autoSettleDisabledAt: null,
637+
settleWhenIdleAt: null,
637638
titleRegenerationRequestId: null,
638639
titleRegenerationStartedAt: null,
639640
latestUserMessageAt: null,
@@ -689,6 +690,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
689690
settledAt: event.payload.settledAt,
690691
unsettledAt: null,
691692
activeOrderKey: null,
693+
settleWhenIdleAt: null,
692694
updatedAt: event.payload.updatedAt,
693695
});
694696
return;
@@ -798,6 +800,21 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
798800
return;
799801
}
800802

803+
case "thread.settle-when-idle-set": {
804+
const existingRow = yield* projectionThreadRepository.getById({
805+
threadId: event.payload.threadId,
806+
});
807+
if (Option.isNone(existingRow)) {
808+
return;
809+
}
810+
yield* projectionThreadRepository.upsert({
811+
...existingRow.value,
812+
settleWhenIdleAt: event.payload.settleWhenIdleAt,
813+
updatedAt: event.payload.updatedAt,
814+
});
815+
return;
816+
}
817+
801818
case "thread.pin-reordered": {
802819
const existingRow = yield* projectionThreadRepository.getById({
803820
threadId: event.payload.threadId,

‎apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
487487
pinOrderKey: "gm",
488488
activeOrderKey: "hq",
489489
autoSettleDisabledAt: null,
490+
settleWhenIdleAt: null,
490491
titleRegeneration: null,
491492
titleState: null,
492493
deletedAt: null,
@@ -614,6 +615,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
614615
pinOrderKey: "gm",
615616
activeOrderKey: "hq",
616617
autoSettleDisabledAt: null,
618+
settleWhenIdleAt: null,
617619
titleRegeneration: null,
618620
titleState: null,
619621
session: {

‎apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
589589
pin_order_key AS "pinOrderKey",
590590
active_order_key AS "activeOrderKey",
591591
auto_settle_disabled_at AS "autoSettleDisabledAt",
592+
settle_when_idle_at AS "settleWhenIdleAt",
592593
title_regeneration_request_id AS "titleRegenerationRequestId",
593594
title_regeneration_started_at AS "titleRegenerationStartedAt",
594595
latest_user_message_at AS "latestUserMessageAt",
@@ -637,6 +638,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
637638
pin_order_key AS "pinOrderKey",
638639
active_order_key AS "activeOrderKey",
639640
auto_settle_disabled_at AS "autoSettleDisabledAt",
641+
settle_when_idle_at AS "settleWhenIdleAt",
640642
title_regeneration_request_id AS "titleRegenerationRequestId",
641643
title_regeneration_started_at AS "titleRegenerationStartedAt",
642644
latest_user_message_at AS "latestUserMessageAt",
@@ -712,6 +714,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
712714
pin_order_key AS "pinOrderKey",
713715
active_order_key AS "activeOrderKey",
714716
auto_settle_disabled_at AS "autoSettleDisabledAt",
717+
settle_when_idle_at AS "settleWhenIdleAt",
715718
title_regeneration_request_id AS "titleRegenerationRequestId",
716719
title_regeneration_started_at AS "titleRegenerationStartedAt",
717720
latest_user_message_at AS "latestUserMessageAt",
@@ -1316,6 +1319,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
13161319
pin_order_key AS "pinOrderKey",
13171320
active_order_key AS "activeOrderKey",
13181321
auto_settle_disabled_at AS "autoSettleDisabledAt",
1322+
settle_when_idle_at AS "settleWhenIdleAt",
13191323
title_regeneration_request_id AS "titleRegenerationRequestId",
13201324
title_regeneration_started_at AS "titleRegenerationStartedAt",
13211325
latest_user_message_at AS "latestUserMessageAt",
@@ -2392,6 +2396,7 @@ pending_approval_requests AS (
23922396
pinOrderKey: row.pinOrderKey ?? null,
23932397
activeOrderKey: row.activeOrderKey ?? null,
23942398
autoSettleDisabledAt: row.autoSettleDisabledAt ?? null,
2399+
settleWhenIdleAt: row.settleWhenIdleAt ?? null,
23952400
titleRegeneration: mapTitleRegeneration(row),
23962401
titleState: row.titleState,
23972402
deletedAt: row.deletedAt,
@@ -2638,6 +2643,7 @@ pending_approval_requests AS (
26382643
pinOrderKey: row.pinOrderKey ?? null,
26392644
activeOrderKey: row.activeOrderKey ?? null,
26402645
autoSettleDisabledAt: row.autoSettleDisabledAt ?? null,
2646+
settleWhenIdleAt: row.settleWhenIdleAt ?? null,
26412647
titleRegeneration: mapTitleRegeneration(row),
26422648
titleState: row.titleState,
26432649
deletedAt: row.deletedAt,
@@ -2799,6 +2805,7 @@ pending_approval_requests AS (
27992805
pinOrderKey: row.pinOrderKey ?? null,
28002806
activeOrderKey: row.activeOrderKey ?? null,
28012807
autoSettleDisabledAt: row.autoSettleDisabledAt ?? null,
2808+
settleWhenIdleAt: row.settleWhenIdleAt ?? null,
28022809
titleRegeneration: mapTitleRegeneration(row),
28032810
titleState: row.titleState,
28042811
session: sessionByThread.get(row.threadId) ?? null,
@@ -2985,6 +2992,7 @@ pending_approval_requests AS (
29852992
pinOrderKey: row.pinOrderKey ?? null,
29862993
activeOrderKey: row.activeOrderKey ?? null,
29872994
autoSettleDisabledAt: row.autoSettleDisabledAt ?? null,
2995+
settleWhenIdleAt: row.settleWhenIdleAt ?? null,
29882996
titleRegeneration: mapTitleRegeneration(row),
29892997
titleState: row.titleState,
29902998
session: sessionByThread.get(row.threadId) ?? null,
@@ -3334,6 +3342,7 @@ pending_approval_requests AS (
33343342
pinOrderKey: threadRow.value.pinOrderKey ?? null,
33353343
activeOrderKey: threadRow.value.activeOrderKey ?? null,
33363344
autoSettleDisabledAt: threadRow.value.autoSettleDisabledAt ?? null,
3345+
settleWhenIdleAt: threadRow.value.settleWhenIdleAt ?? null,
33373346
titleRegeneration: mapTitleRegeneration(threadRow.value),
33383347
titleState: threadRow.value.titleState,
33393348
session: Option.isSome(sessionRow) ? mapSessionRow(sessionRow.value) : null,
@@ -3636,6 +3645,7 @@ pending_approval_requests AS (
36363645
pinOrderKey: threadRow.value.pinOrderKey ?? null,
36373646
activeOrderKey: threadRow.value.activeOrderKey ?? null,
36383647
autoSettleDisabledAt: threadRow.value.autoSettleDisabledAt ?? null,
3648+
settleWhenIdleAt: threadRow.value.settleWhenIdleAt ?? null,
36393649
titleRegeneration: mapTitleRegeneration(threadRow.value),
36403650
titleState: threadRow.value.titleState,
36413651
deletedAt: null,

‎apps/server/src/orchestration/Normalizer.attachments.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import * as Schema from "effect/Schema";
2020
import * as ServerConfig from "../config.ts";
2121
import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
2222
import { cleanupFailedUploadedAttachments, normalizeDispatchCommand } from "./Normalizer.ts";
23+
import { ProjectionSnapshotQuery } from "./Services/ProjectionSnapshotQuery.ts";
2324

2425
const testLayer = Layer.mergeAll(
2526
WorkspacePaths.layer,
2627
ServerConfig.layerTest(process.cwd(), { prefix: "t3-normalizer-attachments-" }),
28+
Layer.mock(ProjectionSnapshotQuery)({}),
2729
).pipe(Layer.provideMerge(NodeServices.layer));
2830

2931
const attachmentUuid = "00000000-0000-4000-8000-0000000000aa";

0 commit comments

Comments
 (0)