Skip to content

Commit 1b8516e

Browse files
only21milcodex
andauthored
fix(mobile): cap live work-log summaries for long approval prompts (#23227)
Co-authored-by: GPT-6.1 Sol <[email protected]>
1 parent d3f6ace commit 1b8516e

2 files changed

Lines changed: 82 additions & 5 deletions

File tree

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,3 +1842,81 @@ describe("streamed feed updates", () => {
18421842
expect(showsDelegation(steps[3]!)).toBe(false);
18431843
});
18441844
});
1845+
1846+
it.each([false, true])(
1847+
"caps live approval headers while preserving the prompt (grouped: %s)",
1848+
(grouped) => {
1849+
const at = "2026-06-20T00:00:02.000Z";
1850+
const prompt = `python3 - <<'PY'\n${"print('approval')\n".repeat(400)}PY`;
1851+
const approval: OrchestrationV2TurnItem = {
1852+
...base("long-approval", at, 2),
1853+
type: "approval_request",
1854+
status: "waiting",
1855+
completedAt: null,
1856+
requestId: RuntimeRequestId.make("long-approval"),
1857+
requestKind: "command",
1858+
prompt,
1859+
};
1860+
const presented = deriveThreadFeedPresentation(
1861+
buildThreadFeed([
1862+
projected(userMessage(), 0),
1863+
...(grouped ? [projected(command(), 1)] : []),
1864+
projected(approval, 2),
1865+
]),
1866+
{ runId, status: "running", startedAt: at, completedAt: null },
1867+
new Set(),
1868+
new Set(),
1869+
at,
1870+
);
1871+
const header = presented.find((row) =>
1872+
grouped ? row.type === "work-toggle" : row.type === "activity-group",
1873+
);
1874+
const label =
1875+
header?.type === "work-toggle"
1876+
? header.summary
1877+
: header?.type === "activity-group"
1878+
? header.activities[0]?.groupStandIn?.label
1879+
: undefined;
1880+
expect(label).toBeDefined();
1881+
expect(label!.length).toBeLessThanOrEqual(203);
1882+
expect(label).toMatch(/^python3 - <<'PY' print/);
1883+
expect(label).not.toContain("\n");
1884+
const feed = buildThreadFeed([projected(approval, 0)]);
1885+
const activity = feed.flatMap((row) =>
1886+
row.type === "activity-group" ? row.activities : [],
1887+
)[0]!;
1888+
expect(activity.detail).toBe(prompt);
1889+
expect(JSON.parse(activity.getFullDetail()!).item).toMatchObject({ prompt });
1890+
expect(activity.getCopyText()).toContain(prompt);
1891+
},
1892+
);
1893+
1894+
it("caps live thought previews while preserving reasoning detail", () => {
1895+
const at = "2026-06-20T00:00:02.000Z";
1896+
const text = "Considering the pending approval\n".repeat(100);
1897+
const thought: OrchestrationV2TurnItem = {
1898+
...base("long-thought", at, 1),
1899+
type: "reasoning",
1900+
status: "running",
1901+
completedAt: null,
1902+
text,
1903+
streaming: true,
1904+
};
1905+
const feed = buildThreadFeed([projected(userMessage(), 0), projected(thought, 1)]);
1906+
const rows = deriveThreadFeedPresentation(
1907+
feed,
1908+
{ runId, status: "running", startedAt: at, completedAt: null },
1909+
new Set(),
1910+
new Set(),
1911+
at,
1912+
);
1913+
const header = rows.find((row) => row.type === "work-toggle");
1914+
expect(header).toMatchObject({ summary: "Thinking", live: true });
1915+
expect(header?.thought).toMatch(/^Considering the pending approval/);
1916+
expect(header?.thought).not.toContain("\n");
1917+
expect(header!.thought!.length).toBeLessThanOrEqual(203);
1918+
const activity = feed.flatMap((row) => (row.type === "activity-group" ? row.activities : []))[0]!;
1919+
expect(activity.detail).toBe(text);
1920+
expect(JSON.parse(activity.getFullDetail()!).item).toMatchObject({ text });
1921+
expect(activity.getCopyText()).toContain(text);
1922+
});

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ function appendToolGroupRows(
17741774
(activity.workEntry.detail?.trim() ?? "") !== "",
17751775
)?.workEntry.detail
17761776
: undefined;
1777-
const thought = latestThought ? liveThoughtLine(latestThought) : "";
1777+
const thought = latestThought ? compactWorkEntryText(liveThoughtLine(latestThought)) : "";
17781778
const summary = live
17791779
? (expanded || thought) && latestActivity.workEntry.itemType === "reasoning"
17801780
? latestActivity.lifecycleStatus === "inProgress"
@@ -1872,9 +1872,8 @@ function appendToolGroupRows(
18721872
function liveToolActivitySummary(activity: ThreadFeedActivity, presentTense: boolean): string {
18731873
const status = liveActivityToolStatus(activity.lifecycleStatus, presentTense);
18741874
if (activity.workEntry.itemType === "reasoning") {
1875-
return (
1876-
activity.workEntry.detail?.trim().replace(/\s+/g, " ") ||
1877-
(status === "inProgress" ? "Thinking" : "Thought")
1875+
return compactWorkEntryText(
1876+
activity.workEntry.detail?.trim() || (status === "inProgress" ? "Thinking" : "Thought"),
18781877
);
18791878
}
18801879
const presentation = resolveWorkEntryToolPresentation({
@@ -1897,7 +1896,7 @@ function liveToolActivitySummary(activity: ThreadFeedActivity, presentTense: boo
18971896
: "Ran";
18981897
return `${verb} ${program ?? "command"}`;
18991898
}
1900-
return activity.detail ?? activity.summary;
1899+
return compactWorkEntryText(activity.detail ?? activity.summary);
19011900
}
19021901

19031902
interface ThreadFeedBuild {

0 commit comments

Comments
 (0)