Skip to content

Commit 57ac2c2

Browse files
fix(mobile): address review on the spawn card summary and live slot
1 parent 8adb157 commit 57ac2c2

3 files changed

Lines changed: 128 additions & 30 deletions

File tree

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export function ThreadDisclosureChevron(props: {
139139
}
140140

141141
function ShimmerWorkContent(props: {
142+
readonly compact?: boolean;
142143
readonly environmentId?: EnvironmentId;
143144
readonly highlighted: boolean;
144145
readonly icon: WorkContentIcon;
@@ -151,26 +152,29 @@ function ShimmerWorkContent(props: {
151152
}) {
152153
return (
153154
<View className="flex-row items-center gap-1.5">
154-
<View className="h-6 w-6 shrink-0 items-center justify-center">
155-
{props.showIcon && props.toolIcon && props.environmentId ? (
156-
<ToolActivityIconView
157-
environmentId={props.environmentId}
158-
icon={props.toolIcon}
159-
fallback={props.icon}
160-
fallbackColor={props.iconSubtleColor}
161-
themeAppearance={props.themeAppearance ?? "light"}
162-
/>
163-
) : props.showIcon ? (
164-
<WorkLogIcon
165-
icon={props.icon}
166-
color={props.iconSubtleColor}
167-
highlighted={props.highlighted}
168-
/>
169-
) : null}
170-
</View>
155+
{props.showIcon ? (
156+
<View className="h-6 w-6 shrink-0 items-center justify-center">
157+
{props.toolIcon && props.environmentId ? (
158+
<ToolActivityIconView
159+
environmentId={props.environmentId}
160+
icon={props.toolIcon}
161+
fallback={props.icon}
162+
fallbackColor={props.iconSubtleColor}
163+
themeAppearance={props.themeAppearance ?? "light"}
164+
/>
165+
) : (
166+
<WorkLogIcon
167+
icon={props.icon}
168+
color={props.iconSubtleColor}
169+
highlighted={props.highlighted}
170+
/>
171+
)}
172+
</View>
173+
) : null}
171174
<Text
172175
className={cn(
173-
"min-w-0 shrink text-sm",
176+
"min-w-0 shrink",
177+
props.compact ? "text-xs" : "text-sm",
174178
props.highlighted ? "text-foreground" : "text-foreground-muted",
175179
)}
176180
numberOfLines={1}
@@ -183,6 +187,8 @@ function ShimmerWorkContent(props: {
183187
}
184188

185189
export function ShimmeringWorkContent(props: {
190+
/** Secondary line: no icon slot, caption size. */
191+
readonly compact?: boolean;
186192
readonly environmentId?: EnvironmentId;
187193
readonly icon: WorkContentIcon;
188194
readonly iconSubtleColor: ColorValue;
@@ -198,7 +204,10 @@ export function ShimmeringWorkContent(props: {
198204
const screenIsFocused = useIsFocused();
199205
const progress = useSharedValue(0);
200206
const gradientId = `work-shimmer-${useId().replaceAll(":", "")}`;
201-
const contentWidth = Math.min(availableWidth, SHIMMER_ICON_AND_GAP_WIDTH + Math.ceil(textWidth));
207+
const contentWidth = Math.min(
208+
availableWidth,
209+
(props.showIcon ? SHIMMER_ICON_AND_GAP_WIDTH : 0) + Math.ceil(textWidth),
210+
);
202211

203212
useEffect(() => {
204213
const subscription = AppState.addEventListener("change", (state) => {
@@ -254,6 +263,7 @@ export function ShimmeringWorkContent(props: {
254263
onLayout={(event) => setAvailableWidth(event.nativeEvent.layout.width)}
255264
>
256265
<ShimmerWorkContent
266+
compact={props.compact}
257267
environmentId={props.environmentId}
258268
highlighted={false}
259269
icon={props.icon}
@@ -294,6 +304,7 @@ export function ShimmeringWorkContent(props: {
294304
>
295305
<Animated.View style={[{ width: availableWidth }, counterSweepStyle]}>
296306
<ShimmerWorkContent
307+
compact={props.compact}
297308
environmentId={props.environmentId}
298309
highlighted
299310
icon={props.icon}
@@ -1015,6 +1026,7 @@ export const ThreadAgentSpawnCard = memo(function ThreadAgentSpawnCard(props: {
10151026
{working ? (
10161027
<ShimmeringWorkContent
10171028
key={props.rowSizing.textSizeKey}
1029+
compact
10181030
icon="brain"
10191031
iconSubtleColor={props.iconSubtleColor}
10201032
label={summary.status}

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from "@t3tools/contracts";
1414

1515
import {
16+
agentSpawnSummary,
1617
buildPendingUserInputAnswers,
1718
buildThreadFeed,
1819
derivePendingApprovals,
@@ -24,6 +25,7 @@ import {
2425
workEntryRowLabel,
2526
type ThreadFeedActivity,
2627
type ThreadFeedEntry,
28+
type WorkLogEntry,
2729
} from "./threadActivity";
2830

2931
describe("Codex feedback pseudo-messages", () => {
@@ -2451,6 +2453,22 @@ describe("buildThreadFeed", () => {
24512453
expect(liveIds([call(1, "inProgress"), call(1, "failed"), call(2, "inProgress")])).toEqual([
24522454
"work-toggle:live-activity-row",
24532455
]);
2456+
// A call whose end was never reported, in a run before an error row,
2457+
// keeps its own identity: only the trailing run can hold the live slot.
2458+
const errorRow = makeActivity({
2459+
id: EventId.make("runtime-error"),
2460+
kind: "runtime.error",
2461+
tone: "error",
2462+
summary: "Provider error",
2463+
createdAt: "2026-04-01T00:00:02.500Z",
2464+
turnId,
2465+
payload: { message: "boom" },
2466+
});
2467+
expect(liveIds([call(1, "inProgress"), errorRow, call(2, "inProgress")])).toEqual([
2468+
"work-toggle:work-live:work-group:tool:turn-failing-calls:call-1",
2469+
"activity-group:runtime-error",
2470+
"work-toggle:live-activity-row",
2471+
]);
24542472
});
24552473

24562474
it("hands a settled tool run off to Thinking once assistant text streams after it", () => {
@@ -3238,6 +3256,55 @@ describe("quiet timeline: nested agents", () => {
32383256
expect(rows[0]?.getFullDetail()).toBe("Reviewer 0 · completed\nReviewer 1 · completed");
32393257
});
32403258

3259+
it("summarizes a spawn card from the newest member report and the batch outcome", () => {
3260+
type Member = NonNullable<WorkLogEntry["agentSpawn"]>["agents"][number];
3261+
const member = (title: string, status: Member["status"], detail: string, seconds: number) =>
3262+
({
3263+
title,
3264+
status,
3265+
detail,
3266+
updatedAt: `2026-04-01T00:00:${String(seconds).padStart(2, "0")}.000Z`,
3267+
}) satisfies Member;
3268+
const direct = (agents: ReadonlyArray<Member>) => ({
3269+
workflowId: null,
3270+
agentTaskIds: agents.map((_, index) => `a${index}`),
3271+
agents,
3272+
});
3273+
3274+
// The newest report wins regardless of member order.
3275+
expect(
3276+
agentSpawnSummary(
3277+
direct([
3278+
member("Agent 0", "inProgress", "Reading b.ts", 5),
3279+
member("Agent 1", "inProgress", "Reading a.ts", 2),
3280+
]),
3281+
"inProgress",
3282+
),
3283+
).toMatchObject({ title: "2 subagents", status: "Reading b.ts", tone: "working" });
3284+
3285+
// A declined request is a failed batch, not a completed one.
3286+
expect(
3287+
agentSpawnSummary(direct([member("Agent 0", "declined", "", 1)]), "declined"),
3288+
).toMatchObject({ status: "failed", tone: "failed" });
3289+
3290+
// A coordinator that failed on its own reports the failure even when every
3291+
// member succeeded; before any member reports, the card has a neutral title.
3292+
const workflow = (agents: ReadonlyArray<Member>) => ({
3293+
workflowId: "wf",
3294+
agentTaskIds: ["wf", ...agents.map((_, index) => `wf:wf:${index}`)],
3295+
agents: [member("review", "failed", "", 9), ...agents],
3296+
});
3297+
expect(
3298+
agentSpawnSummary(workflow([member("Reviewer", "completed", "", 3)]), "failed"),
3299+
).toMatchObject({ title: "Reviewer", status: "failed", tone: "failed" });
3300+
expect(
3301+
agentSpawnSummary(
3302+
{ workflowId: "wf", agentTaskIds: ["wf"], agents: [member("review", undefined, "", 1)] },
3303+
"inProgress",
3304+
),
3305+
).toMatchObject({ title: "Subagents", status: "Working", tone: "working", members: [] });
3306+
});
3307+
32413308
it("treats a Codex child's idle turn end as a finished batch member", () => {
32423309
const turnId = TurnId.make("turn-codex");
32433310
const child = (

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export interface WorkLogEntry {
122122
readonly title: string;
123123
readonly status: WorkLogToolLifecycleStatus | undefined;
124124
readonly detail: string | undefined;
125+
/** When this member last reported, so the card can show the newest activity. */
126+
readonly updatedAt: string;
125127
}>;
126128
};
127129
toolData?: unknown;
@@ -226,6 +228,7 @@ export interface AgentSpawnSummary {
226228
readonly status: string;
227229
readonly tone: "working" | "completed" | "failed" | "stopped";
228230
readonly detail: string | undefined;
231+
readonly updatedAt: string;
229232
}>;
230233
}
231234

@@ -739,6 +742,7 @@ function agentSpawnMember(
739742
title: entry.toolTitle ?? previous?.title ?? entry.label,
740743
status: entry.toolLifecycleStatus ?? previous?.status,
741744
detail: entry.detail ?? previous?.detail,
745+
updatedAt: entry.createdAt,
742746
};
743747
}
744748

@@ -771,6 +775,7 @@ function agentSpawnLifecycleStatus(
771775
return "inProgress";
772776
}
773777
if (statuses.includes("failed")) return "failed";
778+
if (statuses.includes("declined")) return "declined";
774779
if (statuses.includes("stopped")) return "stopped";
775780
return "completed";
776781
}
@@ -792,9 +797,7 @@ function collapseDerivedWorkLogEntries(
792797
// lifecycle row is dropped.
793798
const spawnToolCallIds = new Set(
794799
entries.flatMap((entry) =>
795-
entry.agentSpawnToolCallId !== undefined && !entry.isBackgroundTask
796-
? [entry.agentSpawnToolCallId]
797-
: [],
800+
entry.agentSpawnToolCallId !== undefined ? [entry.agentSpawnToolCallId] : [],
798801
),
799802
);
800803
for (const entry of entries) {
@@ -1250,26 +1253,40 @@ export function agentSpawnSummary(
12501253
status: tone === "working" ? "working" : (agent.status ?? tone),
12511254
tone,
12521255
detail: agent.detail,
1256+
updatedAt: agent.updatedAt,
12531257
};
12541258
});
12551259
const tone = agentSpawnTone(batchStatus);
1256-
const count = Math.max(members.length, 1);
1257-
const title = members.length === 1 ? members[0]!.title : `${count} subagents`;
1260+
// A workflow's coordinator is not a member; before any member reports the
1261+
// batch has none.
1262+
const title =
1263+
members.length === 0
1264+
? "Subagents"
1265+
: members.length === 1
1266+
? members[0]!.title
1267+
: `${members.length} subagents`;
12581268
if (tone === "working") {
12591269
const working = members.filter((member) => member.tone === "working");
1260-
const latest = working.findLast((member) => member.detail !== undefined);
1270+
const latest = working
1271+
.filter((member) => member.detail !== undefined)
1272+
.reduce<(typeof working)[number] | undefined>(
1273+
(newest, member) =>
1274+
newest === undefined || member.updatedAt > newest.updatedAt ? member : newest,
1275+
undefined,
1276+
);
12611277
const status =
12621278
latest?.detail ??
12631279
(members.length > 1 ? `${working.length} of ${members.length} working` : "Working");
12641280
return { title, status, tone, members };
12651281
}
1282+
// The batch tone covers a coordinator that failed or stopped on its own.
12661283
const failed = members.filter((member) => member.tone === "failed").length;
12671284
const stopped = members.filter((member) => member.tone === "stopped").length;
12681285
const outcome =
1269-
failed > 0
1270-
? `${members.length > 1 ? `${failed} ` : ""}failed`
1271-
: stopped > 0
1272-
? `${members.length > 1 ? `${stopped} ` : ""}stopped`
1286+
tone === "failed" || failed > 0
1287+
? `${members.length > 1 && failed > 0 ? `${failed} ` : ""}failed`
1288+
: tone === "stopped" || stopped > 0
1289+
? `${members.length > 1 && stopped > 0 ? `${stopped} ` : ""}stopped`
12731290
: "completed";
12741291
return { title, status: outcome, tone, members };
12751292
}
@@ -2124,7 +2141,9 @@ function appendToolGroupRows(
21242141
const latestActivity = latestActiveActivity ?? activities.at(-1)!;
21252142
// Like web, the trailing run keeps shining after its latest call succeeds;
21262143
// only a failed, declined, or stopped call hands the live slot to "Thinking".
2127-
const shimmer = active || (activeTail && latestActivity.status === "success");
2144+
// Only the trailing run can be the turn's live slot; an in-progress row in
2145+
// an earlier run (a call whose end was never reported) stays in place.
2146+
const shimmer = activeTail && (active || latestActivity.status === "success");
21282147
const singleActivity = activities.length === 1 ? latestActivity : null;
21292148
const summary = live
21302149
? liveToolActivitySummary(latestActivity, live)

0 commit comments

Comments
 (0)