From f619bcaf3f4afe6b378c207f69f09e9fe6e4c2f2 Mon Sep 17 00:00:00 2001 From: repo-worker-code-g Date: Sat, 7 Nov 2026 10:34:20 -0600 Subject: [PATCH] codedb-bridge: null/non-object daemon body is an isError result, not a hang or a null success (#6917) --- bin/codedb-bridge.mjs | 10 ++++++++++ bin/codedb-bridge.test.mjs | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/bin/codedb-bridge.mjs b/bin/codedb-bridge.mjs index 4c18636c55..2987843b76 100644 --- a/bin/codedb-bridge.mjs +++ b/bin/codedb-bridge.mjs @@ -233,6 +233,16 @@ export const createHandler = ({ fetchFn, daemonUrl }) => { if (!res.ok || data?.error) { return textResult(`codedb daemon error for ${name}: ${data?.error ?? `HTTP ${res.status}`}`, true); } + // A 200 body that is null or not a JSON object is a daemon malfunction, + // not a result (#6917): the tree path dereferences data.tree (a raw + // TypeError escapes handle() and the caller never gets a response), + // and the JSON paths would report the literal text "null" as success. + if (!data || typeof data !== 'object' || Array.isArray(data)) { + return textResult( + `codedb daemon at ${daemonUrl} returned a ${data === null ? 'null' : Array.isArray(data) ? 'array' : typeof data} JSON body for ${mapped.route}; expected a JSON object`, + true + ); + } try { data = sliceData(data, mapped.slice); } catch (err) { diff --git a/bin/codedb-bridge.test.mjs b/bin/codedb-bridge.test.mjs index f7cb6bcaff..c4cbd12593 100644 --- a/bin/codedb-bridge.test.mjs +++ b/bin/codedb-bridge.test.mjs @@ -260,3 +260,27 @@ test('daemon errors and an unreachable daemon surface as MCP errors naming the c assert.equal(badArg.result.isError, true); assert.match(badArg.result.content[0].text, /"regex"/); }); + +test('null or non-object daemon bodies are isError results, never a throw or a "null" success (#6917)', async () => { + const handle = createHandler({ + fetchFn: stubFetch({ + '/explore/tree': null, + '/explore/search?q=x': null, + '/explore/outline?path=a.ts': 'weird', + '/explore/hot': [1, 2], + }), + daemonUrl: 'http://127.0.0.1:7719', + }); + const tree = await call(handle, 'codedb_tree', {}); + assert.equal(tree.result.isError, true); + assert.match(tree.result.content[0].text, /null JSON body for \/explore\/tree/); + const search = await call(handle, 'codedb_search', { query: 'x' }); + assert.equal(search.result.isError, true); + assert.match(search.result.content[0].text, /null JSON body/); + const outline = await call(handle, 'codedb_outline', { path: 'a.ts' }); + assert.equal(outline.result.isError, true); + assert.match(outline.result.content[0].text, /string JSON body/); + const hot = await call(handle, 'codedb_hot', {}); + assert.equal(hot.result.isError, true); + assert.match(hot.result.content[0].text, /array JSON body/); +});