Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

test(pane): keep the task-id when redacting a task-notification

Jack Rudenko43a30558fe8f
diff --git a/scripts/redact-transcript-fixture.test.ts b/scripts/redact-transcript-fixture.test.ts
new file mode 100644
index 00000000..24e1e34d
--- /dev/null
+++ b/scripts/redact-transcript-fixture.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, test } from "bun:test";
+import { redact, redactString } from "./redact-transcript-fixture.js";
+
+describe("transcript fixture redaction", () => {
+ // REGRESSION: one-shot session never settles when background-agent notifications arrive mid-turn as attachment/queued_command — Fixed in /dev:fix session dev-fix-20261016-224933-5e5cb5a4
+ test("a task-notification keeps its task-id while redacting its body", () => {
+ const redacted = redactString(
+ "prompt",
+ "<task-notification>\n<task-id>ab9d8b94e58c3540a</task-id>\n<status>completed</status>secret text</task-notification>"
+ );
+ expect(redacted).toContain("<task-id>ab9d8b94e58c3540a</task-id>");
+ expect(redacted).not.toContain("secret text");
+ });
+
+ // REGRESSION: one-shot session never settles when background-agent notifications arrive mid-turn as attachment/queued_command — Fixed in /dev:fix session dev-fix-20261016-224933-5e5cb5a4
+ test("a task-notification without a task-id keeps the id-less redacted form", () => {
+ expect(redactString("prompt", "<task-notification>secret text</task-notification>")).toBe(
+ "<task-notification>redacted</task-notification>"
+ );
+ });
+
+ // REGRESSION: one-shot session never settles when background-agent notifications arrive mid-turn as attachment/queued_command — Fixed in /dev:fix session dev-fix-20261016-224933-5e5cb5a4
+ test("a backgroundTaskId is preserved verbatim", () => {
+ expect(redact({ backgroundTaskId: "b9s8u1vld" })).toEqual({
+ backgroundTaskId: "b9s8u1vld",
+ });
+ });
+
+ // REGRESSION: one-shot session never settles when background-agent notifications arrive mid-turn as attachment/queued_command — Fixed in /dev:fix session dev-fix-20261016-224933-5e5cb5a4
+ test("a quoted task-notification does not keep its task-id", () => {
+ const redacted = redactString(
+ "prompt",
+ '<agent-message from="x">I saw <task-notification><task-id>ae0168d27fc09161c</task-id> earlier</agent-message>'
+ );
+ expect(redacted).not.toContain("<task-id>");
+ expect(redacted).not.toContain("ae0168d27fc09161c");
+ });
+});
diff --git a/scripts/redact-transcript-fixture.ts b/scripts/redact-transcript-fixture.ts
index cb4a09fe..ffe3c668 100644
--- a/scripts/redact-transcript-fixture.ts
+++ b/scripts/redact-transcript-fixture.ts
@@ -12,7 +12,9 @@
* every other string, by a placeholder of the same kind (`<text 812>`). The markers the
* pane transcript follower reads are structural, so they survive with their bodies
* emptied: `[Request interrupted by user…]`, `<task-notification>`, `<command-name>`,
- * `<local-command-stdout>`, `<local-command-caveat>`.
+ * `<local-command-stdout>`, `<local-command-caveat>`. A string that IS a notification
+ * (starts with `<task-notification>`) keeps its `<task-id>`: it is an id linking records
+ * (the notification to its launch), like `agentId`. A string that only quotes one does not.
*
* Used for shapes Phase 2 could not elicit live (a `refusal` stop, an automatic
* compaction inside a turn); see ai-docs/reports/mcp-magmux-panes/phase2-captures.md.
@@ -34,6 +36,7 @@ const KEEP_STRING_KEYS = new Set([
"sourceToolAssistantUUID",
"promptId",
"agentId",
+ "backgroundTaskId",
"requestId",
"name",
"timestamp",
@@ -61,6 +64,16 @@ const MARKERS = [
"system-reminder",
];
+/** Same pattern as `taskIdOf` in packages/cli/src/pane/transcript-follower.ts. */
+const TASK_ID = /<task-id>([^<]+)<\/task-id>/;
+
+/** One marker with its body emptied; a string that IS a task-notification, not one quoting it, keeps its `<task-id>`. */
+function redactedMarker(m: string, s: string): string {
+ const isNotification = m === "task-notification" && s.startsWith("<task-notification>");
+ const taskId = isNotification ? s.match(TASK_ID)?.[1]?.trim() : undefined;
+ return taskId ? `<${m}><task-id>${taskId}</task-id>redacted</${m}>` : `<${m}>redacted</${m}>`;
+}
+
export function redactString(key: string, s: string): string {
if (KEEP_STRING_KEYS.has(key)) return s;
if (s.startsWith("[Request interrupted by user")) return s;
@@ -68,7 +81,7 @@ export function redactString(key: string, s: string): string {
if (key === "cwd") return "/redacted/cwd";
if (key === "gitBranch") return "redacted";
const tags = MARKERS.filter((m) => s.includes(`<${m}>`));
- if (tags.length > 0) return tags.map((m) => `<${m}>redacted</${m}>`).join("\n");
+ if (tags.length > 0) return tags.map((m) => redactedMarker(m, s)).join("\n");
return `<${key || "text"} ${s.length}>`;
}