Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,17 @@ <h1>agentmemory</h1>
if (!res.ok) {
if (res.status === 401) showViewerAuthPrompt();
console.warn('[viewer] API ' + (fetchOpts.method || 'GET') + ' ' + path + ' returned ' + res.status);
return null;
// Some endpoints (e.g. health) intentionally respond with a non-2xx
// status while still returning a valid JSON body describing the
// degraded state (see #1019). Surface that body instead of
// discarding it as null, which used to make a "critical" health
// response render as "unknown".
try {
return await res.json();
} catch (parseErr) {
console.debug('[viewer] API ' + path + ' non-2xx body was not JSON:', parseErr);
return null;
}
Comment on lines +1256 to +1261

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find callers that check for null returns from api/apiGet/apiPost
rg -n '=== null|== null|!== null|!= null' src/viewer/index.html -B2 -A2 | head -80

Repository: rohitg00/agentmemory

Length of output: 2650


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== api helper and nearby callers =="
sed -n '1180,1715p' src/viewer/index.html | cat -n | sed -n '1,560p'

echo
echo "== search for api() callers and null checks =="
rg -n 'apiGet\(|apiPost\(|api\(' src/viewer/index.html -A3 -B3
rg -n '=== null|== null|!== null|!= null' src/viewer/index.html -A2 -B2

echo
echo "== server endpoints that may return non-2xx =="
rg -n 'unauthorized|res\.status|statusCode|json\(|text/plain|graph/query|health' src -A3 -B3

Repository: rohitg00/agentmemory

Length of output: 50376


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== graph/query handler =="
rg -n 'graph/query|queryGraph|/graph/query|status\s*[:=].*500|res\.status\(|throw .*graph|return .*graph' src -A6 -B6

echo
echo "== health handler =="
rg -n 'health|/health|status\s*[:=].*critical|degraded|res\.status\(|res\.json\(|res\.send\(' src -A6 -B6

echo
echo "== viewer callers that treat null specially =="
rg -n 'if \([^)]*=== null\)|if \([^)]*!== null\)|\|\| \[\]' src/viewer/index.html -A2 -B2 | sed -n '1,120p'

Repository: rohitg00/agentmemory

Length of output: 50376


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== graphDisabledResponse and graph/query shapes =="
sed -n '1,220p' src/triggers/api.ts | cat -n | sed -n '1,220p'
echo
sed -n '620,760p' src/functions/graph.ts | cat -n | sed -n '1,220p'

echo
echo "== any explicit non-2xx JSON responses relevant to viewer =="
rg -n 'status_code:\s*(4|5)\d\d|status_code:\s*503|graphDisabledResponse|body:\s*\{' src/triggers/api.ts src/functions/graph.ts -A4 -B4

Repository: rohitg00/agentmemory

Length of output: 50376


Preserve the null-on-HTTP-error contract here.

api() now parses JSON for non-2xx responses, so graphDisabledResponse() and other 503 bodies will reach this branch as objects instead of null. loadGraph() will treat HTTP failures as empty data and skip the error banner/rebuild path. Keep non-2xx as null, or return status alongside the body and check it here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/viewer/index.html` around lines 1256 - 1260, Ensure api() preserves the
null-on-HTTP-error contract: after parsing the response, return null for non-2xx
statuses so graphDisabledResponse() and loadGraph() trigger their existing error
handling; keep parsed JSON only for successful responses, while retaining the
parse-error fallback.

}
hideViewerAuthPrompt();
return await res.json();
Expand Down