Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

fix(ux): a superseded console render never paints over the newer route (#1425)

xerj-org0cd1c1ff35dc
diff --git a/xerj-ux/src/app.js b/xerj-ux/src/app.js
index 95814dc1c..19cebd886 100644
--- a/xerj-ux/src/app.js
+++ b/xerj-ux/src/app.js
@@ -972,7 +972,20 @@ function renderBuilder() {
</div>`;
}
+// render() is async (it awaits the route's data) and is called from many
+// places — boot, hashchange, the live-feature probe, the dashboard store,
+// per-panel settles — with nothing serialising them. Without a guard the
+// LAST render to finish wins, not the last one STARTED: a slow #/corpus fetch
+// begun just before a route change resolves after the new route has painted
+// and paints the old view (and its LIVE pill) back over it, with no further
+// render to correct it (issue #1425). Each render takes a generation number;
+// after every await, a render that has been superseded stops without touching
+// state or the DOM — the newer render owns both.
+let renderGen = 0;
+
async function render() {
+ const gen = ++renderGen;
+ const superseded = () => gen !== renderGen;
const app = document.getElementById('app');
// Resolve the active dashboard from either the default registry or
// the user metadata store. User-cloned dashboards inherit their
@@ -1043,11 +1056,13 @@ async function render() {
} else if (state.section === 'data' || state.section === 'settings') {
try {
data = await buildSectionData(state.section);
+ if (superseded()) return;
// DATA is built from the live index inventory (_cat/indices); SETTINGS is
// local browser state. Label the pill honestly for each.
state.sourceLabel = state.section === 'settings' ? 'LOCAL · SETTINGS' : 'LIVE · XERJ · INDEX INVENTORY';
state.sourceKind = state.section === 'settings' ? 'local' : 'live';
} catch (err) {
+ if (superseded()) return;
data = {};
fetchErr = err;
// Surface the failure in the pill instead of leaving the prior view's
@@ -1066,6 +1081,7 @@ async function render() {
cluster: state.cluster,
filters: activeFilters,
});
+ if (superseded()) return;
data = result.data;
if (dash.id === 'corpus') state.corpus = data;
state.fetchedAt = result.meta.fetchedAt;
@@ -1081,10 +1097,12 @@ async function render() {
}
state.fetchErr = null;
} catch (err) {
+ if (superseded()) return;
state.fetchErr = err.message || String(err);
fetchErr = err;
} finally {
- state.loading = false;
+ // The newer render set loading=true for its own pending fetch; leave it.
+ if (!superseded()) state.loading = false;
}
if (fetchErr) {
app.innerHTML = `
diff --git a/xerj-ux/test/browser/fake-engine.mjs b/xerj-ux/test/browser/fake-engine.mjs
index e9b7d39ce..4714257a5 100644
--- a/xerj-ux/test/browser/fake-engine.mjs
+++ b/xerj-ux/test/browser/fake-engine.mjs
@@ -109,6 +109,9 @@ export async function startFakeEngine() {
attachmentRecords: 0,
/** claim this many search results exist (0 = the truth) */
searchTotal: 0,
+ /** delay (ms) on the corpus home's catalog/index reads — a slow #/corpus
+ * render still in flight when the route changes (issue #1425) */
+ slowCorpus: 0,
};
const server = createServer(async (req, res) => {
@@ -122,6 +125,7 @@ export async function startFakeEngine() {
let body = null;
try { body = raw ? JSON.parse(raw) : null; } catch { body = null; }
entry.body = body;
+ if (state.slowCorpus && /catalog|_cat|knowledge/.test(path)) await new Promise((r) => setTimeout(r, state.slowCorpus));
const send = (status, payload, headers = {}) => {
const text = typeof payload === 'string' ? payload : JSON.stringify(payload);
diff --git a/xerj-ux/test/browser/reader-xss.test.mjs b/xerj-ux/test/browser/reader-xss.test.mjs
index b32176a3b..1b8745f55 100644
--- a/xerj-ux/test/browser/reader-xss.test.mjs
+++ b/xerj-ux/test/browser/reader-xss.test.mjs
@@ -268,6 +268,33 @@ test('operator Discover: hostile hits, facet values and FIELD NAMES stay text',
await page.close();
});
+test('a slow render of the previous route never paints over the route the operator moved to (#1425)', { skip }, async () => {
+ // render() is async and nothing serialised it: a #/corpus render whose
+ // fetches were still in flight when the hash changed finished LAST and
+ // painted corpus (and its LIVE pill) back over the new route, for good.
+ const page = await openOperator(ctx, '#/corpus');
+ await page.waitFor(`/^LIVE/.test(document.querySelector('[data-nav-status]')?.textContent || '')`, { label: 'corpus booted' });
+ const seen = () => page.eval(`({ pill: document.querySelector('[data-nav-status]')?.textContent || '', main: document.querySelector('main.canvas')?.getAttribute('aria-label') || '' })`);
+ ctx.engine.state.slowCorpus = 300; // per catalog/index read; the corpus home makes several in sequence
+ try {
+ await page.setHash('#/corpus?slow=1'); // a corpus render, now slow
+ await sleep(50);
+ await page.setHash('#/dashboards/ai-overview'); // moved on before it lands
+ await page.waitFor(`/MOCK FALLBACK|SAMPLE DATA/.test(document.querySelector('[data-nav-status]')?.textContent || '')`, { label: 'ai-overview painted' });
+ // Wait out every delayed read of the abandoned corpus render (and then some).
+ const t0 = Date.now();
+ while (Date.now() - t0 < 4000) {
+ const now = await seen();
+ assert.match(now.pill, /MOCK FALLBACK|SAMPLE DATA/, `the stale corpus render repainted its pill: ${now.pill}`);
+ assert.doesNotMatch(now.main, /corpus/i, `the stale corpus render repainted its view: ${now.main}`);
+ await sleep(100);
+ }
+ } finally {
+ ctx.engine.state.slowCorpus = 0;
+ }
+ await page.close();
+});
+
test('the whole operator console runs under the shipped policy with zero violations', { skip }, async () => {
// The policy is new; the console is not. Every section the operator can
// reach has to keep working under `script-src 'self'; connect-src 'self'`,