Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

Preserve streamed text and process info when a turn errors out

wyt42f91870e63c
diff --git a/src/main/features/group_chat/plan_executor.ts b/src/main/features/group_chat/plan_executor.ts
index 4fc9ff29..2ee28149 100644
--- a/src/main/features/group_chat/plan_executor.ts
+++ b/src/main/features/group_chat/plan_executor.ts
@@ -262,16 +262,22 @@ function outcomeForSynthTurn(evt: TurnFinishedEvent): TurnOutcome {
if (evt.aborted) {
return abortOutcome(evt);
}
- if (evt.errText) {
- return { kind: 'persist', text: errorBubble(evt.errText) };
- }
if (evt.finalText && evt.finalText.trim()) {
+ // Keep the partial reply and append the error pill underneath when
+ // the stream errored mid-turn — otherwise the user loses everything
+ // the model already produced and only sees the error.
+ const body = evt.errText
+ ? `${evt.finalText}\n\n${errorBubble(evt.errText)}`
+ : evt.finalText;
return {
kind: 'persist',
- text: evt.finalText,
+ text: body,
...(evt.produced.length ? { produced: evt.produced } : {}),
};
}
+ if (evt.errText) {
+ return { kind: 'persist', text: errorBubble(evt.errText) };
+ }
// Empty final on a synth turn = user gets a placeholder so they at least
// see "the plan finished but I had nothing more to add".
return { kind: 'persist', text: '(无回复)' };
@@ -326,9 +332,16 @@ async function outcomeForUserDirectTurn(uid: string, cid: string, evt: TurnFinis
// the form widget entirely (the user-reported bug).
const hasSideEffect = !!evt.form || !!evt.createdAgent || (evt.produced && evt.produced.length > 0);
if ((evt.finalText && evt.finalText.trim()) || hasSideEffect) {
+ // When the stream errored mid-turn but partial text / side effects
+ // already landed, append the error pill instead of dropping the
+ // partial — same intent as outcomeForSynthTurn's branch above.
+ const partial = evt.finalText || '';
+ const body = evt.errText
+ ? (partial ? `${partial}\n\n${errorBubble(evt.errText)}` : errorBubble(evt.errText))
+ : partial;
return {
kind: 'persist',
- text: evt.finalText || '',
+ text: body,
...(evt.form ? { form: evt.form } : {}),
...(evt.produced.length ? { produced: evt.produced } : {}),
...(evt.createdAgent ? { createdAgent: evt.createdAgent } : {}),
diff --git a/src/renderer/modules/conversation.js b/src/renderer/modules/conversation.js
index a5ba60f4..3f46bce2 100644
--- a/src/renderer/modules/conversation.js
+++ b/src/renderer/modules/conversation.js
@@ -2112,8 +2112,24 @@ function _streamingSetError(msg, text) {
}
const finalEl = msg.querySelector('[data-role="final"]');
if (!finalEl) return;
- finalEl.innerHTML = `<span style="color:var(--danger)">${escapeHtml(t('chat.send_failed', { msg: text }))}</span>`;
+ // Preserve any partial reply that streamed in before the error so the
+ // user keeps the assistant's in-flight prose / process info, then append
+ // the error pill underneath. Without this, mid-stream errors wipe the
+ // visible turn entirely and the user only sees the error pill.
+ const partial = String(msg.dataset.streamBuf || '');
+ let bodyHtml = '';
+ if (partial) {
+ const display = _stripSurvivingAgentBlocks(partial);
+ if (display) {
+ bodyHtml = `<div class="markdown-body">${_renderMessageMarkdown(display)}</div>`;
+ msg.dataset.finalText = display;
+ }
+ }
+ const errPill = `<div class="msg-error" style="color:var(--danger);margin-top:6px">${escapeHtml(t('chat.send_failed', { msg: text }))}</div>`;
+ finalEl.innerHTML = bodyHtml + errPill;
finalEl.style.display = '';
+ delete msg.dataset.streamBuf;
+ if (bodyHtml && typeof typesetMath === 'function') typesetMath(finalEl);
}
// Mark the assistant bubble as user-interrupted. Preserves whatever partial