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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(view): hosted page settles reads, acts on its move [N26,H5,C7]
Corey Olson6d9d28d5bf94
diff --git a/src/cockpit.js b/src/cockpit.jsindex 87a8c86b..7a032652 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -961,6 +961,16 @@ async function jsonRequest(path, body, base, headers, cache) {return json;}+/**+ * Whether the signed-in person's linked boards name one this machine's list lacks: only then does the page need the+ * decrypting relay client. The metadata is a same-origin cookie-authenticated read, with none of this machine's local+ * credential.+ */+async function linkedBoardMissing(localIds) {+ const linked = await jsonRequest('/api/v1/boards', undefined, '', {}, 'no-store');+ return Boolean(linked.boards?.some(board => typeof board.id === 'string' && /^[0-9a-f]{32}$/.test(board.id) && typeof board.repository === 'string' && !localIds.has(board.id)));+}+/** Read this machine's API list and the signed-in relay list, preferring a local registration with the same id. */async function listedBoards() {let local = { boards: [], warnings: [] };@@ -970,8 +980,10 @@ async function listedBoards() {try {local = await jsonRequest('/api/v1/boards', undefined, localReadBase, localReadHeaders, 'no-store');} catch (error) {+ // A local read that fails once, as while the view restarts, is no reason to load the relay client for a+ // person whose linked boards are all on this machine or who has none (#748).if (!transport && hosted.relaySession && configuredTransportModule) {- try { await loadTransport(); } catch { /* Keep the local refusal when neither source can be read. */ }+ try { if (await linkedBoardMissing(new Set())) await loadTransport(); } catch { /* Keep the local refusal when neither source can be read. */ }}if (!transport) throw error;localNote(String(error.message || error), true);@@ -979,11 +991,7 @@ async function listedBoards() {}if (hosted.local && hasLocal && hosted.relaySession && configuredTransportModule && !transport) {try {- // Metadata is a same-origin cookie-authenticated read, with none of this machine's local credential.- // Loading the decrypting client is needed only for a linked board absent from the local list.- const linked = await jsonRequest('/api/v1/boards', undefined, '', {}, 'no-store');- const localIds = new Set((local.boards || []).map(board => board.id));- if (linked.boards?.some(board => typeof board.id === 'string' && /^[0-9a-f]{32}$/.test(board.id) && typeof board.repository === 'string' && !localIds.has(board.id))) await loadTransport();+ if (await linkedBoardMissing(new Set((local.boards || []).map(board => board.id)))) await loadTransport();} catch (error) { localNote('Linked boards are unavailable: ' + String(error.message || error), true); }}if (!hasLocal && transportModule && !transport) throw transportLoadError || new Error('The browser transport is still loading.');@@ -3019,7 +3027,11 @@ async function decideRow(kind, command, args, anchor) {return requestMode ? Boolean(feedback.requestId) && feedback.status !== 'refused' : feedback.tone === 'ok';}-/** Run a public API move beside its action and let only the latest one own the console and timer. */+/**+ * Run a public API move beside its action and let only the latest one own the console and timer. The move's own+ * reply is its outcome (#748): the board is read again afterwards, but that read covers every source on a hosted+ * page, and a slow or failing read of another board must neither hold back nor undo a move that went through.+ */async function act(command, args, anchor) {const out = $('console');if (snapshot || (readOnly && !requests)) { out.hidden = false; out.className = 'console no'; out.textContent = snapshot ? 'This is a read-only snapshot.' : 'This is a read-only view.'; return false; }@@ -3057,8 +3069,8 @@ async function act(command, args, anchor) {// What went through says so and then steps aside; a refusal stays until the person closes it.if (!requestMode || request.status === 'done') view.closing = setTimeout(() => { if (latest()) out.hidden = true; }, 6000);}- await refresh();// The result was already revealed. A late refresh must not scroll after the person aims at the next action.+ refresh().catch((error) => { $('live').textContent = 'offline: ' + String(error.message || error); });return !requestMode || request.status !== 'refused';} catch (error) {if (latest()) {diff --git a/test/cockpit/local-origin.test.js b/test/cockpit/local-origin.test.jsindex 17053e8a..09feadf4 100644--- a/test/cockpit/local-origin.test.js+++ b/test/cockpit/local-origin.test.js@@ -239,7 +239,26 @@ test('a pullboard.dev page reads the local board [N26,A2]', { timeout: 120_000 }assert.ok(metadata.length > 0, 'the signed-in page checked its linked-board metadata');assert.ok(metadata.every((entry) => !Object.keys(entry.headers).some((name) => name.toLowerCase() === 'x-pullboard-key')), 'same-origin metadata never gets the local secret header');assert.equal(await chrome.stable('readOnly'), false, 'the local board remains writable');- assert.deepEqual(chrome.exceptions, [], 'Chrome reports no uncaught exceptions');+ // A local read that fails once, as while the view restarts or is busy, is no reason to load the relay module+ // either: this person's linked list is empty, so the page reads the view again instead (#748).+ const { identifier: failOnce } = await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: `(() => {+ if (location.origin !== ${JSON.stringify(HOSTED)} || sessionStorage.getItem('pullboard.test.fail-local-list') !== '1') return;+ sessionStorage.removeItem('pullboard.test.fail-local-list');+ const nextFetch = window.fetch;+ window.fetch = (input, init) => {+ if (!window.__localListFailed && String(typeof input === 'string' ? input : input.url) === ${JSON.stringify(view.base + '/api/v1/boards')}) {+ window.__localListFailed = true;+ return Promise.reject(new TypeError('Failed to fetch'));+ }+ return nextFetch(input, init);+ };+ })()` });+ assert.equal(await chrome.stable("(() => { sessionStorage.setItem('pullboard.test.fail-local-list', '1'); return true; })()"), true, 'the next load meets one failed local read');+ await chrome.send('Page.navigate', { url: HOSTED + '/?relay' });+ await chrome.waitFor("location.search === '?relay' && window.__localListFailed === true && document.querySelector('#chain')?.textContent.includes('A board that stays on this machine')", 20_000); // budget: hang ceiling for one failed read and the next timed refresh.+ await chrome.send('Page.removeScriptToEvaluateOnNewDocument', { identifier: failOnce });+ assert.equal(relayModule(), modulesBefore, 'a failed local read on a local-only signed-in page does not request the relay module');+ assert.equal(await chrome.stable('transportModule'), null, 'and the relay transport stays unloaded');} finally {try { if (stopStandIn) await stopStandIn(); }finally {diff --git a/test/cockpit/relay.test.js b/test/cockpit/relay.test.jsindex 8fa1d52d..e2b9419e 100644--- a/test/cockpit/relay.test.js+++ b/test/cockpit/relay.test.js@@ -1316,21 +1316,52 @@ async function interceptJourneyOrigins(chrome, site, view, { deadline: currentDe};chrome.socket.addEventListener('message', listener);chrome.socket.addEventListener('message', networkListener);+ // Chrome drops a paused request when its document is replaced, and reports no Network.loadingFailed for it (#748),+ // so a read still in flight as the fixture navigates away would be stranded unaccounted. Each hosted document+ // counts its own finite reads and can close to new ones; live streams are continued at once and stay open.+ const { identifier: fetchGate } = await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: `(() => {+ if (location.origin !== ${JSON.stringify(JOURNEY_HOSTED)}) return;+ const nativeFetch = window.fetch.bind(window);+ const gate = { closed: false, open: 0 };+ Object.defineProperty(window, '__journeyFetchGate', { value: gate });+ window.fetch = (input, init) => {+ const url = new URL(typeof input === 'string' ? input : input.url, location.href);+ const accept = new Headers(init?.headers ?? (typeof input === 'string' ? undefined : input.headers)).get('accept') || '';+ if (url.pathname.endsWith('/events') || accept.includes('text/event-stream')) return gate.closed ? new Promise(() => {}) : nativeFetch(input, init);+ if (gate.closed) return new Promise(() => {});+ gate.open += 1;+ return nativeFetch(input, init).finally(() => { gate.open -= 1; });+ };+ })()` });await chrome.send('Fetch.enable', { patterns: [{ urlPattern: JOURNEY_HOSTED + '/*', requestStage: 'Request' }, { urlPattern: JOURNEY_LOCAL + '/*', requestStage: 'Request' }, { urlPattern: view.base + '/*', requestStage: 'Request' }] });+ /** Close the hosted document to new reads and wait until every read it started has its answer from this fixture. */+ async function quiescePage() {+ if (!(await chrome.stable('(() => { const gate = window.__journeyFetchGate; if (gate) gate.closed = true; return Boolean(gate); })()'))) return;+ await chrome.waitFor('window.__journeyFetchGate.open === 0');+ await drainTasks();+ }+ /** Leave the hosted page for a blank one only once nothing it started is still paused here. */+ async function leavePage() {+ await quiescePage();+ await chrome.send('Page.navigate', { url: 'about:blank' });+ await chrome.waitFor('location.href === "about:blank"');+ }const stop = async () => {stopping = true;for (const record of interceptions) record.stopObserved = true;for (const held of heldResponses.splice(0)) held.cancel();for (const release of releaseHeldResponses) release();const errors = [];- // Settle active completions before quiescing the owned page; requests arriving during shutdown- // then receive an explicit matching browser cancellation instead of escaping to a real origin.+ // Close the page to new reads and settle the ones it started before leaving it, so no read is stranded by the+ // navigation; anything still arriving during shutdown is drained instead of escaping to a real origin.+ try { await quiescePage(); } catch (error) { errors.push(error); }try { await drainTasks(); } catch (error) { errors.push(error); }try {await chrome.send('Page.navigate', { url: 'about:blank' });await chrome.waitFor('location.href === "about:blank"');} catch (error) { errors.push(error); }try { await drainTasks(); } catch (error) { errors.push(error); }+ try { await chrome.send('Page.removeScriptToEvaluateOnNewDocument', { identifier: fetchGate }); } catch (error) { errors.push(error); }try { await chrome.send('Fetch.disable'); } catch (error) { errors.push(error); }try { await drainTasks(); } catch (error) { errors.push(error); }finally {@@ -1350,6 +1381,7 @@ async function interceptJourneyOrigins(chrome, site, view, { deadline: currentDeassert.equal(incomplete.length, 0, 'each paused request completes once or has its own confirmed browser cancellation; safe interception trace: ' + diagnostic);};stop.cancelOwned = cancelOwned;+ stop.leavePage = leavePage;/** Observe terminal request outcomes after the caller releases or aborts its owned inputs. */stop.settled = () => Promise.allSettled(tasks);stop.holdNextResponse = holdNextResponse;@@ -1412,6 +1444,7 @@ test('the hosted journey names its phase and stops within its own deadline [N26,const chrome = {socket: new EventTarget(),async send() { return {}; },+ async stable() { return false; },async waitFor() { return true; },};let deadline;@@ -1600,6 +1633,10 @@ test('the hosted page lists linked and local boards together [N26,H5]', {let closingChrome;let stopOrigins;const heldMoves = [];+ // The move's own reply is the act's outcome (#748): every relay read the following refresh makes waits here, so an+ // act that still waited on that whole-page refresh would never complete while they are held.+ const holdRelayReads = "(() => { const read = transport.request; window.__relayReadsHeld = []; window.__releaseRelayReads = () => { transport.request = read; for (const go of window.__relayReadsHeld.splice(0)) go(); }; transport.request = (path, body) => new Promise((resolve, reject) => window.__relayReadsHeld.push(() => read.call(transport, path, body).then(resolve, reject))); return true; })()";+ const releaseRelayReads = '(() => { window.__releaseRelayReads(); return true; })()';/** Read only the fixture's existing bounded, redacted interception trace. */journeyTrace = () => stopOrigins?.trace?.() ?? null;/** Close only this fixture's browser and reads; racing a promise never claims cancellation. */@@ -1673,7 +1710,7 @@ test('the hosted page lists linked and local boards together [N26,H5]', {journeyDeadline.setPhase(journeyPhase);// C's real local board is also paired on the relay so this catches duplicate-ID source preference.// Start a fresh hosted document before pairing C, then wait for transport work rather than assuming C is selected.- await chrome.send('Page.navigate', { url: 'about:blank' });+ await stopOrigins.leavePage();await chrome.send('Page.navigate', { url: JOURNEY_HOSTED + '/#board=' + localRelay.board + '&key=' + encodeURIComponent(localRelayKey) });await chrome.waitFor('location.hash === "" && !!JSON.parse(localStorage.getItem("pullboard.relay.keys.v1") || "{}")[' + JSON.stringify(localRelay.board) + ']', 30_000); // budget: 30s hang ceiling for paired-key storage to settle.assert.ok(linked.calls.some(call => call.method === 'GET'@@ -1683,7 +1720,7 @@ test('the hosted page lists linked and local boards together [N26,H5]', {journeyPhase = 'discover-combined-board-list';journeyDeadline.setPhase(journeyPhase);// The hosted page's real local-view handoff discovers B without a pasted key, URL or port.- await chrome.send('Page.navigate', { url: 'about:blank' });+ await stopOrigins.leavePage();await chrome.send('Page.navigate', { url: JOURNEY_HOSTED + '/' });await chrome.waitFor("[...document.querySelectorAll('#proj-list .proj.repo')].some(row => row.textContent.includes('fixture/repository')) && [...document.querySelectorAll('#proj-list .proj.repo')].some(row => row.textContent.includes('local-machine-b')) && [...document.querySelectorAll('#proj-list .proj.repo')].some(row => row.textContent.includes('local-machine-c'))");const localList = await (await fetchLive(localView.base + '/api/v1/boards', { headers: { 'x-pullboard-key': localView.key } })).json();@@ -1811,10 +1848,12 @@ test('the hosted page lists linked and local boards together [N26,H5]', {await chrome.waitFor("view.root === data.projects.find(row => row.id === " + JSON.stringify(linkedId) + ").root && readOnly && requests");await chrome.click("document.querySelector('#new-item')");await chrome.stable("document.querySelector('#add-title').value = 'relay draft survives local completion'; true");+ assert.equal(await chrome.stable(holdRelayReads), true, 'relay reads wait for the fixture');firstResponse.release();await chrome.waitFor('window.__actOutcome !== null');assert.equal(await chrome.stable('window.__actOutcome'), true, 'a local write response is parsed using the mode it started with after switching to relay');assert.equal(await chrome.stable("document.querySelector('#add-title').value"), 'relay draft survives local completion', 'the older local completion does not clear the current relay draft');+ assert.equal(await chrome.stable(releaseRelayReads), true, 'the held relay reads go on');journeyPhase = 'hold-second-local-completion-across-reselection';journeyDeadline.setPhase(journeyPhase);@@ -1836,9 +1875,12 @@ test('the hosted page lists linked and local boards together [N26,H5]', {await chrome.waitFor("view.root === data.projects.find(row => row.name === 'local-machine-b').root && !readOnly && !requests");await chrome.click("document.querySelector('#new-item')");await chrome.stable("document.querySelector('#add-title').value = 'replacement local draft'; true");+ assert.equal(await chrome.stable(holdRelayReads), true, 'relay reads wait for the fixture');secondResponse.release();await chrome.waitFor('window.__actOutcome !== null');+ assert.equal(await chrome.stable('window.__actOutcome'), true, 'the second local write completes on its own reply');assert.equal(await chrome.stable("document.querySelector('#add-title').value"), 'replacement local draft', 'a completion after switching away and back preserves the replacement draft');+ assert.equal(await chrome.stable(releaseRelayReads), true, 'the held relay reads go on');journeyPhase = 'assert-final-browser-state';journeyDeadline.setPhase(journeyPhase);