From dd4084e564df21ce56f73b8d7fc6dca527d28bd6 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Fri, 23 Oct 2026 13:00:26 -0500 Subject: [PATCH] fix(muse-proxy): name the killing signal in empty-stderr failure detail (#674) Signal-killed runs (OOM SIGKILL, SIGTERM) reported 'muse exec exited with code null' because the close handler ignored its signal argument. The empty-stderr fallback now names the signal when there is no non-completed terminal state. Adds FAILSTATE and SIGKILLME stub modes pinning both empty-stderr fallback branches (terminal state and signal) in stream and non-stream modes; each branch's ablation fails exactly its own new test. --- bin/muse-proxy.mjs | 4 +++- bin/muse-proxy.test.mjs | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/bin/muse-proxy.mjs b/bin/muse-proxy.mjs index f25d83701d..1a0531c726 100644 --- a/bin/muse-proxy.mjs +++ b/bin/muse-proxy.mjs @@ -406,7 +406,9 @@ const server = http.createServer((req, res) => { const stderrLine = stderrTail.trim().split('\n').pop(); const fallback = terminalState && terminalState !== 'completed' ? `muse run terminated with state '${terminalState}'` - : `muse exec exited with code ${code}`; + : signal + ? `muse exec terminated by signal ${signal}` + : `muse exec exited with code ${code}`; const detail = (stderrLine || fallback).trim(); const errorBody = { error: { message: `Muse execution failed: ${detail}` } }; if (stream) { diff --git a/bin/muse-proxy.test.mjs b/bin/muse-proxy.test.mjs index 500801eb87..b19bf41322 100644 --- a/bin/muse-proxy.test.mjs +++ b/bin/muse-proxy.test.mjs @@ -40,6 +40,13 @@ if grep -q CRASHPARTIAL "$prompt" 2>/dev/null; then echo "stub muse: crashed midway" >&2 exit 3 fi +if grep -q FAILSTATE "$prompt" 2>/dev/null; then + printf '%s\\n' '{"payload_type":"run.terminal.failed","payload":{"terminal":"failed"}}' + exit 0 +fi +if grep -q SIGKILLME "$prompt" 2>/dev/null; then + kill -9 $$ +fi if grep -q DIVERGE "$prompt" 2>/dev/null; then printf '%s\\n' '{"payload_type":"run.output.delta","payload":{"text":"abc"}}' printf '%s\\n' '{"payload_type":"run.terminal.completed","payload":{"terminal":"completed","text":"xyz-longer"}}' @@ -190,6 +197,48 @@ test('partial output then failure: masked success becomes an error in both modes } }); +const assertEmptyStderrFallback = async (t, marker, detail) => { + const { port, stop } = await startProxy(); + t.after(stop); + + { + const messages = [{ role: 'user', content: `please ${marker} now` }]; + + const plainRes = await fetch(`http://127.0.0.1:${port}/v1/chat/completions`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ messages }) + }); + assert.equal(plainRes.status, 500, `${marker}: non-stream must be a 500`); + const plainBody = JSON.parse(await plainRes.text()); + assert.match(plainBody.error.message, detail, `${marker}: non-stream detail must name the cause, got: ${plainBody.error.message}`); + assert.doesNotMatch(plainBody.error.message, /code (null|0)\b/); + + const streamRes = await fetch(`http://127.0.0.1:${port}/v1/chat/completions`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ messages, stream: true }) + }); + assert.equal(streamRes.status, 200); + const sse = await streamRes.text(); + const dataLines = sse.split('\n').filter(l => l.startsWith('data: ')); + assert.equal(dataLines[dataLines.length - 1], 'data: [DONE]', `${marker}: stream must end with [DONE]`); + const events = dataLines.slice(0, -1).map(l => JSON.parse(l.slice('data: '.length))); + const errorEvent = events.find(e => e.error); + assert.ok(errorEvent, `${marker}: stream must carry an error event, got: ${JSON.stringify(sse)}`); + assert.match(errorEvent.error.message, detail, `${marker}: stream detail must name the cause, got: ${errorEvent.error.message}`); + assert.doesNotMatch(errorEvent.error.message, /code (null|0)\b/); + } +}; + +test('empty-stderr fallback names the terminal state (#674)', async (t) => { + await assertEmptyStderrFallback(t, 'FAILSTATE', /Muse execution failed: muse run terminated with state 'failed'/); +}); + +test('empty-stderr fallback names the killing signal, not code null (#674)', async (t) => { + await assertEmptyStderrFallback(t, 'SIGKILLME', /Muse execution failed: muse exec terminated by signal SIGKILL/); +}); + test('divergent terminal text: non-stream uses it, stream keeps the deltas already sent', async (t) => { const { port, stop } = await startProxy(); t.after(stop);