From e02b80211a0c5a725e2a66a6a1db764b2649eca1 Mon Sep 17 00:00:00 2001 From: Sanchit Rk <0xsanchit@gmail.com> Date: Sun, 1 Nov 2026 17:03:50 +0530 Subject: [PATCH] fix(desktop): show why a reply failed when the conversation reopens A provider failure was only sent live, so a conversation opened afterwards showed the reply as Interrupted with no reason. thread.history now carries a failed reply's provider/model and reason, and the desktop shows it in place. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/widgets/session/view.tsx | 9 +++++++-- apps/widget/src/codework.ts | 2 ++ packages/codework/src/server/contract.ts | 2 ++ packages/codework/src/server/handlers.ts | 20 +++++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/web/src/widgets/session/view.tsx b/apps/web/src/widgets/session/view.tsx index 3d3a256c..039d8849 100644 --- a/apps/web/src/widgets/session/view.tsx +++ b/apps/web/src/widgets/session/view.tsx @@ -387,13 +387,14 @@ const TurnView = memo(function TurnView({ turn, active }: { readonly turn: Turn; .flatMap((reply) => reply.parts.filter((part) => !(reply === last && part.type === "text"))) .filter(isWork); const interrupted = last?.state === "aborted"; + const failed = last?.error !== undefined; // While the agent works and no answer is streaming, it is thinking or running a tool. const thinking = active && (last?.state !== "draft" || answer.length === 0); return (
{turn.user !== undefined && } - {(work.length > 0 || thinking || answer.length > 0 || interrupted) && ( + {(work.length > 0 || thinking || answer.length > 0 || interrupted || failed) && ( {work.length > 0 && ( )} - {interrupted &&

Interrupted

} + {last?.error !== undefined ? ( +

{last.error}

+ ) : ( + interrupted &&

Interrupted

+ )}
)}
diff --git a/apps/widget/src/codework.ts b/apps/widget/src/codework.ts index 0b7214be..c54fc94d 100644 --- a/apps/widget/src/codework.ts +++ b/apps/widget/src/codework.ts @@ -58,6 +58,8 @@ export const HistoryEntry = Schema.Struct({ /** Epoch milliseconds of the last change; for a reply, when it ended once it is no longer a draft. */ updatedAt: Schema.Finite, parts: Schema.Array(Part), + /** Why a reply failed, as `provider/model: reason`; absent for one that ended normally or was stopped. */ + error: Schema.optionalKey(Schema.String), }); export type HistoryEntry = typeof HistoryEntry.Type; diff --git a/packages/codework/src/server/contract.ts b/packages/codework/src/server/contract.ts index d672f2f0..11f43653 100644 --- a/packages/codework/src/server/contract.ts +++ b/packages/codework/src/server/contract.ts @@ -123,6 +123,8 @@ export const HistoryEntry = Schema.Struct({ /** Epoch milliseconds of the last change; for a reply, when it ended once it is no longer a draft. */ updatedAt: Schema.Finite, parts: Schema.Array(Part), + /** Why a reply failed, as `provider/model: reason`; absent for one that ended normally or was stopped. */ + error: optional(Schema.String), }); export type HistoryEntry = typeof HistoryEntry.Type; diff --git a/packages/codework/src/server/handlers.ts b/packages/codework/src/server/handlers.ts index 6d18fef3..8d7ce5eb 100644 --- a/packages/codework/src/server/handlers.ts +++ b/packages/codework/src/server/handlers.ts @@ -17,7 +17,7 @@ import { ThreadSchema, ThreadStore, } from "@codeworksh/harness/effect"; -import { DateTime, Effect, Option, Stream } from "effect"; +import { DateTime, Effect, Option, Schema, Stream } from "effect"; import { Contract, type HistoryEntry, @@ -77,6 +77,20 @@ const runtimeInput = (runtime: RuntimeConfig | undefined): Session.RuntimeInput ...(runtime?.foundation == null ? {} : { foundation: runtime.foundation }), }); +// A failed reply's envelope keeps the provider's reason; it reads as the live failure does. +const decodeFailedReply = Schema.decodeUnknownOption( + Schema.fromJsonString( + Schema.Struct({ + stopReason: Schema.Literal("error"), + errorMessage: Schema.String, + provider: Schema.Struct({ id: Schema.String }), + model: Schema.String, + }), + ), +); +const replyError = (data: string) => + Option.map(decodeFailedReply(data), (reply) => `${reply.provider.id}/${reply.model}: ${reply.errorMessage}`); + const threadInfo = (threadId: ThreadSchema.ID) => Session.threadInfo(threadId).pipe(Effect.map(toThreadInfo)); // RpcServer's request span has no level, so it is Debug and drops every Info span under it. @@ -278,6 +292,10 @@ export const layer = Contract.Api.toLayer( updatedAt: DateTime.toEpochMillis(entry.updatedAt), // A part this schema does not render (a future aikit type) is skipped, not fatal. parts: parts.flatMap((part) => Option.toArray(MessagePart.decode(part.data))), + ...Option.match(entry.type === "assistant" ? replyError(entry.data) : Option.none(), { + onNone: () => ({}), + onSome: (error) => ({ error }), + }), }, ] : [],