Skip to content

The agent that grows with you

fix(desktop): backend exit lines carry the buffered output tail

Konstantin Khlopkove98d74513bd0
diff --git a/apps/desktop/electron/backend-claim.test.ts b/apps/desktop/electron/backend-claim.test.ts
index f3edd5f64e6..5efca30f765 100644
--- a/apps/desktop/electron/backend-claim.test.ts
+++ b/apps/desktop/electron/backend-claim.test.ts
@@ -7,6 +7,7 @@ import {
claimDecision,
createBackendOutputTail,
DEFAULT_OUTPUT_TAIL_LIMIT,
+ formatBackendExitLine,
isPidOnlyStartMarker,
pidOnlyStartMarker,
probeStartMarker,
@@ -133,3 +134,35 @@ test('attach tolerates a child with missing stdio streams', () => {
tail.attach({ stderr: null, stdout: null })
assert.equal(tail.text(), '')
})
+
+// --- formatBackendExitLine ---------------------------------------------------
+
+test('exit line carries the buffered tail next to the exit code', () => {
+ const tail = createBackendOutputTail(64)
+ tail.append('Traceback (most recent call last):\n')
+
+ const line = formatBackendExitLine('Ignoring stale Hermes backend exit', 1, null, tail)
+
+ assert.equal(line, 'Ignoring stale Hermes backend exit (1)\nRecent backend output:\nTraceback (most recent call last):')
+})
+
+test('exit line prefers the signal over the code, matching the old shape', () => {
+ const tail = createBackendOutputTail(64)
+ tail.append('bye\n')
+
+ const line = formatBackendExitLine('Hermes backend exited', 1, 'SIGTERM', tail)
+
+ assert.equal(line, 'Hermes backend exited (SIGTERM)\nRecent backend output:\nbye')
+})
+
+test('exit line stays byte-identical to the legacy shape when the tail is empty', () => {
+ const line = formatBackendExitLine('Hermes backend exited', 0, null, createBackendOutputTail(64))
+
+ assert.equal(line, 'Hermes backend exited (0)')
+})
+
+test('exit line tolerates a missing tail', () => {
+ const line = formatBackendExitLine('Hermes backend exited', 1, null, null)
+
+ assert.equal(line, 'Hermes backend exited (1)')
+})
diff --git a/apps/desktop/electron/backend-claim.ts b/apps/desktop/electron/backend-claim.ts
index a3542c72201..fb53d21f7a9 100644
--- a/apps/desktop/electron/backend-claim.ts
+++ b/apps/desktop/electron/backend-claim.ts
@@ -225,3 +225,20 @@ export function createBackendOutputTail(limit: number = DEFAULT_OUTPUT_TAIL_LIMI
}
}
}
+
+/**
+ * Exit line for a supervised backend child, carrying the buffered output tail
+ * so the reason the child died reaches desktop.log. Every exit surface uses
+ * this shape — including the "stale" classification, where the line is the
+ * only evidence left: the child is gone and nothing else will say why it
+ * exited. `signal` wins over `code` (null code on signal death and vice
+ * versa); an empty tail keeps the line exactly as it was before.
+ */
+export function formatBackendExitLine(
+ label: string,
+ code: number | null,
+ signal: string | null,
+ outputTail: BackendOutputTail | null
+): string {
+ return `${label} (${signal || code})${outputTail?.describe() ?? ''}`
+}
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index ca4ee1a03f3..35b5a132e14 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -50,6 +50,7 @@ import {
claimDecision,
createBackendOutputTail,
execText,
+ formatBackendExitLine,
isPidOnlyStartMarker,
pidOnlyStartMarker,
probeStartMarker,
@@ -12757,7 +12758,7 @@ async function runPoolBackendStart(profile, entry, opts: { forceLocal?: boolean;
rejectStart?.(error)
})
child.once('exit', (code, signal) => {
- rememberLog(`Hermes backend for profile "${profile}" exited (${signal || code})`)
+ rememberLog(formatBackendExitLine(`Hermes backend for profile "${profile}" exited`, code, signal, outputTail))
releaseLocalBackendSlot(entry)
releaseBackendChild(child)
@@ -13256,7 +13257,7 @@ async function runHermesStart() {
releaseBackendChild(hermesProcess)
if (!backendConnectionState.clearForCurrentProcess(processOwner)) {
- rememberLog(`Ignoring stale Hermes backend exit (${signal || code})`)
+ rememberLog(formatBackendExitLine('Ignoring stale Hermes backend exit', code, signal, primaryOutputTail))
if (!backendReady) {
rejectBackendStart?.(new Error('Hermes backend start was superseded by a newer connection attempt.'))
@@ -13265,7 +13266,7 @@ async function runHermesStart() {
return
}
- rememberLog(`Hermes backend exited (${signal || code})`)
+ rememberLog(formatBackendExitLine('Hermes backend exited', code, signal, primaryOutputTail))
sendBackendExit({ code, signal })
if (!backendReady) {