Compare commits

...
Author SHA1 Message Date
paseo-bot[bot] 3f2e4580e6 fix(app): keep copy turn after a provider failure
The error row supplies the fork cursor. Keep Copy turn when the same turn contains a partial assistant reply.
2026-11-21 21:10:35 +00:00
paseo-bot[bot] bde4f407f7 fix(agents): carry separate errors through current turn handling
Record failure rows with their turn ID and use the observed failure in parent notifications. Keep failed-turn timing on the existing timeline cache.
2026-11-21 20:46:47 +00:00
paseo-bot[bot] 744878bf62 refactor(agents): name finish notification options 2026-10-13 13:26:03 +02:00
paseo-bot[bot] e1ce819d11 fix(agents): retain complete failure outcomes through delivery
Capture the failure reason when the terminal notification is queued, preserve provider diagnostics at their producer, and apply the existing notification text budget. Failed responses also keep their completion timing when their footer is anchored to error activity.
2026-10-13 13:20:08 +02:00
paseo-bot[bot] 6d7aaf5461 test(app): distinguish timeline errors from submission failures
A rejected prompt displays its reason in both the submission status and the timeline. Scope the timeline assertions to the notification row.
2026-10-13 13:05:09 +02:00
paseo-bot[bot] 9e596e3377 fix(agents): preserve failure reasons and failed-turn forking
Typed failure activity no longer appears in assistant replies. Attach the response footer to the error cursor and read lastError for failed schedules and child notifications so those consumers retain their behavior.
2026-10-13 12:59:06 +02:00
paseo-bot[bot] e5efa7324d test(server): expect failure activity during agent creation
Verify fetched and live creation timelines use the typed error item when an initial provider prompt is rejected.
2026-10-13 05:03:13 +02:00
paseo-bot[bot]andAndonis 303ee418cc test(server): verify failure activity on current timeline paths
Keep daemon failures separate from preceding assistant output and verify live error delivery, including assistant text that resembles the legacy error marker. Update startup failure and successful session-replacement assertions for typed errors.

