Skip to content
Merged
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
36 changes: 36 additions & 0 deletions packages/chat-ui/src/streaming-reply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,42 @@ describe("nextStreamingReplyState (CL-6115: token deltas fold into a growing rep
});
});

describe("nextStreamingReplyState (CL-6376: the typing pulse clears on a dispatch failure too)", () => {
test("a chat.message carrying a turnFailed part clears a pending reply", () => {
const state = { text: "" };
expect(
nextStreamingReplyState(state, {
eventType: "chat.message",
data: {
id: "msg_1",
parts: [
{ kind: "text", text: "I didn't get that one", turnFailed: true },
],
},
}),
).toBeNull();
});

test("an ordinary chat.message (no turnFailed part) leaves the reply untouched", () => {
const state = { text: "" };
expect(
nextStreamingReplyState(state, {
eventType: "chat.message",
data: { id: "msg_1", parts: [{ kind: "text", text: "hi" }] },
}),
).toBe(state);
});

test("a chat.message with no pending reply stays null", () => {
expect(
nextStreamingReplyState(null, {
eventType: "chat.message",
data: { parts: [{ kind: "text", text: "x", turnFailed: true }] },
}),
).toBeNull();
});
});

describe("openPendingReply", () => {
test("opens an empty pending reply when idle", () => {
expect(openPendingReply(null)).toEqual({ text: "" });
Expand Down
28 changes: 26 additions & 2 deletions packages/chat-ui/src/streaming-reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ function innerEventType(data: unknown): string | null {
return typeof type === "string" ? type : null;
}

/** Whether a `chat.message` payload carries `postUndeliveredNotice`'s
* `turnFailed` part (see `packages/chat/src/workbench-service.ts`). This
* notice posts straight to the room with no `chat.agent` events at all —
* the dispatch failed before `sendMail` ever reached the agent — so
* without this check a turn that fails this way never emits the
* `reactor.error`/`inference.error` this module otherwise relies on to
* clear the typing pulse, leaving it stranded until the 120s backstop. */
function hasTurnFailedPart(data: unknown): boolean {
if (typeof data !== "object" || data === null) return false;
const parts = (data as Record<string, unknown>).parts;
if (!Array.isArray(parts)) return false;
return parts.some(
(part) =>
typeof part === "object" &&
part !== null &&
(part as Record<string, unknown>).turnFailed === true,
);
}

/**
* The streaming reply's whole state machine, pure: an `inference.start`
* opens an empty in-progress reply if nothing is showing yet (it never
Expand All @@ -58,13 +77,18 @@ function innerEventType(data: unknown): string | null {
* clear it — the turn is over. `inference.done` only clears once tokens
* have streamed (the persisted message takes over); an empty pending
* survives so the typing pulse stays up across tool rounds. `inference.error`
* always clears. Every other event type (tool calls, thinking, usage)
* leaves the current state untouched.
* always clears. A `chat.message` carrying `postUndeliveredNotice`'s
* `turnFailed` part also clears it (see `hasTurnFailedPart`) — the one
* failure path with no `chat.agent` events of its own. Every other event
* type (tool calls, thinking, usage) leaves the current state untouched.
*/
export function nextStreamingReplyState(
current: StreamingReplyState,
event: { readonly eventType: string; readonly data: unknown },
): StreamingReplyState {
if (event.eventType === "chat.message") {
return hasTurnFailedPart(event.data) ? null : current;
}
if (event.eventType !== "chat.agent") return current;

const innerType = innerEventType(event.data);
Expand Down
56 changes: 54 additions & 2 deletions packages/chat-ui/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2772,8 +2772,14 @@
"Reply in thread" link and the standalone add-reaction trigger. Floats
over the message's top-right corner, fading in on hover/focus-within
like `.chat-pin-toggle` above, plus `data-open` so it stays put while its
own picker or menu is open even if focus moves into a portaled menu. */
.chat-message-group {
own picker or menu is open even if focus moves into a portaled menu.
Positioned relative to `.chat-message-row` (CL-6376) — the wrapper
around this one message's own content, siblings-with but excluding its
optional `.chat-day-divider` — rather than `.chat-message-group` as a
whole: anchoring to the outer group let the toolbar float up into the
day divider's own space on the first message of a new day, detached
from the row a reader was actually hovering. */
.chat-message-row {
position: relative;
}

Expand Down Expand Up @@ -3622,3 +3628,49 @@
.chat-pr-failed-what-happened:hover {
color: var(--foreground);
}

/* The general chat timeline's own failed-turn row (CL-6376) — a quiet
inline system line under the same left gutter every message sits
under, not a bordered banner: muted danger-tinted text, a small ghost
Retry, and "What happened" as an inline disclosure. Reads as part of
the conversation rather than an alert dropped into it. */
.chat-turn-failed {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.5rem;
margin: 0.15rem 0 0.35rem 2.9rem;
max-width: 100%;
font-size: 0.8125rem;
}

.chat-turn-failed-text {
color: color-mix(in srgb, var(--destructive) 78%, var(--muted-foreground));
}

.chat-turn-failed-retry {
height: auto;
padding: 0.05rem 0.45rem;
font-size: 0.75rem;
}

.chat-turn-failed-disclosure {
border: 0;
background: transparent;
padding: 0;
font-size: 0.75rem;
color: var(--muted-foreground);
text-decoration: underline;
text-underline-offset: 2px;
cursor: pointer;
}

.chat-turn-failed-disclosure:hover {
color: var(--foreground);
}

.chat-turn-failed-detail {
flex-basis: 100%;
font-size: 0.75rem;
color: var(--muted-foreground);
}
Loading
Loading