AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
console: a refused brains listing is a refusal, not "no brains" (#936)
xerj-org79e207e08178
diff --git a/xerj-ux/src/data/second-brain-api.js b/xerj-ux/src/data/second-brain-api.jsindex 5cf562e57..f62f3a0d0 100644--- a/xerj-ux/src/data/second-brain-api.js+++ b/xerj-ux/src/data/second-brain-api.js@@ -252,12 +252,19 @@ const enc = encodeURIComponent;* Brains = what the console's brains listing returns (the reserved* `.xerj-memory-{brain}-edges` indices this session's role may read,* each with its meta-doc `nodes_index`). An empty listing is a normal- * state (no brains / a role that may not read them), not an error; a- * transport failure is.+ * state (no brains), not an error; a transport failure is.+ *+ * A 401/403 listing is a REFUSAL, not "no brains": no session / a role+ * that may not read brains means the page cannot know whether brains+ * exist, and must say the read was refused — never teach `xerj brain`+ * over a refusal, and never let the status pill claim LIVE for a read+ * that did not run (liveSecondBrain's catch shapes this into the+ * refused envelope; ux/ego-ledger.js#EmptyBrainNote renders it).*/async function discoverBrains(_baseUrl, signal) {const r = await fetch(`${GRAPH}/brains`, { signal, credentials: 'same-origin', headers: { accept: 'application/json' } });- if (r.status === 401 || r.status === 403 || r.status === 404) return [];+ if (r.status === 401 || r.status === 403) throw new Error(`graph/brains HTTP ${r.status}`);+ if (r.status === 404) return []; // a console without the graph routes proves no brain either wayif (!r.ok) throw new Error(`graph/brains HTTP ${r.status}`);const j = await r.json();return (((j && j.data && j.data.brains) || [])diff --git a/xerj-ux/src/ux/ego-ledger.js b/xerj-ux/src/ux/ego-ledger.jsindex 30ca7a0e7..07c0156a0 100644--- a/xerj-ux/src/ux/ego-ledger.js+++ b/xerj-ux/src/ux/ego-ledger.js@@ -935,9 +935,9 @@ const BrainErrorNote = ({ brain, reason }) => `<button type="button" class="text-btn" data-sb-retry>RETRY</button></div>`;-/** A 401/403 from the brain list is a REFUSAL, not an outage: on an- * auth-enabled engine a console session cannot read `.xerj-memory-*`- * (issue #936). Say that, and point at the views that do work. */+/** A 401/403 from the console graph read path is a REFUSAL, not an+ * outage: no session, or a role that may not read brains (issue #936).+ * Say that, and point at the views that do work. */export const isRefusal = (error) => /HTTP 40[13]\b/.test(String(error || ''));/** A brand-new brain: the ONE command that fills it, copyable. */@@ -947,10 +947,10 @@ export const EmptyBrainNote = ({ brain, connected, error }) => {<div class="sb-empty"><div class="sb-ftitle">THE GRAPH API REFUSED THIS CONSOLE SESSION</div><div class="mono faint" style="margin:var(--sp-1) 0;">${esc(String(error).slice(0, 120))}</div>- <p class="sb-ftext">On an auth-enabled engine the brain views need an engine API key, and a- passkey session is not one (issue #936). Nothing here is a guess, so nothing is shown.- What was indexed is on CORPUS, and any record opens in the READER — those go through the- session and work. On a node started with <span class="mono">--insecure</span> this page works.</p>+ <p class="sb-ftext">The brain views read the graph through the console session, and this+ session was refused — there is none, or its role may not read brains (owner and admin+ may; issue #936). Nothing here is a guess, so nothing is shown. What was indexed is on+ CORPUS, and any record opens in the READER — those go through the session and work.</p><a class="text-btn" href="#/corpus">OPEN CORPUS</a></div>`;}diff --git a/xerj-ux/src/ux/reader-render.js b/xerj-ux/src/ux/reader-render.jsindex 688ce4431..aba73ad82 100644--- a/xerj-ux/src/ux/reader-render.js+++ b/xerj-ux/src/ux/reader-render.js@@ -432,7 +432,7 @@ export function renderGraphPanel(g = {}) {return h('div', { class: 'rd-empty' },g.guest? 'This share does not include the knowledge graph.'- : ['The graph API refused this console session (', mono(str(g.error) || 'HTTP 401'), '). On an auth-enabled engine the graph needs an engine API key; records and search still work.']);+ : ['The graph API refused this console session (', mono(str(g.error) || 'HTTP 401'), '). Brain reads need a session whose role may read brains; records and search still work.']);case 'error':return h('div', { class: 'rd-empty' }, 'Graph unavailable: ', mono(str(g.error) || 'unknown error'));case 'ok': {diff --git a/xerj-ux/test/browser/fake-engine.mjs b/xerj-ux/test/browser/fake-engine.mjsindex 904b5ab9b..e9b7d39ce 100644--- a/xerj-ux/test/browser/fake-engine.mjs+++ b/xerj-ux/test/browser/fake-engine.mjs@@ -96,9 +96,13 @@ export async function startFakeEngine() {operator: false,/** status overrides: { search, mapping, ego, proxySearch, all } → HTTP status */fail: {},- /** An `--insecure` node: the brain list, each brain's meta document and- * `ego` answer WITHOUT a key, so the operator's graph path can be driven.- * `brains` is the `_cat` order; only `inbox` holds edges for the fixtures. */+ /** The engine's graph posture toward THIS console session, exercised+ * through the console's graph read path (`/_xerj-console/api/v1/graph/…`,+ * issue #936): `openGraph` true = the session may read the graph (the+ * operator tier on an `--insecure` node); false = every graph read is+ * refused (401) — the auth-enabled posture that used to 401 the old+ * keyless `_cat` probe. `brains` is the listing order; only `inbox`+ * holds edges for the fixtures. */openGraph: false,brains: ['inbox'],/** claim this many attachment records exist (0 = the truth) */@@ -169,21 +173,23 @@ export async function startFakeEngine() {send(200, searchResponse(body, state));return;}- send(404, { error: { code: 'not_found', message: p } });- return;- }-- // ---- the graph without a key (an `--insecure` node), when a test asks --- if (state.openGraph && !auth) {- if (path === '/_cat/indices/.xerj-memory-*') {- res.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' });- res.end(state.brains.map((b) => `green open .xerj-memory-${b}-edges u1 1 0 1 0 1kb 1kb 1kb`).join('\n'));+ // ---- the console's graph read path (a session, never a key) --------+ // Brain discovery + the reader panel's ego walk, as+ // xerj-console-api/src/graph.rs serves them. `state.openGraph` is the+ // engine's posture: readable, or a flat refusal to this session.+ if (p === '/graph/brains') {+ if (!state.openGraph) { send(401, { error: { code: 'unauthorized', message: 'the engine refused this console session' } }); return; }+ send(200, { data: { brains: state.brains.map((b) => ({ name: b, nodes_index: 'ax-inbox' })), total: state.brains.length } });return;}- const bm = path.match(/^\/\.xerj-memory-([^/]+)-edges\/_doc\/__xerj-brain-meta$/);- if (bm) { send(state.brains.includes(bm[1]) ? 200 : 404, { _index: `.xerj-memory-${bm[1]}-edges`, _id: '__xerj-brain-meta', found: true, _source: { nodes_index: 'ax-inbox' } }); return; }- const gm = path.match(/^\/_graph\/([^/]+)\/ego$/);- if (gm) { send(200, gm[1] === 'inbox' ? hostileEgo : { node: url.searchParams.get('node'), edges: [], nodes: {}, not_shown: {} }); return; }+ const gm = p.match(/^\/graph\/([^/]+)\/ego$/);+ if (gm) {+ if (!state.openGraph) { send(401, { error: { code: 'unauthorized', message: 'the engine refused this console session' } }); return; }+ send(200, gm[1] === 'inbox' ? hostileEgo : { node: url.searchParams.get('node'), edges: [], nodes: {}, not_shown: {} });+ return;+ }+ send(404, { error: { code: 'not_found', message: p } });+ return;}// ---- data plane (API key) --------------------------------------------diff --git a/xerj-ux/test/browser/reader-xss.test.mjs b/xerj-ux/test/browser/reader-xss.test.mjsindex baee5392c..ba2f7f358 100644--- a/xerj-ux/test/browser/reader-xss.test.mjs+++ b/xerj-ux/test/browser/reader-xss.test.mjs@@ -176,10 +176,11 @@ test('operator reader: changing the query type runs the text in the box, not the});test('the link `xerj brain` prints (#/second-brain?brain=…) opens the Second Brain view even when the brains probe is refused — never a SAMPLE DATA dashboard', { skip }, async () => {- // On an auth-enabled engine `GET /_cat/indices/.xerj-memory-*` answers 401- // to a console session (this fake does the same without a key), so the- // Second Brain dashboard is "gated". The printed link is explicit and must- // resolve to it (PR #945 review: it fell through to System's host metrics).+ // On an engine that refuses graph reads to this console session the brains+ // listing `/_xerj-console/api/v1/graph/brains` answers 401 (this fake does+ // so unless a test opens the graph), so the Second Brain dashboard is+ // "gated". The printed link is explicit and must resolve to it (PR #945+ // review: it fell through to System's host metrics).const page = await openOperator(ctx, '#/second-brain?brain=inbox');await page.waitFor(`document.getElementById('app')?.getAttribute('aria-busy') === 'false' && !!document.querySelector('h1.h-scene')`, { label: 'the routed view' });await new Promise((r) => setTimeout(r, 300));@@ -201,9 +202,11 @@ test('the link `xerj brain` prints (#/second-brain?brain=…) opens the Second Btest('operator graph panel: two brains over one index — the links come from the brain that has them, and the panel names both', { skip }, async () => {// PR #945 review: `xerj brain casefile` + `xerj brain vendors` on one node →- // two brains list ax-docs; the panel walked the first `_cat` listed and said- // "no links" for the other brain's records. `other` is listed first here and- // holds nothing for the fixtures; `inbox` holds the hostile ego.+ // two brains list ax-docs; the panel walked the first brain the listing+ // returned and said "no links" for the other brain's records. `other` is+ // listed first here and holds nothing for the fixtures; `inbox` holds the+ // hostile ego. The walk rides the console's session-authorized graph read+ // path (issue #936), not the data plane.ctx.engine.state.openGraph = true;ctx.engine.state.brains = ['other', 'inbox'];ctx.engine.state.log.length = 0;@@ -216,8 +219,8 @@ test('operator graph panel: two brains over one index — the links come from thassert.match(g.text, /3 linked records · brains other, inbox consulted · links in inbox · 1 hop/);const hrefs = await page.eval(`[...document.querySelectorAll('.rd-neigh')].map((a) => a.getAttribute('href'))`);assert.ok(hrefs.length === 3 && hrefs.every((h) => h.includes('brain=inbox')), `each neighbour links into the brain its link came from: ${hrefs}`);- const asked = ctx.engine.state.log.filter((r) => /^\/_graph\/[^/]+\/ego$/.test(r.path)).map((r) => r.path);- assert.deepEqual([...new Set(asked)], ['/_graph/other/ego', '/_graph/inbox/ego'], 'both candidates were asked');+ const asked = ctx.engine.state.log.filter((r) => /^\/_xerj-console\/api\/v1\/graph\/[^/]+\/ego$/.test(r.path)).map((r) => r.path);+ assert.deepEqual([...new Set(asked)], ['/_xerj-console/api/v1/graph/other/ego', '/_xerj-console/api/v1/graph/inbox/ego'], 'both candidates were asked, through the console session');// an explicit hint walks that brain aloneawait page.setHash(`${readerHash(HOSTILE_ID)}&brain=other`);await page.waitFor(`/Brain other records no links/.test(document.querySelector('.rd-graph').textContent)`, { label: 'the hint alone' });