Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(chat): never read an idle turn with live rows as completed

liuzixiang0aeb5ccf28c4
diff --git a/apps/desktop/src/features/chat/transcript/TurnProcess.tsx b/apps/desktop/src/features/chat/transcript/TurnProcess.tsx
index 95700dfc4..fdd6cc797 100644
--- a/apps/desktop/src/features/chat/transcript/TurnProcess.tsx
+++ b/apps/desktop/src/features/chat/transcript/TurnProcess.tsx
@@ -128,6 +128,7 @@ export function TurnProcess({
const label = (() => {
if (phase.kind === "failed") return t("chat.processFailed");
if (phase.kind === "stopped") return t("chat.processStopped");
+ if (phase.kind === "unsettled") return t("chat.processUnsettled");
if (phase.kind === "completed") return t("chat.processCompleted");
// Live: only stages with their own settled wording get their own label. The
// rest describe an instant at the start of a request, and naming them would
diff --git a/apps/desktop/src/lib/turn-process.ts b/apps/desktop/src/lib/turn-process.ts
index aef11dc7f..0060724dd 100644
--- a/apps/desktop/src/lib/turn-process.ts
+++ b/apps/desktop/src/lib/turn-process.ts
@@ -194,21 +194,28 @@ export function segmentTurnProcess(
* working on, because a shell command can be arbitrarily long and would push
* the counts off the row.
*
- * Precedence is deliberate: failure, stop, running, completed. A recorded
- * failure outranks everything: the turn produced no answer, and a header
- * reading "Processed" over a failed run hid that. A user stop outranks a live
- * run and completion alike - the work was interrupted, not finished - and it is
- * read from the turn's own aborted rows because the turn result only
+ * Precedence is deliberate: failure, stop, running, unsettled, completed. A
+ * recorded failure outranks everything: the turn produced no answer, and a
+ * header reading "Processed" over a failed run hid that. A user stop outranks a
+ * live run and completion alike - the work was interrupted, not finished - and
+ * it is read from the turn's own aborted rows because the turn result only
* distinguishes completed from failed. Both assistant message rows and activity
* item rows count; a Stop while a tool or reasoning row is in flight settles
* there rather than in a trailing text. Delegate child rows are deliberately
- * not scanned: a failed child is not a failed or stopped turn.
+ * not scanned: a failed child is not a failed or stopped turn. An idle turn
+ * whose rows never reached a terminal status is not completed either - a crash
+ * or a lost host leaves its last row streaming forever, and reading that as
+ * done is exactly the lie the completed fallback used to tell - so it reports
+ * an unknown outcome. Rows recorded before statuses existed carry no signal
+ * either way and stay completed.
*/
export type TurnProcessPhase =
| { kind: "failed" }
| { kind: "stopped" }
/** Live work; `phase` names the runtime stage when one is known. */
| { kind: "running"; phase?: AgentActivity["phase"] }
+ /** Nothing is driving the turn, yet its rows never settled. */
+ | { kind: "unsettled" }
| { kind: "completed" };
export function turnProcessPhase({
@@ -238,6 +245,12 @@ export function turnProcessPhase({
);
if (stopped) return { kind: "stopped" };
if (isActive) return { kind: "running", phase: activity?.phase };
+ const unsettled = parts.some((part) =>
+ part.kind === "message"
+ ? part.message.status === "streaming"
+ : part.items.some((item) => item.message.status === "streaming"),
+ );
+ if (unsettled) return { kind: "unsettled" };
return { kind: "completed" };
}
diff --git a/apps/desktop/test/turn-process.test.mjs b/apps/desktop/test/turn-process.test.mjs
index b07bf4dad..5688ce5bc 100644
--- a/apps/desktop/test/turn-process.test.mjs
+++ b/apps/desktop/test/turn-process.test.mjs
@@ -504,6 +504,40 @@ test("a failed child never turns a completed turn into failed or stopped", () =>
);
});
+test("an idle turn whose rows never settled is not reported as completed", () => {
+ // A sidecar crash or a lost host leaves the last rows streaming forever: the
+ // idle turn must not claim an outcome the transcript never recorded (#1923).
+ const streamingAnswer = {
+ kind: "message",
+ message: message("t1", "assistant", "", { status: "streaming" }),
+ };
+ assert.deepEqual(
+ turnProcessPhase({ parts: [streamingAnswer], isActive: false, failed: false }),
+ { kind: "unsettled" },
+ );
+ // A tool that never answered reads the same way while nothing drives it.
+ const hungTool = {
+ kind: "activity",
+ items: [{ kind: "tool", message: message("tool1", "tool", "", { toolName: "Bash", status: "streaming" }) }],
+ };
+ assert.deepEqual(
+ turnProcessPhase({ parts: [hungTool], isActive: false, failed: false }),
+ { kind: "unsettled" },
+ );
+ // While the turn is live the same rows are just work in progress.
+ assert.deepEqual(
+ turnProcessPhase({ parts: [streamingAnswer], isActive: true, failed: false }),
+ { kind: "running", phase: undefined },
+ );
+ // Rows recorded before statuses existed carry no signal either way: a
+ // settled turn stays completed rather than rewriting history.
+ const legacy = { kind: "message", message: message("t2", "assistant", "done") };
+ assert.deepEqual(
+ turnProcessPhase({ parts: [legacy], isActive: false, failed: false }),
+ { kind: "completed" },
+ );
+});
+
test("the header count comes from the production activity summary", () => {
const entry = turn([
message("user", "user", "Run"),
diff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.ts
index 8ecf62369..dfd961a8d 100644
--- a/packages/i18n/src/locales/de/index.ts
+++ b/packages/i18n/src/locales/de/index.ts
@@ -627,6 +627,7 @@ export const de = {
"processCompletedFor": "Abgeschlossen in {{time}}",
"processStopped": "Gestoppt",
"processStoppedFor": "Gestoppt nach {{time}}",
+ "processUnsettled": "Ergebnis unbekannt",
"processFailed": "Fehlgeschlagen",
"processFailedFor": "Fehlgeschlagen nach {{time}}",
"waitingForModel": "Warten auf Modell",
diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.ts
index 54eb8cbf3..ddb984fe6 100644
--- a/packages/i18n/src/locales/en/index.ts
+++ b/packages/i18n/src/locales/en/index.ts
@@ -639,6 +639,7 @@ export const en = {
processCompletedFor: "Finished in {{time}}",
processStopped: "Stopped",
processStoppedFor: "Stopped after {{time}}",
+ processUnsettled: "Outcome unknown",
processFailed: "Failed",
processFailedFor: "Failed after {{time}}",
waitingForModel: "Waiting for model",
diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.ts
index 40c01094a..97f1dd827 100644
--- a/packages/i18n/src/locales/es/index.ts
+++ b/packages/i18n/src/locales/es/index.ts
@@ -627,6 +627,7 @@ export const es = {
"processCompletedFor": "Completado en {{time}}",
"processStopped": "Detenido",
"processStoppedFor": "Detenido tras {{time}}",
+ "processUnsettled": "Resultado desconocido",
"processFailed": "Fallido",
"processFailedFor": "Fallido tras {{time}}",
"waitingForModel": "Esperando modelo",
diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.ts
index 723e5ba26..f1287b0b5 100644
--- a/packages/i18n/src/locales/fr/index.ts
+++ b/packages/i18n/src/locales/fr/index.ts
@@ -627,6 +627,7 @@ export const fr = {
"processCompletedFor": "Terminé en {{time}}",
"processStopped": "Arrêté",
"processStoppedFor": "Arrêté après {{time}}",
+ "processUnsettled": "Résultat inconnu",
"processFailed": "Échec",
"processFailedFor": "Échec après {{time}}",
"waitingForModel": "En attente du modèle",
diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.ts
index fd95c8096..cfabc62b8 100644
--- a/packages/i18n/src/locales/ko/index.ts
+++ b/packages/i18n/src/locales/ko/index.ts
@@ -636,6 +636,7 @@ export const ko = {
processCompletedFor: "실행 완료, {{time}}",
processStopped: "중지됨",
processStoppedFor: "중지됨, {{time}}",
+ processUnsettled: "결과 미확인",
processFailed: "실패",
processFailedFor: "실패, {{time}}",
waitingForModel: "모델 대기 중",
diff --git a/packages/i18n/src/locales/pt-BR/index.ts b/packages/i18n/src/locales/pt-BR/index.ts
index 12a50fe18..695d84d1f 100644
--- a/packages/i18n/src/locales/pt-BR/index.ts
+++ b/packages/i18n/src/locales/pt-BR/index.ts
@@ -626,6 +626,7 @@ export const ptBR = {
processCompletedFor: "Concluído em {{time}}",
processStopped: "Interrompido",
processStoppedFor: "Interrompido após {{time}}",
+ processUnsettled: "Resultado desconhecido",
processFailed: "Falhou",
processFailedFor: "Falhou após {{time}}",
waitingForModel: "Aguardando o modelo…",
diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.ts
index 8f89672c7..6462404f1 100644
--- a/packages/i18n/src/locales/tr/index.ts
+++ b/packages/i18n/src/locales/tr/index.ts
@@ -636,6 +636,7 @@ export const tr = {
processCompletedFor: "{{time}} içinde tamamlandı",
processStopped: "Durduruldu",
processStoppedFor: "{{time}} sonra durduruldu",
+ processUnsettled: "Sonuç bilinmiyor",
processFailed: "Başarısız",
processFailedFor: "{{time}} sonra başarısız",
waitingForModel: "Model bekleniyor",
diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.ts
index b8602e172..032813aab 100644
--- a/packages/i18n/src/locales/zh-CN/index.ts
+++ b/packages/i18n/src/locales/zh-CN/index.ts
@@ -632,6 +632,7 @@ export const zhCN = {
processCompletedFor: "运行完成,{{time}}",
processStopped: "已停止",
processStoppedFor: "已停止,{{time}}",
+ processUnsettled: "结果未知",
processFailed: "失败",
processFailedFor: "失败,{{time}}",
waitingForModel: "等待模型响应",
diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.ts
index 9483adbce..1ef3a49ef 100644
--- a/packages/i18n/src/locales/zh-TW/index.ts
+++ b/packages/i18n/src/locales/zh-TW/index.ts
@@ -632,6 +632,7 @@ export const zhTW = {
processCompletedFor: "執行完成,{{time}}",
processStopped: "已停止",
processStoppedFor: "已停止,{{time}}",
+ processUnsettled: "結果未知",
processFailed: "失敗",
processFailedFor: "失敗,{{time}}",
waitingForModel: "等待模型響應",