Skip to content

Commit 3d340da

Browse files
committed
fix(mobile): long commands no longer freeze Android work-log taps
A multi-kilobyte command (a heredoc) became one single-line work-log label. Android lays out and hit-tests the whole string on the UI thread, so a tap on the row stalled input dispatch (911 ms on a POCO F1 for a 24k-char command) and long enough ones ANR. Cap one-line labels at 200 characters; the expanded body and copy keep the full command. Fixes #17380
1 parent 6002c5c commit 3d340da

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,22 @@ it("uses a compact reasoning preview and a short expanded heading", () => {
23222322
expect(workEntryRowLabel({ ...entry, toolLifecycleStatus: "completed" }, true)).toBe("Thought");
23232323
});
23242324

2325+
it("caps one-line work-log labels for multi-kilobyte commands", () => {
2326+
const command = `cd /repo && python3 - <<'PY'\n${"print('x')\n".repeat(400)}PY`;
2327+
const entry = {
2328+
id: "heredoc",
2329+
label: "Ran command",
2330+
createdAt: "2026-09-17T12:00:00Z",
2331+
itemType: "command_execution" as const,
2332+
tone: "tool" as const,
2333+
command,
2334+
};
2335+
for (const label of [workEntryRowLabel(entry), workEntryRowLabel(entry, true)]) {
2336+
expect(label.startsWith("cd /repo && python3 - <<'PY' print('x')")).toBe(true);
2337+
expect(label.length).toBeLessThanOrEqual(203);
2338+
}
2339+
});
2340+
23252341
it("keeps search output in expanded details rather than the compact label", () => {
23262342
const entry = {
23272343
id: "search",

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
formatSearchToolLabel,
6363
} from "@t3tools/shared/toolActivity";
6464
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
65+
import { truncate } from "@t3tools/shared/String";
6566
import type { HtmlRenderReference } from "@t3tools/shared/htmlRender";
6667
import type { McpAppReference } from "@t3tools/shared/mcpApp";
6768
import {
@@ -254,8 +255,15 @@ export interface AgentSpawnSummary {
254255
}>;
255256
}
256257

258+
/**
259+
* Work-log headers render one line, but Android still lays out and hit-tests
260+
* the whole string, so a multi-kilobyte heredoc stalls touch dispatch until
261+
* the app ANRs. Expanded bodies and copy keep the full text.
262+
*/
263+
const WORK_LOG_LABEL_MAX_LENGTH = 200;
264+
257265
function compactWorkEntryText(value: string): string {
258-
return value.replace(/\s+/gu, " ").trim();
266+
return truncate(value.replace(/\s+/gu, " "), WORK_LOG_LABEL_MAX_LENGTH);
259267
}
260268

261269
/** Expanded work rows keep their detail while compact rows show a stable one-line label. */
@@ -296,7 +304,7 @@ export function workEntryRowLabel(entry: WorkLogPresentationEntry, expanded = fa
296304
? entry.changedFiles[0]!
297305
: `${entry.changedFiles[0]!} +${entry.changedFiles.length - 1} more`
298306
: null);
299-
if (expanded) return preview?.trim() || entry.label;
307+
if (expanded) return preview?.trim() ? truncate(preview, WORK_LOG_LABEL_MAX_LENGTH) : entry.label;
300308
return preview ? compactWorkEntryText(preview) || entry.label : entry.label;
301309
}
302310

@@ -872,7 +880,7 @@ function singleToolCallLabel(activity: ThreadFeedActivity, expanded: boolean): s
872880
const presentation = resolveWorkEntryToolPresentation(activity.workEntry, "completed");
873881
if (presentation) return presentation.displayName;
874882
const command = activity.workEntry.command?.trim();
875-
return command || activity.summary;
883+
return command ? truncate(command, WORK_LOG_LABEL_MAX_LENGTH) : activity.summary;
876884
}
877885

878886
function isEmptyMessage(entry: RawThreadFeedEntry): boolean {

0 commit comments

Comments
 (0)