Skip to content

Commit 13d459e

Browse files
t3dotggclaude
andcommitted
Migrate clients to the server-backed settled lifecycle
settle/unsettle now dispatch thread.settle / thread.unsettle instead of riding archive/unarchive, and effectiveSettled keys on the projected settledOverride/settledAt. Because settled threads stay in the live shell stream, the archive-era workarounds are deleted: - settledHolds optimistic-hold machinery (web + mobile) - archived-snapshot merging into the v2 lists - unarchive-on-open when activating a settled row — opening is plain navigation now, and history stays readable without un-settling - the auto-settled un-settle special case: reason 'user' pins any settled row active until real activity clears the pin Archive regains its original meaning (hidden from lists) and is no longer offered as settle's alias anywhere in v2. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent d3431e0 commit 13d459e

9 files changed

Lines changed: 154 additions & 411 deletions

File tree

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,12 @@ export function HomeRouteScreen() {
123123
onProjectSortOrderChange={setProjectSortOrder}
124124
onSearchQueryChange={setSearchQuery}
125125
onSelectThread={(thread) => {
126-
// Archived (= manually settled) rows are invisible to the live
127-
// thread queries — opening the screen without unarchiving leaves
128-
// it unresolvable and can drop outbox sends. Opening is
129-
// activity, and activity un-settles: unarchive first, then
130-
// navigate. Auto-settled rows (archivedAt null) are still live.
131-
void (async () => {
132-
if (thread.archivedAt !== null) {
133-
const unsettled = await unsettleThread(thread);
134-
if (!unsettled) return;
135-
}
136-
navigation.navigate("Thread", {
137-
environmentId: thread.environmentId,
138-
threadId: thread.id,
139-
});
140-
})();
126+
// Settled threads are live shells: opening one is plain
127+
// navigation, and sending a message un-settles server-side.
128+
navigation.navigate("Thread", {
129+
environmentId: thread.environmentId,
130+
threadId: thread.id,
131+
});
141132
}}
142133
onSelectPendingTask={openPendingTask}
143134
onDeletePendingTask={confirmDeletePendingTask}

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 16 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import { AppText as Text } from "../../components/AppText";
2424
import { EmptyState } from "../../components/EmptyState";
2525
import type { WorkspaceState } from "../../state/workspaceModel";
2626
import type { SavedRemoteConnection } from "../../lib/connection";
27-
import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
28-
import { useArchivedThreadSnapshots } from "../archive/useArchivedThreadSnapshots";
27+
import { scopedProjectKey } from "../../lib/scopedEntities";
2928
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
3029
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
3130
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
@@ -291,15 +290,9 @@ export function HomeScreen(props: HomeScreenProps) {
291290

292291
// Thread List v2 (beta): one flat list in creation order, no grouping.
293292
// Settled threads collapse into a recency tail below the card block.
294-
// Settle = archive in the client-only model, and the live shell stream
295-
// drops archived threads — merge them back from the archived snapshot so
296-
// they render as the settled tail. Live shells win on overlap.
297-
const archivedEnvironmentIds = useMemo(
298-
() =>
299-
threadListV2Enabled ? props.environments.map((environment) => environment.environmentId) : [],
300-
[props.environments, threadListV2Enabled],
301-
);
302-
const { snapshots: archivedSnapshots } = useArchivedThreadSnapshots(archivedEnvironmentIds);
293+
// Settled threads stay in the live shell stream (settled ≠ archived), so
294+
// the partition works directly off live shells — no snapshot merging or
295+
// optimistic holds.
303296
// PR states stream in per-row (rows own the VCS subscriptions); a merged or
304297
// closed PR auto-settles its thread on the next partition (mirrors web).
305298
const [changeRequestStateByKey, setChangeRequestStateByKey] = useState<
@@ -320,84 +313,14 @@ export function HomeScreen(props: HomeScreenProps) {
320313
},
321314
[],
322315
);
323-
// Bridge the gap between the live stream dropping a just-settled thread
324-
// and the archived snapshot returning it: hold the shell we settled,
325-
// marked archived, until the snapshot carries it. Held explicitly at
326-
// settle time so deleted threads are never resurrected.
327-
const [settledHolds, setSettledHolds] = useState<ReadonlyMap<string, EnvironmentThreadShell>>(
328-
() => new Map(),
329-
);
330316
const handleSettleThread = useCallback(
331317
(thread: EnvironmentThreadShell) => {
332-
const threadKey = scopedThreadKey(thread.environmentId, thread.id);
333-
// An existing hold means a settle for this thread is already in flight
334-
// (or done and awaiting its snapshot). Re-triggering would fail the
335-
// executor's in-flight check and the rollback below would strip the
336-
// first settle's hold, flickering the row out of the settled tail.
337-
if (settledHolds.has(threadKey)) {
338-
return;
339-
}
340-
setSettledHolds((current) =>
341-
new Map(current).set(threadKey, {
342-
...thread,
343-
archivedAt: thread.archivedAt ?? new Date().toISOString(),
344-
}),
345-
);
346-
void (async () => {
347-
// Roll the optimistic hold back if the settle was blocked or failed —
348-
// otherwise a never-archived thread would render settled forever.
349-
const succeeded = await props.onSettleThread(thread);
350-
if (!succeeded) {
351-
setSettledHolds((current) => {
352-
const next = new Map(current);
353-
next.delete(threadKey);
354-
return next;
355-
});
356-
}
357-
})();
318+
void props.onSettleThread(thread);
358319
},
359-
[props.onSettleThread, settledHolds],
320+
[props.onSettleThread],
360321
);
361-
// Delete and un-settle both invalidate any hold for the thread.
362-
const dropSettledHold = useCallback((thread: EnvironmentThreadShell) => {
363-
setSettledHolds((current) => {
364-
const threadKey = scopedThreadKey(thread.environmentId, thread.id);
365-
if (!current.has(threadKey)) return current;
366-
const next = new Map(current);
367-
next.delete(threadKey);
368-
return next;
369-
});
370-
}, []);
371-
const handleDeleteThread = useCallback(
372-
(thread: EnvironmentThreadShell) => {
373-
dropSettledHold(thread);
374-
props.onDeleteThread(thread);
375-
},
376-
[dropSettledHold, props.onDeleteThread],
377-
);
378-
const handleUnsettleThread = useCallback(
379-
(thread: EnvironmentThreadShell) => {
380-
dropSettledHold(thread);
381-
props.onUnsettleThread(thread);
382-
},
383-
[dropSettledHold, props.onUnsettleThread],
384-
);
385-
useEffect(() => {
386-
if (settledHolds.size === 0) return;
387-
const covered = new Set<string>();
388-
for (const { environmentId, snapshot } of archivedSnapshots) {
389-
for (const thread of snapshot.threads) {
390-
covered.add(scopedThreadKey(environmentId, thread.id));
391-
}
392-
}
393-
if ([...settledHolds.keys()].some((threadKey) => covered.has(threadKey))) {
394-
setSettledHolds((current) => {
395-
const next = new Map(current);
396-
for (const threadKey of covered) next.delete(threadKey);
397-
return next;
398-
});
399-
}
400-
}, [archivedSnapshots, settledHolds]);
322+
const handleDeleteThread = props.onDeleteThread;
323+
const handleUnsettleThread = props.onUnsettleThread;
401324
// The settled tail renders in pages; expansion resets when the filter
402325
// context changes so environment/search flips never inherit a deep page.
403326
const [settledVisibleCount, setSettledVisibleCount] = useState(
@@ -424,21 +347,10 @@ export function HomeScreen(props: HomeScreenProps) {
424347
}, [threadListV2Enabled]);
425348
const threadListV2Layout = useMemo(() => {
426349
if (!threadListV2Enabled) return { items: [], hiddenSettledCount: 0 };
427-
const merged = new Map<string, EnvironmentThreadShell>();
428-
for (const { environmentId, snapshot } of archivedSnapshots) {
429-
for (const thread of snapshot.threads) {
430-
merged.set(scopedThreadKey(environmentId, thread.id), { ...thread, environmentId });
431-
}
432-
}
433-
for (const thread of props.threads) {
434-
merged.set(scopedThreadKey(thread.environmentId, thread.id), thread);
435-
}
436-
for (const [threadKey, shell] of settledHolds) {
437-
if (merged.has(threadKey)) continue;
438-
merged.set(threadKey, shell);
439-
}
350+
// Settled threads are live shells; archived threads keep their original
351+
// "hidden from lists" meaning.
440352
return buildThreadListV2Items({
441-
threads: [...merged.values()],
353+
threads: props.threads.filter((thread) => thread.archivedAt === null),
442354
environmentId: props.selectedEnvironmentId,
443355
searchQuery: props.searchQuery,
444356
changeRequestStateByKey,
@@ -448,9 +360,7 @@ export function HomeScreen(props: HomeScreenProps) {
448360
}, [
449361
changeRequestStateByKey,
450362
nowMinute,
451-
settledHolds,
452363
settledVisibleCount,
453-
archivedSnapshots,
454364
props.searchQuery,
455365
props.selectedEnvironmentId,
456366
props.threads,
@@ -591,17 +501,12 @@ export function HomeScreen(props: HomeScreenProps) {
591501
const keyExtractor = useCallback((item: HomeListItem) => item.key, []);
592502

593503
/* Empty states */
594-
// v2 shows archived threads as its settled tail, so an archived-only
595-
// workspace still has a list to render there. The signal must ignore the
596-
// search/environment filters: an active query that matches nothing needs
597-
// the in-list "No results" state, not the full-page "No threads yet".
504+
// The signal must ignore the search/environment filters: an active query
505+
// that matches nothing needs the in-list "No results" state, not the
506+
// full-page "No threads yet". Settled threads are unarchived live shells,
507+
// so the v1 check already covers v2.
598508
const hasAnyThreads =
599-
props.threads.some((thread) => thread.archivedAt === null) ||
600-
props.pendingTasks.length > 0 ||
601-
(threadListV2Enabled &&
602-
(props.threads.length > 0 ||
603-
settledHolds.size > 0 ||
604-
archivedSnapshots.some(({ snapshot }) => snapshot.threads.length > 0)));
509+
props.threads.some((thread) => thread.archivedAt === null) || props.pendingTasks.length > 0;
605510
const hasResults = projectGroups.length > 0;
606511
const selectedEnvironmentLabel =
607512
props.selectedEnvironmentId === null

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

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ function useThreadActionExecutor(
4848
const archiveMutation = useAtomCommand(threadEnvironment.archive, { reportFailure: false });
4949
const unarchiveMutation = useAtomCommand(threadEnvironment.unarchive, { reportFailure: false });
5050
const deleteMutation = useAtomCommand(threadEnvironment.delete, { reportFailure: false });
51-
// Client-only settled model: settle/unsettle ride the archive lifecycle so
52-
// no server upgrade is required. See client-runtime threadSettled.ts.
53-
const settleMutation = archiveMutation;
54-
const unsettleMutation = unarchiveMutation;
51+
const settleMutation = useAtomCommand(threadEnvironment.settle, { reportFailure: false });
52+
const unsettleMutation = useAtomCommand(threadEnvironment.unsettle, { reportFailure: false });
5553
const inFlightThreadKeys = useRef(new Set<string>());
5654

5755
const executeAction = useCallback(
@@ -87,35 +85,35 @@ function useThreadActionExecutor(
8785
);
8886
return false;
8987
}
90-
// Auto-settled rows (inactivity / merged PR) are not archived;
91-
// unarchiving them would be rejected. Nothing to undo — no-op.
92-
if (action === "unsettle" && thread.archivedAt === null) {
93-
return false;
94-
}
95-
const mutation =
96-
action === "settle"
97-
? settleMutation
98-
: action === "unsettle"
99-
? unsettleMutation
100-
: action === "archive"
101-
? archiveMutation
102-
: action === "unarchive"
103-
? unarchiveMutation
104-
: deleteMutation;
105-
const result = await mutation({
106-
environmentId: thread.environmentId,
107-
input: { threadId: thread.id },
108-
});
88+
const result =
89+
action === "unsettle"
90+
? // reason "user" pins the thread active: auto-settle stays
91+
// suppressed until real activity clears the pin server-side.
92+
await unsettleMutation({
93+
environmentId: thread.environmentId,
94+
input: { threadId: thread.id, reason: "user" },
95+
})
96+
: await (
97+
action === "settle"
98+
? settleMutation
99+
: action === "archive"
100+
? archiveMutation
101+
: action === "unarchive"
102+
? unarchiveMutation
103+
: deleteMutation
104+
)({
105+
environmentId: thread.environmentId,
106+
input: { threadId: thread.id },
107+
});
109108
if (result._tag === "Failure") {
110109
Alert.alert(actionFailureTitle(action), actionFailureMessage(action, result.cause));
111110
return false;
112111
}
113-
// Archived threads leave the live shell stream, and the v2 list
114-
// renders them from the archived snapshot — keep it fresh for every
115-
// action that changes what that snapshot should contain (delete
116-
// included, or a deleted settled row lingers until some later
117-
// refresh).
118-
refreshArchivedThreadsForEnvironment(thread.environmentId);
112+
// Settled threads stay in the live shell stream; only the archive
113+
// lifecycle still feeds the archived-snapshot surface.
114+
if (action === "archive" || action === "unarchive" || action === "delete") {
115+
refreshArchivedThreadsForEnvironment(thread.environmentId);
116+
}
119117
onCompleted?.(action, thread);
120118
return true;
121119
} finally {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
187187
[handleDelete, handleSettle, handleUnsettle],
188188
);
189189

190-
// Swipe: the v2 primary action is the lifecycle transition. Un-settle only
191-
// exists when there is an archive to undo; an auto-settled slim row
192-
// (inactivity / merged PR, archivedAt null) offers Settle, which archives
193-
// it — the explicit "keep it settled" the row can actually deliver.
194-
const canUnsettle = variant === "slim" && thread.archivedAt !== null;
190+
// Swipe: the v2 primary action is the lifecycle transition. Every settled
191+
// row can un-settle — explicit settles clear the override, auto-settled
192+
// rows get pinned active until real activity clears the pin.
193+
const canUnsettle = variant === "slim";
195194
const primaryAction = useMemo(
196195
() =>
197196
canUnsettle

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,21 @@ describe("sortThreadsForListV2", () => {
7777
});
7878

7979
describe("buildThreadListV2Items", () => {
80-
it("partitions archived (settled) threads into a slim tail with one divider", () => {
80+
it("partitions settled threads into a slim tail with one divider", () => {
8181
const { items } = buildThreadListV2Items({
8282
threads: [
8383
makeThread({ id: ThreadId.make("active"), title: "Active" }),
8484
makeThread({
8585
id: ThreadId.make("settled"),
8686
title: "Settled",
87-
archivedAt: NOW,
87+
settledOverride: "settled",
88+
settledAt: NOW,
8889
}),
8990
makeThread({
9091
id: ThreadId.make("settled-2"),
9192
title: "Settled 2",
92-
archivedAt: NOW,
93+
settledOverride: "settled",
94+
settledAt: NOW,
9395
}),
9496
],
9597
environmentId: null,
@@ -129,15 +131,16 @@ describe("buildThreadListV2Items", () => {
129131
expect(items.map((item) => item.thread.id)).toEqual(["newer-created", "older-created"]);
130132
});
131133

132-
it("keeps archived threads in the tail and filters by search query", () => {
134+
it("keeps settled threads in the tail and filters by search query", () => {
133135
const { items } = buildThreadListV2Items({
134136
threads: [
135137
makeThread({ id: ThreadId.make("match"), title: "Fix login bug" }),
136138
makeThread({ id: ThreadId.make("miss"), title: "Greeting" }),
137139
makeThread({
138-
id: ThreadId.make("archived"),
140+
id: ThreadId.make("settled"),
139141
title: "Fix login again",
140-
archivedAt: NOW,
142+
settledOverride: "settled",
143+
settledAt: NOW,
141144
}),
142145
],
143146
environmentId: null,
@@ -147,7 +150,7 @@ describe("buildThreadListV2Items", () => {
147150

148151
expect(items.map((item) => [item.thread.id, item.variant])).toEqual([
149152
["match", "card"],
150-
["archived", "slim"],
153+
["settled", "slim"],
151154
]);
152155
});
153156
});
@@ -160,7 +163,8 @@ describe("buildThreadListV2Items settled paging", () => {
160163
makeThread({
161164
id: ThreadId.make(`settled-${index}`),
162165
title: `Settled ${index}`,
163-
archivedAt: NOW,
166+
settledOverride: "settled",
167+
settledAt: NOW,
164168
latestUserMessageAt: `2026-06-01T0${index}:00:00.000Z`,
165169
}),
166170
),

0 commit comments

Comments
 (0)