Skip to content
TypeScript

fix(mobile): cap live work-log summaries for long approval prompts (#23227)

Victor Vogel1b8516e87479
diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts
index 409631131c0..583cbe7098e 100644
--- a/apps/mobile/src/lib/threadActivity.test.ts
+++ b/apps/mobile/src/lib/threadActivity.test.ts
@@ -1842,3 +1842,81 @@ describe("streamed feed updates", () => {
expect(showsDelegation(steps[3]!)).toBe(false);
});
});
+
+it.each([false, true])(
+ "caps live approval headers while preserving the prompt (grouped: %s)",
+ (grouped) => {
+ const at = "2026-06-20T00:00:02.000Z";
+ const prompt = `python3 - <<'PY'\n${"print('approval')\n".repeat(400)}PY`;
+ const approval: OrchestrationV2TurnItem = {
+ ...base("long-approval", at, 2),
+ type: "approval_request",
+ status: "waiting",
+ completedAt: null,
+ requestId: RuntimeRequestId.make("long-approval"),
+ requestKind: "command",
+ prompt,
+ };
+ const presented = deriveThreadFeedPresentation(
+ buildThreadFeed([
+ projected(userMessage(), 0),
+ ...(grouped ? [projected(command(), 1)] : []),
+ projected(approval, 2),
+ ]),
+ { runId, status: "running", startedAt: at, completedAt: null },
+ new Set(),
+ new Set(),
+ at,
+ );
+ const header = presented.find((row) =>
+ grouped ? row.type === "work-toggle" : row.type === "activity-group",
+ );
+ const label =
+ header?.type === "work-toggle"
+ ? header.summary
+ : header?.type === "activity-group"
+ ? header.activities[0]?.groupStandIn?.label
+ : undefined;
+ expect(label).toBeDefined();
+ expect(label!.length).toBeLessThanOrEqual(203);
+ expect(label).toMatch(/^python3 - <<'PY' print/);
+ expect(label).not.toContain("\n");
+ const feed = buildThreadFeed([projected(approval, 0)]);
+ const activity = feed.flatMap((row) =>
+ row.type === "activity-group" ? row.activities : [],
+ )[0]!;
+ expect(activity.detail).toBe(prompt);
+ expect(JSON.parse(activity.getFullDetail()!).item).toMatchObject({ prompt });
+ expect(activity.getCopyText()).toContain(prompt);
+ },
+);
+
+it("caps live thought previews while preserving reasoning detail", () => {
+ const at = "2026-06-20T00:00:02.000Z";
+ const text = "Considering the pending approval\n".repeat(100);
+ const thought: OrchestrationV2TurnItem = {
+ ...base("long-thought", at, 1),
+ type: "reasoning",
+ status: "running",
+ completedAt: null,
+ text,
+ streaming: true,
+ };
+ const feed = buildThreadFeed([projected(userMessage(), 0), projected(thought, 1)]);
+ const rows = deriveThreadFeedPresentation(
+ feed,
+ { runId, status: "running", startedAt: at, completedAt: null },
+ new Set(),
+ new Set(),
+ at,
+ );
+ const header = rows.find((row) => row.type === "work-toggle");
+ expect(header).toMatchObject({ summary: "Thinking", live: true });
+ expect(header?.thought).toMatch(/^Considering the pending approval/);
+ expect(header?.thought).not.toContain("\n");
+ expect(header!.thought!.length).toBeLessThanOrEqual(203);
+ const activity = feed.flatMap((row) => (row.type === "activity-group" ? row.activities : []))[0]!;
+ expect(activity.detail).toBe(text);
+ expect(JSON.parse(activity.getFullDetail()!).item).toMatchObject({ text });
+ expect(activity.getCopyText()).toContain(text);
+});
diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts
index bd7af44b2fa..91681731aab 100644
--- a/apps/mobile/src/lib/threadActivity.ts
+++ b/apps/mobile/src/lib/threadActivity.ts
@@ -1774,7 +1774,7 @@ function appendToolGroupRows(
(activity.workEntry.detail?.trim() ?? "") !== "",
)?.workEntry.detail
: undefined;
- const thought = latestThought ? liveThoughtLine(latestThought) : "";
+ const thought = latestThought ? compactWorkEntryText(liveThoughtLine(latestThought)) : "";
const summary = live
? (expanded || thought) && latestActivity.workEntry.itemType === "reasoning"
? latestActivity.lifecycleStatus === "inProgress"
@@ -1872,9 +1872,8 @@ function appendToolGroupRows(
function liveToolActivitySummary(activity: ThreadFeedActivity, presentTense: boolean): string {
const status = liveActivityToolStatus(activity.lifecycleStatus, presentTense);
if (activity.workEntry.itemType === "reasoning") {
- return (
- activity.workEntry.detail?.trim().replace(/\s+/g, " ") ||
- (status === "inProgress" ? "Thinking" : "Thought")
+ return compactWorkEntryText(
+ activity.workEntry.detail?.trim() || (status === "inProgress" ? "Thinking" : "Thought"),
);
}
const presentation = resolveWorkEntryToolPresentation({
@@ -1897,7 +1896,7 @@ function liveToolActivitySummary(activity: ThreadFeedActivity, presentTense: boo
: "Ran";
return `${verb} ${program ?? "command"}`;
}
- return activity.detail ?? activity.summary;
+ return compactWorkEntryText(activity.detail ?? activity.summary);
}
interface ThreadFeedBuild {