Skip to content
TypeScript

fix(server): restart notes no longer split an emoji in a long background task label (#29647)

Alex Southwellbbaa535fa4d7
diff --git a/apps/server/src/orchestration-v2/RestartBackgroundNote.test.ts b/apps/server/src/orchestration-v2/RestartBackgroundNote.test.ts
index 24269dfeaff..954ba2f31a3 100644
--- a/apps/server/src/orchestration-v2/RestartBackgroundNote.test.ts
+++ b/apps/server/src/orchestration-v2/RestartBackgroundNote.test.ts
@@ -113,6 +113,13 @@ it("names a lost subagent by the id the agent resumes it with", () => {
parentTaskId: "a".repeat(400),
}).label;
assert.lengthOf(longId, 160);
+ assert.isTrue(
+ cancelledRosterTaskWork({
+ kind: "command",
+ taskId: "shell-1",
+ description: `${"d".repeat(158)}🚀 deploy`,
+ }).label.isWellFormed(),
+ );
assert.isFalse(isAwaitedWork(cancelledRosterTaskWork({ kind: "command", taskId: "shell-2" })));
assert.isTrue(
isAwaitedWork(cancelledRosterTaskWork({ kind: "command", taskId: "tests", awaited: true })),
diff --git a/apps/server/src/orchestration-v2/RestartBackgroundNote.ts b/apps/server/src/orchestration-v2/RestartBackgroundNote.ts
index 24afd61d618..c495290ad08 100644
--- a/apps/server/src/orchestration-v2/RestartBackgroundNote.ts
+++ b/apps/server/src/orchestration-v2/RestartBackgroundNote.ts
@@ -17,7 +17,11 @@ function compactLabel(value: unknown, maxLength = MAX_LABEL_LENGTH): string | un
if (typeof value !== "string") return undefined;
const text = value.replaceAll(/\s+/g, " ").trim();
if (text.length === 0) return undefined;
- return text.length > maxLength ? `${text.slice(0, maxLength - 1)}…` : text;
+ if (text.length <= maxLength) return text;
+ // Half an emoji serializes to a lone surrogate escape, which provider JSON parsers reject.
+ const last = text.charCodeAt(maxLength - 2);
+ const end = last >= 0xd800 && last <= 0xdbff ? maxLength - 2 : maxLength - 1;
+ return `${text.slice(0, end)}…`;
}
/** A bounded label that keeps its id suffix whole whenever it fits. */