Skip to content

Commit d6858e9

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-26407
2 parents 93b440d + c3858bf commit d6858e9

34 files changed

Lines changed: 1724 additions & 269 deletions

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

Lines changed: 95 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,92 @@ function compactionLabel(label: string, title: string | undefined) {
12081208
: label;
12091209
}
12101210

1211+
function RunFoldButton({
1212+
entry,
1213+
environmentId,
1214+
threadId,
1215+
onToggle,
1216+
rowSizing,
1217+
iconColor,
1218+
}: {
1219+
entry: Extract<ThreadFeedEntry, { type: "run-fold" }>;
1220+
environmentId: EnvironmentId;
1221+
threadId: ThreadId;
1222+
onToggle: (runId: RunId) => void;
1223+
rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
1224+
iconColor: ColorValue;
1225+
}) {
1226+
const loadWork = useAtomCommand(threadEnvironment.loadEarlierHistory, { reportFailure: false });
1227+
const anchorsKey = entry.deferredWorkItemIds?.join("\n") ?? "";
1228+
const [failed, setFailed] = useState(false);
1229+
const load = () => {
1230+
if (!anchorsKey) return;
1231+
void Promise.all(
1232+
anchorsKey
1233+
.split("\n")
1234+
.map((workAnchorId) => loadWork({ environmentId, input: { threadId, workAnchorId } })),
1235+
).then((results) =>
1236+
setFailed(
1237+
results.some((result) => result._tag === "Failure" || result.value._tag === "error"),
1238+
),
1239+
);
1240+
};
1241+
const loadOnExpand = useEffectEvent(load);
1242+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Restored expanded folds load their deferred server history on mount.
1243+
useEffect(() => {
1244+
if (entry.expanded && anchorsKey && environmentId && threadId) loadOnExpand();
1245+
}, [entry.expanded, anchorsKey, environmentId, threadId]);
1246+
const error = anchorsKey && failed ? "Couldn't load work. Tap to retry." : null;
1247+
const loading = entry.expanded && anchorsKey !== "" && !failed;
1248+
const toggle = () => {
1249+
setFailed(false);
1250+
if (error && entry.expanded) load();
1251+
else onToggle(entry.runId);
1252+
};
1253+
1254+
return (
1255+
<View className="min-w-0 flex-1">
1256+
<Pressable
1257+
accessibilityRole="button"
1258+
accessibilityState={{ expanded: entry.expanded, busy: loading }}
1259+
onPress={toggle}
1260+
hitSlop={4}
1261+
className="min-h-11 min-w-0 flex-1 flex-row items-center gap-2"
1262+
style={{ minHeight: Math.max(TURN_FOLD_HEIGHT - 3.5, rowSizing.estimatedRowHeight) }}
1263+
>
1264+
<Text
1265+
key={rowSizing.textSizeKey}
1266+
numberOfLines={1}
1267+
className="shrink font-t3-medium text-sm tabular-nums text-foreground-muted"
1268+
>
1269+
{entry.label}
1270+
{error ? ` · ${error}` : ""}
1271+
</Text>
1272+
<ThreadDisclosureChevron
1273+
expanded={entry.expanded}
1274+
collapsedDirection="right"
1275+
size={15}
1276+
tintColor={iconColor}
1277+
/>
1278+
</Pressable>
1279+
{loading ? (
1280+
<View
1281+
accessible={false}
1282+
importantForAccessibility="no-hide-descendants"
1283+
className="gap-2 px-1 pb-2"
1284+
>
1285+
{(["40%", "60%", "33%"] as const).map((width) => (
1286+
<View key={width} className="flex-row items-center gap-2">
1287+
<View className="size-3 rounded bg-subtle-strong" />
1288+
<View className="h-2.5 rounded-full bg-subtle-strong" style={{ width }} />
1289+
</View>
1290+
))}
1291+
</View>
1292+
) : null}
1293+
</View>
1294+
);
1295+
}
1296+
12111297
function renderFeedEntry(
12121298
info: { item: ThreadFeedRow; index: number },
12131299
props: Pick<
@@ -1279,30 +1365,15 @@ function renderFeedEntry(
12791365
if (entry.type === "run-fold") {
12801366
return (
12811367
<View className="mb-1 flex-row items-center border-b border-border-subtle px-2">
1282-
<Pressable
1283-
accessibilityRole="button"
1284-
accessibilityState={{ expanded: entry.expanded }}
1285-
onPress={() => props.onToggleTurnFold(entry.runId)}
1286-
hitSlop={4}
1287-
className="min-h-11 min-w-0 flex-1 flex-row items-center gap-2"
1288-
style={{
1289-
minHeight: Math.max(TURN_FOLD_HEIGHT - 3.5, props.workRowSizing.estimatedRowHeight),
1290-
}}
1291-
>
1292-
<Text
1293-
key={props.workRowSizing.textSizeKey}
1294-
numberOfLines={1}
1295-
className="shrink font-t3-medium text-sm tabular-nums text-foreground-muted"
1296-
>
1297-
{entry.label}
1298-
</Text>
1299-
<ThreadDisclosureChevron
1300-
expanded={entry.expanded}
1301-
collapsedDirection="right"
1302-
size={15}
1303-
tintColor={iconSubtleColor}
1304-
/>
1305-
</Pressable>
1368+
<RunFoldButton
1369+
key={entry.id}
1370+
entry={entry}
1371+
environmentId={props.environmentId}
1372+
threadId={props.threadId}
1373+
onToggle={props.onToggleTurnFold}
1374+
rowSizing={props.workRowSizing}
1375+
iconColor={iconSubtleColor}
1376+
/>
13061377
{entry.checkpointSummary ? (
13071378
<TurnDiffStat
13081379
checkpoint={entry.checkpointSummary}

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,21 @@ describe("buildThreadFeed", () => {
809809
"message",
810810
"message",
811811
]);
812+
const anchor = {
813+
...command(),
814+
deferredWork: { cursor: "old-work", itemCount: 100, lastOrdinal: 100 },
815+
};
816+
const deferredFeed = buildThreadFeed([projected(userMessage(), 0), projected(anchor, 1)]);
817+
const running = { ...latestRun, status: "running" as const, completedAt: null };
818+
const deferredRows = deriveThreadFeedPresentation(deferredFeed, running, new Set());
819+
const disclosure = deferredRows.find((entry) => entry.type === "run-fold");
820+
expect(disclosure).toMatchObject({ deferredWorkItemIds: [anchor.id], expanded: false });
821+
if (disclosure?.type !== "run-fold") throw new Error("Expected deferred work disclosure");
822+
expect(
823+
deriveThreadFeedPresentation(deferredFeed, running, new Set([disclosure.runId])).some(
824+
(entry) => entry.type === "activity-group",
825+
),
826+
).toBe(true);
812827
expect(expanded[4]).toMatchObject({ message: { id: middle.messageId, text: middle.text } });
813828

814829
const active = deriveThreadFeedPresentation(

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ type ThreadFeedEntryContent =
231231
}
232232
| {
233233
readonly type: "run-fold";
234+
readonly deferredWorkItemIds?: ReadonlyArray<string>;
234235
readonly id: string;
235236
readonly createdAt: string;
236237
readonly runId: RunId;
@@ -1082,6 +1083,7 @@ function threadFeedActivityIsVisible(
10821083
}
10831084

10841085
interface ThreadFeedRunFold {
1086+
readonly deferredWorkItemIds?: ReadonlyArray<string>;
10851087
readonly runId: RunId;
10861088
readonly createdAt: string;
10871089
readonly hiddenEntryIds: ReadonlySet<string>;
@@ -1273,7 +1275,17 @@ function deriveThreadFeedRunFolds(
12731275
const duration = elapsedMs === null ? null : formatDuration(elapsedMs);
12741276
const interrupted =
12751277
latestRunMatches && (latestRun.status === "interrupted" || latestRun.status === "cancelled");
1278+
const deferredWorkItemIds = group.entries.flatMap((entry) =>
1279+
entry.type === "activity-group"
1280+
? entry.activities.flatMap((activity) =>
1281+
activity.projectedItem.item.deferredWork
1282+
? [String(activity.projectedItem.sourceItemId)]
1283+
: [],
1284+
)
1285+
: [],
1286+
);
12761287
foldsByAnchorId.set(firstHiddenEntry.id, {
1288+
...(deferredWorkItemIds.length > 0 ? { deferredWorkItemIds } : {}),
12771289
runId,
12781290
createdAt: firstHiddenEntry.createdAt,
12791291
hiddenEntryIds,
@@ -1286,6 +1298,23 @@ function deriveThreadFeedRunFolds(
12861298
: "Worked",
12871299
});
12881300
}
1301+
const covered = new Set(
1302+
[...foldsByAnchorId.values()].flatMap((fold) => [...fold.hiddenEntryIds]),
1303+
);
1304+
for (const entry of feed) {
1305+
if (entry.type !== "activity-group" || covered.has(entry.id)) continue;
1306+
const deferredWorkItemIds = entry.activities.flatMap((activity) =>
1307+
activity.projectedItem.item.deferredWork ? [String(activity.projectedItem.sourceItemId)] : [],
1308+
);
1309+
if (deferredWorkItemIds.length === 0) continue;
1310+
foldsByAnchorId.set(entry.id, {
1311+
runId: RunId.make(`deferred-work:${entry.id}`),
1312+
createdAt: entry.createdAt,
1313+
hiddenEntryIds: new Set([entry.id]),
1314+
label: "Earlier work",
1315+
deferredWorkItemIds,
1316+
});
1317+
}
12891318
return foldsByAnchorId;
12901319
}
12911320

@@ -1501,11 +1530,13 @@ export function deriveThreadFeedPresentation(
15011530
row.runId !== fold.runId ||
15021531
row.createdAt !== fold.createdAt ||
15031532
row.label !== fold.label ||
1504-
row.expanded !== expanded
1533+
row.expanded !== expanded ||
1534+
row.deferredWorkItemIds?.join("|") !== fold.deferredWorkItemIds?.join("|")
15051535
) {
15061536
row = {
15071537
type: "run-fold",
15081538
id: `run-fold:${fold.runId}`,
1539+
...(fold.deferredWorkItemIds ? { deferredWorkItemIds: fold.deferredWorkItemIds } : {}),
15091540
createdAt: fold.createdAt,
15101541
runId: fold.runId,
15111542
label: fold.label,
@@ -2189,7 +2220,7 @@ export function buildThreadFeed(
21892220
for (let index = restart?.row ?? 0; index < visibleTurnItems.length; index += 1) {
21902221
const row = visibleTurnItems[index]!;
21912222
const item = row.item;
2192-
if (turnItemIsWorkspacePreparation(item)) continue;
2223+
if (turnItemIsWorkspacePreparation(item) && !item.deferredWork) continue;
21932224
if (item.type === "todo_list" || item.type === "checkpoint") continue;
21942225
if (
21952226
item.type === "user_message" &&

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ export interface OrchestratorV2Shape {
344344
cursor: string,
345345
throughEntryId?: string,
346346
conversationOnly?: boolean,
347+
workMode?: "deferred" | "work",
347348
) => Effect.Effect<OrchestrationV2ThreadHistoryPage, OrchestratorV2Error>;
348349
readonly getTimelinePage: (
349350
threadId: ThreadId,
@@ -13281,9 +13282,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1328113282
);
1328213283
}),
1328313284
getThreadHistoryPage: Effect.fn("OrchestratorV2.getThreadHistoryPage")(
13284-
function (threadId, cursor, throughEntryId, conversationOnly) {
13285+
function (threadId, cursor, throughEntryId, conversationOnly, workMode) {
1328513286
return projectionStore
13286-
.getThreadHistoryPage(threadId, cursor, throughEntryId, conversationOnly)
13287+
.getThreadHistoryPage(threadId, cursor, throughEntryId, conversationOnly, workMode)
1328713288
.pipe(Effect.mapError((cause) => new OrchestratorProjectionError({ threadId, cause })));
1328813289
},
1328913290
),

0 commit comments

Comments
 (0)