Skip to content

Commit 6084c26

Browse files
committed
fix(tui): render final event error when assistant output is empty (#14687)
1 parent 94fdee2 commit 6084c26

7 files changed

Lines changed: 56 additions & 2 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Docs: https://docs.openclaw.ai
3131

3232
- Gateway/chat streaming tool-boundary text retention: merge assistant delta segments into per-run chat buffers so pre-tool text is preserved in live chat deltas/finals when providers emit post-tool assistant segments as non-prefix snapshots. (#36957) Thanks @Datyedyeguy.
3333
- TUI/model indicator freshness: prevent stale session snapshots from overwriting freshly patched model selection (and reset per-session freshness when switching session keys) so `/model` updates reflect immediately instead of lagging by one or more commands. (#21255) Thanks @kowza.
34+
- TUI/final-error rendering fallback: when a chat `final` event has no renderable assistant content but includes envelope `errorMessage`, render the formatted error text instead of collapsing to `"(no output)"`, preserving actionable failure context in-session. (#14687) Thanks @Mquarmoc.
3435
- OpenAI Codex OAuth/login hardening: fail OAuth completion early when the returned token is missing `api.responses.write`, and allow `openclaw models auth login --provider openai-codex` to use the built-in OAuth path even when no provider plugins are installed. (#36660) Thanks @driesvints.
3536
- OpenAI Codex OAuth/scope request parity: augment the OAuth authorize URL with required API scopes (`api.responses.write`, `model.request`, `api.model.read`) before browser handoff so OAuth tokens include runtime model/request permissions expected by OpenAI API calls. (#24720) Thanks @Skippy-Gunboat.
3637
- Gateway/remote WS break-glass hostname support: honor `OPENCLAW_ALLOW_INSECURE_PRIVATE_WS=1` for `ws://` hostname URLs (not only private IP literals) across onboarding validation and runtime gateway connection checks, while still rejecting public IP literals and non-unicast IPv6 endpoints. (#36930) Thanks @manju-rn.

‎src/tui/tui-event-handlers.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,26 @@ describe("tui-event-handlers: handleAgentEvent", () => {
403403
expect(state.activeChatRunId).toBe("run-active");
404404
});
405405

406+
it("renders final error text when chat final has no content but includes event errorMessage", () => {
407+
const { state, chatLog, handleChatEvent } = createHandlersHarness({
408+
state: { activeChatRunId: null },
409+
});
410+
411+
handleChatEvent({
412+
runId: "run-error-envelope",
413+
sessionKey: state.currentSessionKey,
414+
state: "final",
415+
message: { content: [] },
416+
errorMessage: '401 {"error":{"message":"Missing scopes: model.request"}}',
417+
});
418+
419+
expect(chatLog.finalizeAssistant).toHaveBeenCalledTimes(1);
420+
const [rendered] = chatLog.finalizeAssistant.mock.calls[0] ?? [];
421+
expect(String(rendered)).toContain("HTTP 401");
422+
expect(String(rendered)).toContain("Missing scopes: model.request");
423+
expect(chatLog.dropAssistant).not.toHaveBeenCalledWith("run-error-envelope");
424+
});
425+
406426
it("drops streaming assistant when chat final has no message", () => {
407427
const { state, chatLog, handleChatEvent } = createHandlersHarness({
408428
state: { activeChatRunId: null },

‎src/tui/tui-event-handlers.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ export function createEventHandlers(context: EventHandlerContext) {
202202
: ""
203203
: "";
204204

205-
const finalText = streamAssembler.finalize(evt.runId, evt.message, state.showThinking);
205+
const finalText = streamAssembler.finalize(
206+
evt.runId,
207+
evt.message,
208+
state.showThinking,
209+
evt.errorMessage,
210+
);
206211
const suppressEmptyExternalPlaceholder =
207212
finalText === "(no output)" && !isLocalRunId?.(evt.runId);
208213
if (suppressEmptyExternalPlaceholder) {

‎src/tui/tui-formatters.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export function sanitizeRenderableText(text: string): string {
142142
export function resolveFinalAssistantText(params: {
143143
finalText?: string | null;
144144
streamedText?: string | null;
145+
errorMessage?: string | null;
145146
}) {
146147
const finalText = params.finalText ?? "";
147148
if (finalText.trim()) {
@@ -151,6 +152,10 @@ export function resolveFinalAssistantText(params: {
151152
if (streamedText.trim()) {
152153
return streamedText;
153154
}
155+
const errorMessage = params.errorMessage ?? "";
156+
if (errorMessage.trim()) {
157+
return formatRawAssistantErrorForUi(errorMessage);
158+
}
154159
return "(no output)";
155160
}
156161

‎src/tui/tui-stream-assembler.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ describe("TuiStreamAssembler", () => {
8686
expect(finalText).toBe("Streamed");
8787
});
8888

89+
it("falls back to event error message when final payload has no renderable text", () => {
90+
const assembler = new TuiStreamAssembler();
91+
const finalText = assembler.finalize(
92+
"run-3-error",
93+
{ role: "assistant", content: [] },
94+
false,
95+
'401 {"error":{"message":"Missing scopes: model.request"}}',
96+
);
97+
expect(finalText).toContain("HTTP 401");
98+
expect(finalText).toContain("Missing scopes: model.request");
99+
});
100+
89101
it("returns null when delta text is unchanged", () => {
90102
const assembler = new TuiStreamAssembler();
91103
const first = assembler.ingestDelta("run-4", messageWithContent([text("Repeat")]), false);

‎src/tui/tui-stream-assembler.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class TuiStreamAssembler {
174174
return state.displayText;
175175
}
176176

177-
finalize(runId: string, message: unknown, showThinking: boolean): string {
177+
finalize(runId: string, message: unknown, showThinking: boolean, errorMessage?: string): string {
178178
const state = this.getOrCreateRun(runId);
179179
const streamedDisplayText = state.displayText;
180180
const streamedTextBlocks = [...state.contentBlocks];
@@ -192,6 +192,7 @@ export class TuiStreamAssembler {
192192
const finalText = resolveFinalAssistantText({
193193
finalText: shouldKeepStreamedText ? streamedDisplayText : finalComposed,
194194
streamedText: streamedDisplayText,
195+
errorMessage,
195196
});
196197

197198
this.runs.delete(runId);

‎src/tui/tui.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ describe("resolveFinalAssistantText", () => {
2323
}),
2424
).toBe("All done");
2525
});
26+
27+
it("falls back to formatted error text when final and streamed text are empty", () => {
28+
expect(
29+
resolveFinalAssistantText({
30+
finalText: "",
31+
streamedText: "",
32+
errorMessage: '401 {"error":{"message":"Missing scopes: model.request"}}',
33+
}),
34+
).toContain("HTTP 401");
35+
});
2636
});
2737

2838
describe("tui slash commands", () => {

0 commit comments

Comments
 (0)