Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions apps/server/src/project/AgentSessionScanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,84 @@ describe("parseAgentSessionTranscript", () => {
});
});

it("drops Claude background task notifications injected as user turns", () => {
const notification = [
"<task-notification>",
"<task-id>task-1</task-id>",
"<status>completed</status>",
'<summary>Background command "Run tests" completed</summary>',
"</task-notification>",
].join("\n");
const thread = AgentSessionScanner.parseAgentSessionTranscript({
contents: [
JSON.stringify({
type: "user",
sessionId: "claude-session",
origin: { kind: "task-notification" },
message: { role: "user", content: notification },
}),
JSON.stringify({
type: "user",
sessionId: "claude-session",
message: { role: "user", content: "Run the tests in the background" },
}),
JSON.stringify({
type: "assistant",
sessionId: "claude-session",
message: { role: "assistant", content: [{ type: "text", text: "Started the tests" }] },
}),
JSON.stringify({
type: "user",
sessionId: "claude-session",
message: { role: "user", content: notification },
}),
JSON.stringify({
type: "assistant",
sessionId: "claude-session",
message: { role: "assistant", content: [{ type: "text", text: "All tests passed" }] },
}),
JSON.stringify({
type: "user",
sessionId: "claude-session",
message: { role: "user", content: "Why does <task-notification> show up in logs?" },
}),
JSON.stringify({
type: "user",
sessionId: "claude-session",
message: { role: "user", content: `${notification}\nCompare with\n${notification}` },
}),
JSON.stringify({
type: "user",
sessionId: "claude-session",
message: { role: "user", content: "<task-notification>" },
}),
JSON.stringify({
type: "user",
sessionId: "claude-session",
message: { role: "user", content: `<task-notification> is in my logs:\n${notification}` },
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}),
].join("\n"),
source: "claudeAgent",
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
fallbackSessionId: "fallback",
lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"),
});

expect(thread).toMatchObject({
title: "Run the tests in the background",
omittedMessageCount: 0,
messages: [
{ role: "user", text: "Run the tests in the background" },
{ role: "assistant", text: "Started the tests" },
{ role: "assistant", text: "All tests passed" },
{ role: "user", text: "Why does <task-notification> show up in logs?" },
{ role: "user", text: `${notification}\nCompare with\n${notification}` },
{ role: "user", text: "<task-notification>" },
{ role: "user", text: `<task-notification> is in my logs:\n${notification}` },
],
});
});

it.each([
{ customTitles: ["Refactor auth module"], expected: "Refactor auth module" },
// Claude writes an empty customTitle when the user clears a rename.
Expand Down
21 changes: 20 additions & 1 deletion apps/server/src/project/AgentSessionScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,27 @@ function codexTurnId(metadata: unknown): string | null {
return decoded.value.turn_id;
}

// Claude records background task completions as user turns it injected itself; its UI
// shows them as task status, not as something the user typed.
function isClaudeTaskNotification(record: DecodedTranscriptRecord): boolean {
if (record.type !== "user") return false;
const text = extractText(record.message?.content);
const closingTag = "</task-notification>";
// Exactly one block: user text around a pasted block keeps the message.
return (
text.lastIndexOf("<task-notification>") === 0 &&
text.endsWith(closingTag) &&
text.indexOf(closingTag) === text.length - closingTag.length
);
}

function isHiddenClaudeRecord(record: DecodedTranscriptRecord): boolean {
return record.isSidechain === true || record.isMeta === true || record.isCompactSummary === true;
return (
record.isSidechain === true ||
record.isMeta === true ||
record.isCompactSummary === true ||
isClaudeTaskNotification(record)
);
}

// Claude repeats session fields on records that need not be retained.
Expand Down
Loading