Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(view): a failed read keeps the chosen board, read again [N26,A2]

Corey Olson344e599ad324
diff --git a/src/cockpit.js b/src/cockpit.js
index 90d7eb93..969aa8cb 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -242,7 +242,7 @@ ${pageScriptPart2(pageScope)}function syncBoardMode(root) {
document.body.classList.toggle('requests', requests);
}
-${pageScriptPart3(pageScope)}async function refresh(fresh = null) {
+${pageScriptPart3(pageScope)}async function refresh(fresh = null, attempt = 1) {
const generation = ++refreshStarted;
const root = view.root;
const mark = root ? view.seen['pb.seen.' + root] ?? keep('pb.seen.' + root) : null;
@@ -258,6 +258,13 @@ ${pageScriptPart3(pageScope)}async function refresh(fresh = null) {
// Only a read of every board can say the shown project is gone and choose another. A catch-up that could not read
// the shown board, as while the view restarts, failed; it keeps the board and the page says it is offline.
if (fresh && !next.project && !next.group) throw new Error('the board did not answer; is pullboard view still running?');
+ // The shown board is listed but its read failed, as one dropped under load: read it again rather than hand the page
+ // to another board; only a board gone from the list does that (#889).
+ const failed = !next.project && !next.group && next.projects.find((p) => p.root === root && !p.ok);
+ if (failed) {
+ if (attempt < 3) { await new Promise((later) => { setTimeout(later, 300 * attempt); }); return refresh(fresh, attempt + 1); }
+ throw new Error(failed.error);
+ }
refreshDrawn = { generation, full: !fresh };
if (!next.project && !next.group && next.projects.some((p) => p.ok)) {
view.root = next.projects.find((p) => p.ok).root;
diff --git a/test/cockpit/local-origin.test.js b/test/cockpit/local-origin.test.js
index f60787ac..264c90eb 100644
--- a/test/cockpit/local-origin.test.js
+++ b/test/cockpit/local-origin.test.js
@@ -480,11 +480,25 @@ export async function createTransport() { return { async request(path) {
await open(VERSION, true);
await chrome.waitFor("Boolean(transport) && [...boardSources.values()].map((source) => source.kind).sort().join() === 'local,relay' && document.querySelectorAll('#proj-list .proj.repo').length === 2", 25_000); // budget: hang ceiling for the relay module and its board list after the local read; no throughput claim.
const roots = JSON.parse(await chrome.stable("JSON.stringify(Object.fromEntries([...boardSources.values()].map((source) => [source.kind, source.board.root])))"));
- // A failed wait names the root the page reported next to the one it expected, so a spelling mismatch shows (#937).
+ // The page's own record of its last switch and its last reads, for the readiness capture (#889).
+ await chrome.stable(`(() => {
+ const read = api, pick = switchTo;
+ window.__journal = { switchedTo: null, reads: [] };
+ api = async (path, ...rest) => {
+ const entry = { path: String(path).split('?')[0], outcome: 'pending' };
+ window.__journal.reads = [...window.__journal.reads, entry].slice(-6);
+ try { const reply = await read(path, ...rest); entry.outcome = 'ok'; return reply; }
+ catch (error) { entry.outcome = 'failed: ' + String(error.message || error).slice(0, 80); throw error; }
+ };
+ switchTo = (root, ...rest) => { window.__journal.switchedTo = root; return pick(root, ...rest); };
+ return true;
+ })()`);
+ // A failed wait names the selected root, the sources, the last switch and the last reads, next to the root it
+ // expected, so a spelling mismatch, a dropped switch, a late read or a lost read shows which it was (#937, #889).
const selected = async (root) => {
try { await chrome.waitFor(`data?.project?.root === ${JSON.stringify(root)} && document.querySelector('#chain')?.textContent.length > 0`, 25_000); } // budget: hang ceiling for one board switch and its state read; no throughput claim.
catch (error) {
- const reported = await chrome.stable('JSON.stringify(data?.project?.root ?? null)').catch(() => 'unreadable');
+ const reported = await chrome.stable(`JSON.stringify({ selected: data?.project?.root ?? null, viewRoot: view.root, sources: [...boardSources.values()].map((source) => source.kind + ':' + source.board.root), ...window.__journal })`).catch(() => 'unreadable');
throw new Error(`${error.message}; the page reported ${reported}, expected ${JSON.stringify(root)}`);
}
};
@@ -501,6 +515,22 @@ export async function createTransport() { return { async request(path) {
await chrome.stable(`(switchTo(${JSON.stringify(roots.local)}), true)`);
await selected(roots.local);
assert.equal(await bannerHidden(), false, 'back on this machine\'s board, the note returns');
+ // A read of the chosen board that fails once, as one dropped under load, is read again: the page stays on the
+ // board the person chose instead of moving to the other one (#889).
+ await chrome.stable(`(switchTo(${JSON.stringify(roots.relay)}), true)`);
+ await selected(roots.relay);
+ await chrome.stable(`(() => {
+ const localId = [...boardSources.values()].find((source) => source.kind === 'local').board.id, read = api;
+ let armed = true;
+ api = async (path, ...rest) => {
+ if (armed && String(path).startsWith('/api/v1/boards/' + encodeURIComponent(localId) + '/state')) { armed = false; throw new Error('a dropped read'); }
+ return read(path, ...rest);
+ };
+ return true;
+ })()`);
+ await chrome.stable(`(switchTo(${JSON.stringify(roots.local)}), true)`);
+ await selected(roots.local);
+ assert.equal(await chrome.stable('view.root'), roots.local, 'the page keeps the board the person chose after one failed read');
assert.equal(await bannerText(), mixedNote);
} finally {
local.client = null;