Co-authored-by: Andonis <qq3290949433@gmail.com>
2026-10-13 04:57:22 +02:00
paseo-bot[bot] b282bbb944 Merge remote-tracking branch 'origin/main' into bot/fix-4262-131bae8c 2026-10-13 04:53:51 +02:00
Andonis 3e977b5e7b fix(server): keep system errors separate from replies 2026-09-03 15:56:42 +08:00
26 changed files with 348 additions and 173 deletions
@@ -320,10 +320,12 @@ async function retryRestoredSubmission(page: Page, prompt: string): Promise<void
}
async function expectRejectedPromptBeforeError(page: Page, prompt: string, errorMessage: string) {
const messages = page.getByTestId("user-message").or(page.getByTestId("assistant-message"));
const messages = page
.getByTestId("user-message")
.or(page.getByTestId("timeline-notification").filter({ hasText: errorMessage }));
await expect(messages).toHaveCount(2);
await expect(messages.nth(0)).toContainText(prompt);
await expect(messages.nth(1)).toContainText(`[System Error] ${errorMessage}`);
await expect(messages.nth(1)).toHaveText(errorMessage);
}
async function configureSteerInSettings(page: Page): Promise<void> {
@@ -51,7 +51,7 @@ test.describe("Assistant fork menu", () => {
await openAgentRoute(page, session);
await expectComposerVisible(page);
await submitMessage(page, "Emit a synthetic turn failure.");
await expect(page.getByText("[System Error] Requested mock provider failure")).toBeVisible({
await expect(page.getByText("Requested mock provider failure")).toBeVisible({
timeout: 30_000,
});
+10 -8
View File
@@ -189,8 +189,9 @@ export async function createCreationScenario(page: Page) {
await requests.settled();
await expect(
page
.getByTestId("assistant-message")
.filter({ hasText: "[System Error] Requested mock prompt rejection", visible: true }),
.getByTestId("timeline-notification")
.filter({ hasText: "Requested mock prompt rejection" })
.filter({ visible: true }),
).toBeVisible();
await expect(
page
@@ -206,11 +207,15 @@ export async function createCreationScenario(page: Page) {
async expectPromptBeforeError(prompt: string) {
const messages = page
.getByTestId("user-message")
.or(page.getByTestId("assistant-message"))
.or(
page
.getByTestId("timeline-notification")
.filter({ hasText: "Requested mock prompt rejection" }),
)
.filter({ visible: true });
await expect(messages).toHaveCount(2);
await expect(messages.nth(0)).toContainText(prompt);
await expect(messages.nth(1)).toContainText("[System Error]");
await expect(messages.nth(1)).toHaveText("Requested mock prompt rejection");
await expect(messages.nth(1)).toBeInViewport();
},
async reloadAgent() {
@@ -220,10 +225,7 @@ export async function createCreationScenario(page: Page) {
},
async expectAssistantReply() {
await expect(
page
.getByTestId("assistant-message")
.filter({ visible: true, hasNotText: "[System Error]" })
.first(),
page.getByTestId("assistant-message").filter({ visible: true }).first(),
).toBeVisible();
},
async expectStartupFailure() {
@@ -148,6 +148,35 @@ function findLayoutItem(layout: StreamLayout, id: string): StreamLayoutItem {
}
describe("layoutStream", () => {
it.each(["web", "android"] as const)(
"hosts failed response footers on the error row on %s",
(platform) => {
const error: StreamItem = {
kind: "notification",
sourceType: "error",
level: "error",
id: "error-1",
message: "Provider failed",
timestamp: timestamp(2),
timelineCursor: { epoch: "timeline-1", seq: 42 },
};
const user = userMessage("user-1", 1);
const latest = layoutFor({ platform, tail: [user, error] });
expect(latest.auxiliaryTurnFooter?.itemId).toBe(error.id);
const completed = layoutFor({
platform,
tail: [user, error, userMessage("user-2", 3)],
isTurnActive: true,
});
expect(findLayoutItem(completed, error.id).completedFooter?.itemId).toBe(error.id);
const afterReply = layoutFor({
platform,
tail: [user, assistantMessage("assistant-1", 2), error],
});
expect(afterReply.auxiliaryTurnFooter?.itemId).toBe(error.id);
},
);
it("keeps separate footers for an assistant turn and an adjacent tool-only turn", () => {
const priorAssistant = assistantMessage("prior", 1, undefined, "turn-1");
const nextTool = toolCall("next-tool", 2, "turn-2");
+4 -1
View File
@@ -102,7 +102,10 @@ function findTurnFooterSource(input: {
if (!item || (laterItem && !continuesResponse(item, laterItem))) {
return toolFallback;
}
if (item.kind === "assistant_message") {
if (
item.kind === "assistant_message" ||
(item.kind === "notification" && item.sourceType === "error")
) {
return { item, items, index };
}
laterItem = item;
@@ -32,7 +32,12 @@ function assistantMessage(
describe("resolveAssistantTurnForkBoundary", () => {
it("forks a failed assistant turn from its Paseo timeline cursor without a provider message id", () => {
const failedTurn = {
...assistantMessage("assistant-error", 2),
kind: "notification" as const,
sourceType: "error" as const,
level: "error" as const,
message: "Provider failed",
id: "error-1",
timestamp: timestamp(2),
timelineCursor: { epoch: "timeline-1", seq: 42 },
};
@@ -10,6 +10,11 @@ export function resolveAssistantTurnForkBoundary(input: {
supportsTimelineCursor: boolean;
}): AssistantTurnForkBoundary | undefined {
const item = input.items[input.startIndex];
if (item?.kind === "notification" && item.sourceType === "error") {
return input.supportsTimelineCursor && item.timelineCursor
? { boundaryCursor: item.timelineCursor }
: undefined;
}
if (item?.kind !== "assistant_message") {
return undefined;
}
@@ -1,6 +1,7 @@
import React, { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { page } from "vitest/browser";
import { i18n } from "@/i18n/i18next";
import type { TurnTiming } from "@/timeline/turn-time";
import type { StreamItem } from "@/types/stream";
@@ -40,14 +41,14 @@ const reply: StreamItem = {
timestamp: FRIDAY_NIGHT,
};
function renderCompletedFooter(timing: TurnTiming): void {
function renderCompletedFooter(timing: TurnTiming, items: StreamItem[] = [reply]): void {
act(() =>
root.render(
<CompletedTurnFooterRow
strategy={createNativeStreamStrategy()}
items={[reply]}
items={items}
timing={timing}
startIndex={0}
startIndex={items.length - 1}
supportsTimelineCursor={false}
/>,
),
@@ -92,3 +93,22 @@ it.each([
"Friday 11:11 PM": 1,
});
});
it("offers Copy turn for a reply followed by an error", async () => {
const error: StreamItem = {
kind: "notification",
sourceType: "error",
level: "error",
id: "failure",
message: "Provider failed",
timestamp: FRIDAY_NIGHT,
turnId: "failed-turn",
};
const timing = { completedAt: FRIDAY_NIGHT, durationMs: 26_000 };
renderCompletedFooter(timing, [{ ...reply, turnId: "failed-turn" }, error]);
await expect.element(page.getByRole("button", { name: "Copy turn" })).toBeVisible();
renderCompletedFooter(timing, [{ ...reply, turnId: "earlier-turn" }, error]);
await expect.element(page.getByRole("button", { name: "Copy turn" })).not.toBeInTheDocument();
});
@@ -184,6 +184,13 @@ function CompletedTurnFooter({
}),
[strategy, items, startIndex],
);
const source = items[startIndex];
const hasCopyContent = useMemo(
() =>
source?.kind === "assistant_message" ||
(source?.kind === "notification" && source.sourceType === "error" && getContent().length > 0),
[getContent, source],
);
const boundary = resolveAssistantTurnForkBoundary({
items,
startIndex,
@@ -201,7 +208,7 @@ function CompletedTurnFooter({
return (
<View style={stylesheet.turnFooterSlot}>
<AssistantTurnFooter
getContent={items[startIndex]?.kind === "assistant_message" ? getContent : undefined}
getContent={hasCopyContent ? getContent : undefined}
completedAt={timing?.completedAt}
durationMs={timing?.durationMs}
onFork={boundary && onForkAssistantTurn ? handleFork : undefined}
+1 -1
View File
@@ -1404,7 +1404,7 @@ export const Notification = memo(function Notification({
[resolvedDisableOuterSpacing, config.bg],
);
return (
<View style={containerStyle}>
<View style={containerStyle} testID="timeline-notification">
<View style={notificationStylesheet.content}>
<View style={notificationStylesheet.row}>
<View style={notificationStylesheet.iconContainer}>
@@ -22,6 +22,31 @@ function assistant(id: string, timestamp: Date, text = id): StreamItem {
}
describe("deriveStreamTurnTiming", () => {
it("retains completed timing for a failed response with or without assistant text", () => {
const userAt = new Date("2026-05-15T00:00:00.000Z");
const failedAt = new Date("2026-05-15T00:00:07.000Z");
const error: StreamItem = {
kind: "notification",
sourceType: "error",
level: "error",
id: "error-1",
message: "Provider failed",
timestamp: failedAt,
};
for (const replies of [[], [assistant("assistant-1", new Date("2026-05-15T00:00:03.000Z"))]]) {
const timing = deriveStreamTurnTiming({
isTurnActive: false,
activeTurnStartedAt: null,
tail: [user("user-1", userAt), ...replies, error],
head: [],
});
assert.deepEqual(timing.byItemId.get(error.id), {
completedAt: failedAt,
durationMs: 7000,
});
}
});
it("starts elapsed time from the submitted prompt", () => {
const submittedAt = new Date("2026-05-15T00:00:00.000Z");
+12 -9
View File
@@ -14,7 +14,7 @@ export interface StreamTurnTiming {
interface OpenTurn {
userAt: Date | null;
lastItemAt: Date | null;
assistantIds: readonly string[];
responseIds: readonly string[];
previousItem: StreamItem | null;
}
@@ -32,7 +32,7 @@ interface TailTurnTiming {
const EMPTY_OPEN_TURN: OpenTurn = {
userAt: null,
lastItemAt: null,
assistantIds: [],
responseIds: [],
previousItem: null,
};
@@ -44,7 +44,7 @@ function closeTurn(turn: OpenTurn, into: Map<string, TurnTiming>): void {
completedAt: turn.lastItemAt,
durationMs: turn.userAt ? Math.max(0, turn.lastItemAt.getTime() - turn.userAt.getTime()) : null,
};
let footerIds = turn.assistantIds;
let footerIds = turn.responseIds;
if (footerIds.length === 0 && turn.previousItem?.kind === "tool_call") {
footerIds = [turn.previousItem.id];
}
@@ -60,22 +60,25 @@ function walkTurns(
): OpenTurn {
let userAt = from.userAt;
let lastItemAt = from.lastItemAt;
let assistantIds = [...from.assistantIds];
let responseIds = [...from.responseIds];
let previousItem = from.previousItem;
for (const item of items) {
if (startsNewTurn(item, previousItem)) {
closeTurn({ userAt, lastItemAt, assistantIds, previousItem }, into);
closeTurn({ userAt, lastItemAt, responseIds, previousItem }, into);
userAt = isTurnTrigger(item) ? item.timestamp : null;
lastItemAt = null;
assistantIds = [];
responseIds = [];
}
lastItemAt = item.timestamp;
if (item.kind === "assistant_message") {
assistantIds.push(item.id);
if (
item.kind === "assistant_message" ||
(item.kind === "notification" && item.sourceType === "error")
) {
responseIds.push(item.id);
}
previousItem = item;
}
return { userAt, lastItemAt, assistantIds, previousItem };
return { userAt, lastItemAt, responseIds, previousItem };
}
function areTimingsEqual(a: Map<string, TurnTiming>, b: Map<string, TurnTiming>): boolean {
@@ -187,7 +187,12 @@ try {
if (agent?.status === "error" && agent.attentionReason === "error") return agent;
}, "unexpected provider exit did not raise error attention");
const failure = await daemon.client.fetchAgentTimeline(crashing.id, { limit: 20 });
assert.match(JSON.stringify(failure.entries), /\[System Error\].*ACP process exited/);
assert(
failure.entries.some(
({ item }) => item.type === "error" && item.message.includes("ACP process exited"),
),
"unexpected provider exit did not add an error row",
);
console.log("Unexpected ACP exit raised error attention and added a timeline entry.");
await daemon.client.sendMessage(running.id, "Hold the turn open.");
@@ -4907,11 +4907,7 @@ test("a prompt after provider replacement reopens the stale session", async () =
expect(timeline.filter((item) => item.type === "user_message")).toMatchObject([
{ text: "continue after reload", clientMessageId: "stale-session-retry" },
]);
expect(
timeline.some(
(item) => item.type === "assistant_message" && item.text.includes("[System Error]"),
),
).toBe(false);
expect(timeline.some((item) => item.type === "error")).toBe(false);
} finally {
await manager.closeAgent(created.id).catch(() => undefined);
await manager.flush().catch(() => undefined);
@@ -8413,47 +8409,78 @@ test("ignores stale autonomous terminals without lowering the active turn lifecy
});
});
test("preserves terminal fallback when no active turn identity was observed", async () => {
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-untracked-terminal-"));
const storage = new AgentStorage(join(workdir, "agents"), logger);
let capturedSession: TestAgentSession | null = null;
test.each(["Task completed.", "[System Error] untracked failure"])(
"preserves terminal fallback and separates untracked failure activity after %s",
async (assistantText) => {
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-untracked-terminal-"));
const storage = new AgentStorage(join(workdir, "agents"), logger);
let capturedSession: TestAgentSession | null = null;
class LiveEventClient extends TestAgentClient {
override async createSession(config: AgentSessionConfig): Promise<AgentSession> {
capturedSession = new TestAgentSession(config);
return capturedSession;
class LiveEventClient extends TestAgentClient {
override async createSession(config: AgentSessionConfig): Promise<AgentSession> {
capturedSession = new TestAgentSession(config);
return capturedSession;
}
}
}
const manager = new AgentManager({
clients: { codex: new LiveEventClient() },
registry: storage,
logger,
idFactory: () => "00000000-0000-4000-8000-000000000136",
});
const snapshot = await manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
workspaceId: undefined,
});
capturedSession!.pushEvent({
type: "turn_failed",
provider: "codex",
turnId: "untracked-turn",
error: "untracked failure",
});
await vi.waitFor(() => {
const failed = manager.getAgent(snapshot.id);
expect(failed?.lifecycle).toBe("error");
expect(failed?.lastError).toBe("untracked failure");
});
expect(manager.getTimeline(snapshot.id)).toContainEqual(
expect.objectContaining({
const manager = new AgentManager({
clients: { codex: new LiveEventClient() },
registry: storage,
logger,
idFactory: () => "00000000-0000-4000-8000-000000000136",
});
const snapshot = await manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
workspaceId: undefined,
});
const events: AgentManagerEvent[] = [];
manager.subscribe((event) => events.push(event), { agentId: snapshot.id, replayState: false });
await manager.appendTimelineItem(snapshot.id, {
type: "assistant_message",
text: expect.stringContaining("untracked failure"),
}),
);
});
text: assistantText,
messageId: "assistant-1",
});
capturedSession!.pushEvent({
type: "turn_failed",
provider: "codex",
turnId: "untracked-turn",
error: "untracked failure",
});
await vi.waitFor(() => {
const failed = manager.getAgent(snapshot.id);
expect(failed?.lifecycle).toBe("error");
expect(failed?.lastError).toBe("untracked failure");
});
expect(manager.getTimeline(snapshot.id)).toContainEqual(
expect.objectContaining({
type: "error",
message: expect.stringContaining("untracked failure"),
}),
);
const projected = projectTimelineRows({
rows: await manager.getTimelineRows(snapshot.id),
mode: "projected",
});
expect(projected.map((entry) => entry.item)).toEqual([
{
type: "assistant_message",
text: assistantText,
messageId: "assistant-1",
},
{ type: "error", message: "untracked failure" },
]);
expect(events).toContainEqual(
expect.objectContaining({
type: "agent_stream",
event: expect.objectContaining({
type: "timeline",
item: { type: "error", message: "untracked failure" },
}),
}),
);
},
);
test("cancelAgentRun waits for an acknowledged autonomous interrupt to settle", async () => {
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-live-cancel-"));
@@ -9969,7 +9996,7 @@ test("streamAgent clears pending run when startTurn fails before a turn id exist
clientMessageId: "rejected-prompt",
messageId: "rejected-prompt",
},
{ type: "assistant_message", text: "[System Error] Invalid request: missing field `text`" },
{ type: "error", message: "Invalid request: missing field `text`" },
]);
await expect(manager.runAgent(agent.id, "second turn")).resolves.toEqual(
@@ -11330,7 +11357,7 @@ test("archiveAgent cascade surfaces partial child archive failures", async () =>
);
});
test("turn_failed emits a system error assistant timeline message and keeps error lifecycle", async () => {
test("turn_failed emits error activity and keeps error lifecycle", async () => {
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-turn-failed-"));
const storagePath = join(workdir, "agents");
const storage = new AgentStorage(storagePath, logger);
@@ -11398,12 +11425,15 @@ test("turn_failed emits a system error assistant timeline message and keeps erro
const systemErrors = manager
.getTimeline(agent.id)
.filter(
(item): item is Extract<AgentTimelineItem, { type: "assistant_message" }> =>
item.type === "assistant_message" && item.text.includes("[System Error]"),
);
.filter((item): item is Extract<AgentTimelineItem, { type: "error" }> => item.type === "error");
expect(systemErrors).toHaveLength(1);
expect(systemErrors[0]?.text).toContain("invalid model id");
expect(systemErrors[0]?.message).toContain("invalid model id");
expect(await manager.getTimelineRows(agent.id)).toContainEqual(
expect.objectContaining({
turnId: "turn-failed-1",
item: { type: "error", message: "invalid model id" },
}),
);
});
test("turn_failed surfaces provider code and diagnostic in system error message", async () => {
@@ -11470,17 +11500,16 @@ test("turn_failed surfaces provider code and diagnostic in system error message"
await expect(manager.runAgent(agent.id, "hello")).rejects.toThrow("Provider execution failed");
expect(manager.getAgent(agent.id)?.lastError).toBe("Provider execution failed");
expect(manager.getAgent(agent.id)?.lastError).toBe(
"Provider execution failed\n\ncode: 126\n\nNo preset version installed for command claude",
);
const systemError = manager
.getTimeline(agent.id)
.find(
(item): item is Extract<AgentTimelineItem, { type: "assistant_message" }> =>
item.type === "assistant_message" && item.text.includes("[System Error]"),
);
expect(systemError?.text).toContain("Provider execution failed");
expect(systemError?.text).toContain("code: 126");
expect(systemError?.text).toContain("No preset version installed for command claude");
.find((item): item is Extract<AgentTimelineItem, { type: "error" }> => item.type === "error");
expect(systemError?.message).toContain("Provider execution failed");
expect(systemError?.message).toContain("code: 126");
expect(systemError?.message).toContain("No preset version installed for command claude");
});
test("permission request notifies once without forcing unread attention state", async () => {
@@ -641,8 +641,6 @@ interface AgentMetadataPatch {
metadata?: Record<string, JsonValue | null>;
}
const SYSTEM_ERROR_PREFIX = "[System Error]";
function normalizePersistenceForConfig(
handle: AgentPersistenceHandle | null,
config: AgentSessionConfig,
@@ -5587,13 +5585,10 @@ export class AgentManager {
if (!isForegroundEvent && !agent.activeForegroundTurnId) {
agent.lifecycle = "error";
}
agent.lastError = event.error;
await this.appendSystemErrorTimelineMessage(
agent,
event.provider,
this.formatTurnFailedMessage(event),
options,
);
agent.lastError = this.formatTurnFailedMessage(event);
if (!options?.fromHistory) {
await this.recordTurnFailure(agent.id, event.provider, agent.lastError, eventTurnId);
}
this.resolvePendingPermissionsForAgent(agent, event.provider, options, "Turn failed");
}
@@ -5823,42 +5818,17 @@ export class AgentManager {
return existing;
}
private async appendSystemErrorTimelineMessage(
agent: ActiveManagedAgent,
private async recordTurnFailure(
agentId: string,
provider: AgentProvider,
message: string,
options?: { fromHistory?: boolean },
turnId: string | undefined,
): Promise<void> {
if (options?.fromHistory) {
const lastItem = await this.getLastItemFromStores(agentId);
if (lastItem?.type === "error" && lastItem.message === message) {
return;
}
const normalized = message.trim();
if (!normalized) {
return;
}
const text = `${SYSTEM_ERROR_PREFIX} ${normalized}`;
const lastItem = await this.getLastItemFromStores(agent.id);
if (lastItem?.type === "assistant_message" && lastItem.text === text) {
return;
}
const item: AgentTimelineItem = { type: "assistant_message", text };
const row = this.recordTimeline(agent.id, item);
this.dispatchStream(
agent.id,
{
type: "timeline",
item,
provider,
},
{
seq: row.seq,
epoch: this.timelineStore.getEpoch(agent.id),
timestamp: row.timestamp,
},
);
this.recordAndDispatchTimelineItem(agentId, { type: "error", message }, provider, turnId);
}
private formatTurnFailedMessage(
@@ -298,9 +298,18 @@ test("error and missing-child notifications never claim successful completion",
const state = await scenario();
await state.service.register(intent);
await until(() => state.observation.waits.length === 1);
state.observation.waits[0]!.result.resolve(outcome("error"));
const failed = outcome("error");
failed.error = "Provider failed: " + "x".repeat(4100);
state.observation.waits[0]!.result.resolve(failed);
await until(() => state.delivery.prompts.length === 1);
expect(state.delivery.prompts[0]).toContain("errored");
expect(state.delivery.prompts[0]).toContain(
`<agent-error>
${failed.error.slice(0, 4000)}
[truncated 117 chars; use get_agent_activity for the full response]
</agent-error>`,
);
expect(state.delivery.prompts[0]).not.toContain("Partial work saved");
await state.service.register({ ...intent, childAgentId: "missing-child" });
await until(() => state.observation.waits.length === 2);
state.observation.waits[1]!.result.resolve({
@@ -190,6 +190,7 @@ export function createFinishSubscriptions(deps: Dependencies): FinishSubscriptio
title,
reason,
lastAssistantMessage: result.lastMessage,
error: result.error,
permissionRequest: request,
}),
source: {
@@ -29,6 +29,7 @@ interface FinishNotificationBodyInput {
title: string;
reason: FinishNotificationReason;
lastAssistantMessage: string | null;
error: string | null;
permissionRequest?: AgentPermissionRequest;
}
@@ -58,13 +59,15 @@ export function formatFinishNotificationBody(params: FinishNotificationBodyInput
)}\n</permission-request>`,
);
}
let lastAssistantMessage = params.lastAssistantMessage?.trim();
if (lastAssistantMessage) {
if (lastAssistantMessage.length > FINISH_NOTIFICATION_MESSAGE_LIMIT) {
const omitted = lastAssistantMessage.length - FINISH_NOTIFICATION_MESSAGE_LIMIT;
lastAssistantMessage = `${lastAssistantMessage.slice(0, FINISH_NOTIFICATION_MESSAGE_LIMIT)}\n[truncated ${omitted} chars; use get_agent_activity for the full response]`;
const failed = params.reason === "errored";
let outcome = (failed ? params.error : params.lastAssistantMessage)?.trim();
if (outcome) {
if (outcome.length > FINISH_NOTIFICATION_MESSAGE_LIMIT) {
const omitted = outcome.length - FINISH_NOTIFICATION_MESSAGE_LIMIT;
outcome = `${outcome.slice(0, FINISH_NOTIFICATION_MESSAGE_LIMIT)}\n[truncated ${omitted} chars; use get_agent_activity for the full response]`;
}
sections.push(`<agent-response>\n${lastAssistantMessage}\n</agent-response>`);
const tag = failed ? "agent-error" : "agent-response";
sections.push(`<${tag}>\n${outcome}\n</${tag}>`);
}
return sections.join("\n\n");
}
@@ -374,7 +374,7 @@ test.each(["agent", "workspace"] as const)(
clientMessageId: agent.clientMessageId,
messageId: agent.clientMessageId,
},
{ type: "assistant_message", text: `[System Error] ${rejection}` },
{ type: "error", message: rejection },
];
expect(
(await client.fetchAgentTimeline(created.id)).entries.map((entry) => entry.item),
@@ -63,12 +63,7 @@ test("keeps two concurrent startup steer messages in one real Codex turn", async
expect(
events.filter((event) => event.type === "turn_canceled" || event.type === "turn_failed"),
).toHaveLength(0);
expect(
timeline.entries.some(
(entry) =>
entry.item.type === "assistant_message" && entry.item.text.includes("[System Error]"),
),
).toBe(false);
expect(timeline.entries.some(({ item }) => item.type === "error")).toBe(false);
}
} finally {
await Promise.all(subscriptions.map((subscription) => subscription.release()));
@@ -33,20 +33,16 @@ function hasRunningBashToolCall(messages: SessionOutboundMessage[], agentId: str
);
}
function getAssistantTexts(messages: SessionOutboundMessage[], agentId: string): string[] {
function getStreamErrors(messages: SessionOutboundMessage[], agentId: string): string[] {
return messages
.filter(
(message) =>
message.type === "agent_stream" &&
message.payload.agentId === agentId &&
message.payload.event.type === "timeline" &&
message.payload.event.item.type === "assistant_message",
message.payload.event.item.type === "error",
)
.map((message) => message.payload.event.item.text);
}
function findSystemErrorText(texts: string[]): string | null {
return texts.find((text) => text.includes("[System Error]")) ?? null;
.map((message) => message.payload.event.item.message);
}
function getTimelineAssistantTexts(
@@ -121,7 +117,7 @@ async function waitForRunningBashToolCall(
while (Date.now() < deadline) {
await approvePendingPermissions(client, agentId, handledPermissionIds);
const streamSystemError = findSystemErrorText(getAssistantTexts(collector.messages, agentId));
const streamSystemError = getStreamErrors(collector.messages, agentId)[0];
if (streamSystemError) {
throw new Error(`OpenCode failed before tool call started: ${streamSystemError}`);
}
@@ -131,11 +127,13 @@ async function waitForRunningBashToolCall(
}
const timeline = await client.fetchAgentTimeline(agentId, { limit: 120 }).catch(() => null);
const timelineSystemError = timeline
? findSystemErrorText(getTimelineAssistantTexts(timeline).slice(-8))
: null;
if (timelineSystemError) {
throw new Error(`OpenCode failed before tool call started: ${timelineSystemError}`);
const timelineSystemError = timeline?.entries
.slice(-8)
.find(({ item }) => item.type === "error");
if (timelineSystemError?.item.type === "error") {
throw new Error(
`OpenCode failed before tool call started: ${timelineSystemError.item.message}`,
);
}
if (
timeline?.entries.some(
@@ -314,16 +312,12 @@ describe("daemon E2E (real opencode) - send while working and interrupt", () =>
const finish = await waitForIdleResolvingPermissions(client, agent.id, 240_000);
expect(finish.status).toBe("idle");
const postSendAssistantTexts = getAssistantTexts(collector.messages, agent.id);
expect(postSendAssistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(postSendAssistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(
false,
);
expect(getStreamErrors(collector.messages, agent.id)).toEqual([]);
const timeline = await client.fetchAgentTimeline(agent.id, { limit: 160 });
const assistantTexts = getTimelineAssistantTexts(timeline);
expect(assistantTexts.some((text) => text.includes(followUpToken))).toBe(true);
expect(assistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(timeline.entries.some(({ item }) => item.type === "error")).toBe(false);
expect(assistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(false);
} finally {
collector.unsubscribe();
@@ -383,18 +377,12 @@ describe("daemon E2E (real opencode) - send while working and interrupt", () =>
const finish = await waitForIdleResolvingPermissions(client, agent.id, 240_000);
expect(finish.status).toBe("idle");
const postInterruptAssistantTexts = getAssistantTexts(collector.messages, agent.id);
expect(postInterruptAssistantTexts.some((text) => text.includes("[System Error]"))).toBe(
false,
);
expect(postInterruptAssistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(
false,
);
expect(getStreamErrors(collector.messages, agent.id)).toEqual([]);
const timeline = await client.fetchAgentTimeline(agent.id, { limit: 200 });
const assistantTexts = getTimelineAssistantTexts(timeline);
expect(assistantTexts.some((text) => text.includes(followUpToken))).toBe(true);
expect(assistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(timeline.entries.some(({ item }) => item.type === "error")).toBe(false);
expect(assistantTexts.some((text) => text.includes(SYSTEM_ERROR_SNIPPET))).toBe(false);
} finally {
collector.unsubscribe();
@@ -957,9 +957,16 @@ describe("daemon E2E (real claude) - send message during tool call", () => {
});
// No system error messages should leak into the timeline
const hasSystemError = assistantTexts.some((text) => text.includes("[System Error]"));
expect(hasSystemError).toBe(false);
expect(postSendAssistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(timeline.entries.some(({ item }) => item.type === "error")).toBe(false);
expect(
postSendMessages.some(
(message) =>
message.type === "agent_stream" &&
message.payload.agentId === agent.id &&
message.payload.event.type === "timeline" &&
message.payload.event.item.type === "error",
),
).toBe(false);
const responded = assistantTexts.some((text) =>
text.toUpperCase().includes("INTERRUPT_RECEIVED"),
@@ -450,7 +450,7 @@ describe("daemon E2E (real codex) - send message during tool call", () => {
const item = entry.item as Extract<AgentTimelineItem, { type: "assistant_message" }>;
return item.text;
});
expect(assistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(timeline.entries.some(({ item }) => item.type === "error")).toBe(false);
expect(assistantTexts.some((text) => text.toUpperCase().includes("INTERRUPT_RECEIVED"))).toBe(
true,
);
@@ -527,7 +527,7 @@ describe("daemon E2E (real codex) - send message during tool call", () => {
const item = entry.item as Extract<AgentTimelineItem, { type: "assistant_message" }>;
return item.text;
});
expect(assistantTexts.some((text) => text.includes("[System Error]"))).toBe(false);
expect(timeline.entries.some(({ item }) => item.type === "error")).toBe(false);
expect(
assistantTexts.some((text) => text.toUpperCase().includes("QUICK_FOLLOW_UP_RECEIVED")),
).toBe(true);
@@ -1937,6 +1937,57 @@ describe("ScheduleService", () => {
expect(storedAgent?.archivedAt).toBeTruthy();
});
test.each(["new-agent", "agent"] as const)(
"scheduled %s failures preserve the provider reason",
async (targetType) => {
const manager = new AgentManager({
logger: createTestLogger(),
clients: createTestAgentClients({
turnFailure: {
error: "Requested fake provider failure",
code: "126",
diagnostic: "Provider executable failed",
},
}),
registry: agentStorage,
});
const service = createScheduleService({
paseoHome: tempDir,
logger: createTestLogger(),
agentManager: manager,
agentStorage,
providerSnapshotManager: NO_UNATTENDED_SCHEDULE_POLICY,
now: () => now,
});
const agent = await manager.createAgent(
{ provider: "claude", cwd: tempDir, modeId: "bypassPermissions" },
undefined,
{ workspaceId: undefined },
);
await manager.runAgent(agent.id, "Earlier successful request");
const earlierReply = await manager.getLastAssistantMessage(agent.id);
expect(earlierReply).toBeTruthy();
const schedule = await service.create({
prompt: "Emit a turn failure",
cadence: { type: "every", everyMs: 60_000 },
target:
targetType === "agent"
? { type: "agent", agentId: agent.id }
: {
type: "new-agent",
config: { provider: "claude", cwd: tempDir, archiveOnFinish: false },
},
maxRuns: 1,
});
await service.runOnce(schedule.id);
expect((await service.inspect(schedule.id)).runs[0]).toMatchObject({
status: "failed",
error: "Requested fake provider failure\n\ncode: 126\n\nProvider executable failed",
});
await manager.closeAgent(agent.id);
},
);
test("records prompt-start failures as failed and archives the scheduled agent", async () => {
class StartFailureScheduleSession implements AgentSession {
readonly provider = "claude";
@@ -986,6 +986,12 @@ export class ScheduleService {
requireSchedule(updatedSchedule, params.scheduleId);
}
private scheduledAgentFailure(agentId: string): Error {
return new Error(
this.agentManager.getAgent(agentId)?.lastError ?? `Scheduled agent ${agentId} failed`,
);
}
private async executeSchedule(
schedule: StoredSchedule,
runId: string,
@@ -1019,7 +1025,7 @@ export class ScheduleService {
throw new Error(`Scheduled agent ${agent.id} is waiting for permission`);
}
if (waitResult.status === "error") {
throw new Error(waitResult.lastMessage ?? `Scheduled agent ${agent.id} failed`);
throw this.scheduledAgentFailure(agent.id);
}
return {
agentId: agent.id,
@@ -1086,7 +1092,7 @@ export class ScheduleService {
throw new Error(`Scheduled agent ${agent.id} is waiting for permission`);
}
if (waitResult.status === "error") {
throw new Error(waitResult.lastMessage ?? `Scheduled agent ${agent.id} failed`);
throw this.scheduledAgentFailure(agent.id);
}
const timelineText = curateAgentActivity(result.timeline);
return {
@@ -74,6 +74,7 @@ interface Deferred<T> {
}
interface FakeAgentSessionOptions {
turnFailure?: TestAgentClientOptions["turnFailure"];
providerName: string;
config: AgentSessionConfig;
supportsMcpServers?: boolean;
@@ -89,6 +90,10 @@ interface FakeAgentSessionOptions {
}
export interface TestAgentClientOptions {
turnFailure?: Pick<
Extract<AgentStreamEvent, { type: "turn_failed" }>,
"error" | "code" | "diagnostic"
>;
beforeCreateSession?: (config: AgentSessionConfig) => Promise<void>;
beforeResumeSession?: (handle: AgentPersistenceHandle) => Promise<void>;
closeSession?: () => Promise<void>;
@@ -375,6 +380,7 @@ class FakeAgentSession implements AgentSession {
private readonly closeSession: (() => Promise<void>) | undefined;
private readonly onStartTurn: TestAgentClientOptions["onStartTurn"];
private readonly beforeTurnComplete: ((prompt: AgentPromptInput) => Promise<void>) | undefined;
private readonly turnFailure: TestAgentClientOptions["turnFailure"];
private readonly historyEvents: readonly AgentStreamEvent[] | undefined;
constructor(options: FakeAgentSessionOptions) {
@@ -393,6 +399,7 @@ class FakeAgentSession implements AgentSession {
this.onStartTurn = options.onStartTurn;
this.beforeTurnComplete = options.beforeTurnComplete;
this.historyEvents = options.historyEvents;
this.turnFailure = options.turnFailure;
this.historyPath = path.join(
tmpdir(),
"paseo-fake-provider-history",
@@ -842,6 +849,7 @@ class FakeAgentSession implements AgentSession {
type: "turn_failed",
provider: this.providerName,
error: "Requested fake provider failure",
...this.turnFailure,
};
await this.appendHistoryEvent(failed);
this.notifySubscribers(failed);
@@ -1318,6 +1326,7 @@ class FakeAgentClient implements AgentClient {
onInterrupt: this.options.onInterrupt,
beforeSetMode: this.options.beforeSetMode,
historyEvents: this.options.historyEvents,
turnFailure: this.options.turnFailure,
});
}
@@ -1349,6 +1358,7 @@ class FakeAgentClient implements AgentClient {
onInterrupt: this.options.onInterrupt,
beforeSetMode: this.options.beforeSetMode,
historyEvents: this.options.historyEvents,
turnFailure: this.options.turnFailure,
});
}