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: retain action ownership across board switches [N26,H5]
Corey Olson89c456d82721
diff --git a/src/cockpit.js b/src/cockpit.jsindex 7b8a9d42..302e794e 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -2955,6 +2955,7 @@ function trapFocus(event) {*/async function decideRow(kind, command, args, anchor) {if (snapshot || (readOnly && !requests)) return false;+ const requestMode = requests;const root = view.root, scroll = window.scrollY;const ids = String(args.ids).split(/\s+/);const prefix = kind + ':';@@ -2965,15 +2966,15 @@ async function decideRow(kind, command, args, anchor) {view.specFeedback = feedback;render();// A waiting request keeps its row; let browser anchoring follow growth above it.- if (!requests) window.scrollTo({ top: scroll, behavior: 'instant' });+ if (!requestMode) window.scrollTo({ top: scroll, behavior: 'instant' });try {const move = pageMove(command, kind === 'doctrine' ? { ...args, ids: ids.map((id) => 'doctrine:' + id).join(' ') } : args);- const result = requests ? await sendPersonRequest(root, move.body) : await api(boardPath(root) + '/moves', move.body);- const request = requests && result?.result?.request;- if (requests && (!request?.id || !['waiting', 'done', 'refused'].includes(request.status))) throw new Error('The request did not include its status; refresh the board to check it.');- feedback.tone = requests ? request.status === 'done' ? 'ok' : request.status === 'refused' ? 'no' : '' : 'ok';- feedback.text = requests ? requestNotice(request) : moveMessage(move.body, result.result);- if (requests) { feedback.requestId = request.id; feedback.status = request.status; }+ const result = requestMode ? await sendPersonRequest(root, move.body) : await api(boardPath(root) + '/moves', move.body);+ const request = requestMode && result?.result?.request;+ if (requestMode && (!request?.id || !['waiting', 'done', 'refused'].includes(request.status))) throw new Error('The request did not include its status; refresh the board to check it.');+ feedback.tone = requestMode ? request.status === 'done' ? 'ok' : request.status === 'refused' ? 'no' : '' : 'ok';+ feedback.text = requestMode ? requestNotice(request) : moveMessage(move.body, result.result);+ if (requestMode) { feedback.requestId = request.id; feedback.status = request.status; }// Decided from the list, the pick moves on to the next row before the board redraws without the decided one, so// the next key decides that one.if (feedback.from === 'list' && feedback.tone !== 'no' && next && view.row[kind] === ids[0] && root === view.root) view.row[kind] = next;@@ -2984,7 +2985,7 @@ async function decideRow(kind, command, args, anchor) {}if (root === view.root && view.specFeedback === feedback) {render();- if (!requests) window.scrollTo({ top: scroll, behavior: 'instant' });+ if (!requestMode) window.scrollTo({ top: scroll, behavior: 'instant' });// A phone row click jumps to its detail. A later list-key decision returns the next pick to view,// instead of restoring that detail's scroll position with the focused list still offscreen.if (feedback.from === 'list' && feedback.tone === 'ok' && next && view.row[kind] === next) {@@ -2993,15 +2994,16 @@ async function decideRow(kind, command, args, anchor) {// Center an offscreen pick: nearest can round a half-pixel edge just outside the viewport.if (rect && (rect.top < 0 || rect.bottom > innerHeight)) picked.scrollIntoView({ block: 'center', behavior: 'instant' });}- if (!requests || feedback.status === 'done') setTimeout(() => { if (view.specFeedback === feedback) { view.specFeedback = null; render(); } }, 6000);+ if (!requestMode || feedback.status === 'done') setTimeout(() => { if (view.specFeedback === feedback) { view.specFeedback = null; render(); } }, 6000);}- return requests ? Boolean(feedback.requestId) && feedback.status !== 'refused' : feedback.tone === 'ok';+ 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. */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; }+ const requestMode = requests;// A form's result stands above its actions, or above the shout composer's bar, never inside that one row.if (anchor) {const target = anchor.matches('form')@@ -3016,28 +3018,28 @@ async function act(command, args, anchor) {clearTimeout(view.closing);out.hidden = false;out.className = 'console';- out.textContent = requests ? 'Request waiting…' : 'running…';+ out.textContent = requestMode ? 'Request waiting…' : 'running…';out.scrollIntoView({ block: 'nearest' });try {// On the local view the person's word to the coordinator is the person's own request, not a shout the// coordinator sends itself; through the relay every action is already a sealed request.- const asked = command === 'request' && !requests;+ const asked = command === 'request' && !requestMode;const move = asked ? null : pageMove(command === 'request' ? 'shout' : command, command === 'request' ? { to: 'coordinator', text: args.text } : args);const result = asked ? await api(boardPath(root) + '/requests', { text: String(args.text || '').trim() })- : requests ? await sendPersonRequest(root, move.body) : await api(boardPath(root) + '/moves', move.body);- const request = requests && result?.result?.request;- if (requests && (!request?.id || !['waiting', 'done', 'refused'].includes(request.status))) throw new Error('The request did not include its status; refresh the board to check it.');+ : requestMode ? await sendPersonRequest(root, move.body) : await api(boardPath(root) + '/moves', move.body);+ const request = requestMode && result?.result?.request;+ if (requestMode && (!request?.id || !['waiting', 'done', 'refused'].includes(request.status))) throw new Error('The request did not include its status; refresh the board to check it.');if (latest()) {- out.className = 'console' + (requests ? request.status === 'done' ? ' ok' : request.status === 'refused' ? ' no' : '' : ' ok');- out.textContent = requests ? requestNotice(request) : asked ? 'Sent to the coordinator.' : '$ pullboard ' + move.label + '\\n' + moveMessage(move.body, result.result);- if (requests) view.request = { root, id: request.id, run };+ out.className = 'console' + (requestMode ? request.status === 'done' ? ' ok' : request.status === 'refused' ? ' no' : '' : ' ok');+ out.textContent = requestMode ? requestNotice(request) : asked ? 'Sent to the coordinator.' : '$ pullboard ' + move.label + '\\n' + moveMessage(move.body, result.result);+ if (requestMode) view.request = { root, id: request.id, run };out.scrollIntoView({ block: 'center' });// What went through says so and then steps aside; a refusal stays until the person closes it.- if (!requests || request.status === 'done') view.closing = setTimeout(() => { if (latest()) out.hidden = true; }, 6000);+ 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.- return !requests || request.status !== 'refused';+ return !requestMode || request.status !== 'refused';} catch (error) {if (latest()) {out.className = 'console no';@@ -3340,7 +3342,12 @@ document.addEventListener('keydown', (event) => {});$('add-form').addEventListener('submit', async (event) => {event.preventDefault();- if (await act('add', { lane: $('add-lane').value, title: $('add-title').value, criterion: $('add-criterion').value, specs: $('add-specs').value, brief: $('add-brief').value }, event.currentTarget)) {+ const root = view.root;+ const submitted = { lane: $('add-lane').value, title: $('add-title').value, criterion: $('add-criterion').value, specs: $('add-specs').value, brief: $('add-brief').value };+ if (await act('add', submitted, event.currentTarget) && view.root === root+ && $('add-lane').value === submitted.lane && $('add-title').value === submitted.title+ && $('add-criterion').value === submitted.criterion && $('add-specs').value === submitted.specs+ && $('add-brief').value === submitted.brief) {$('add-title').value = '';$('add-criterion').value = '';$('add-specs').value = '';@@ -3365,7 +3372,10 @@ $('shout-form').addEventListener('submit', async (event) => {});$('hold-form').addEventListener('submit', async (event) => {event.preventDefault();- if (await act('hold', { lane: $('hold-lane').value, reason: $('hold-reason').value }, event.currentTarget)) $('hold-reason').value = '';+ const root = view.root;+ const submitted = { lane: $('hold-lane').value, reason: $('hold-reason').value };+ if (await act('hold', submitted, event.currentTarget) && view.root === root+ && $('hold-lane').value === submitted.lane && $('hold-reason').value === submitted.reason) $('hold-reason').value = '';});// The first entry keeps the tab it opened on; Back and Forward show what each entry names.address(false);diff --git a/test/cockpit/relay.test.js b/test/cockpit/relay.test.jsindex 9bad6094..4740a133 100644--- a/test/cockpit/relay.test.js+++ b/test/cockpit/relay.test.js@@ -935,6 +935,26 @@ async function journeyRelaySite(box, localOrigin) {async function interceptJourneyOrigins(chrome, site, view) {const failures = [];const tasks = [];+ const heldResponses = [];+ const releaseHeldResponses = new Set();+ const holdNextResponse = (matches) => {+ let entry;+ const pending = new Promise((resolve, reject) => {+ const timer = setTimeout(() => {+ const index = heldResponses.indexOf(entry);+ if (index !== -1) heldResponses.splice(index, 1);+ reject(new Error('The real API response did not reach the fixture hold within 10 seconds.'));+ }, 10_000);+ entry = {+ matches,+ resolve(value) { clearTimeout(timer); resolve(value); },+ cancel() { clearTimeout(timer); reject(new Error('The fixture closed before the held API response arrived.')); },+ };+ heldResponses.push(entry);+ });+ void pending.catch(() => {});+ return pending;+ };const listener = ({ data }) => {const message = JSON.parse(String(data));if (message.method !== 'Fetch.requestPaused') return;@@ -957,6 +977,17 @@ async function interceptJourneyOrigins(chrome, site, view) {await reader.cancel();body = Buffer.from(first.value || []);} else body = Buffer.from(await response.arrayBuffer());+ const heldIndex = heldResponses.findIndex((entry) => entry.matches({ method: asked.method, path: address.pathname, status: response.status }));+ if (heldIndex !== -1) {+ const [held] = heldResponses.splice(heldIndex, 1);+ let release;+ const released = new Promise((resume) => {+ release = () => { releaseHeldResponses.delete(release); resume(); };+ releaseHeldResponses.add(release);+ });+ held.resolve({ status: response.status, release });+ await released;+ }await chrome.send('Fetch.fulfillRequest', {requestId, responseCode: response.status,responseHeaders: [...response.headers].filter(([name]) => !['content-length', 'connection', 'transfer-encoding', 'keep-alive', 'date'].includes(name.toLowerCase())).map(([name, value]) => ({ name, value })),@@ -966,11 +997,15 @@ async function interceptJourneyOrigins(chrome, site, view) {};chrome.socket.addEventListener('message', listener);await chrome.send('Fetch.enable', { patterns: [{ urlPattern: JOURNEY_HOSTED + '/*', requestStage: 'Request' }, { urlPattern: JOURNEY_LOCAL + '/*', requestStage: 'Request' }, { urlPattern: view.base + '/*', requestStage: 'Request' }] });- return async () => {+ const stop = async () => {+ for (const held of heldResponses.splice(0)) held.cancel();+ for (const release of releaseHeldResponses) release();chrome.socket.removeEventListener('message', listener);try { await Promise.all(tasks); } finally { await chrome.send('Fetch.disable'); }assert.deepEqual(failures, [], 'the hosted and loopback fixture requests complete');};+ stop.holdNextResponse = holdNextResponse;+ return stop;}test('the hosted page lists linked and local boards together [N26,H5]', {@@ -1003,6 +1038,7 @@ test('the hosted page lists linked and local boards together [N26,H5]', {let site;let chrome;let stopOrigins;+ const heldMoves = [];try {localView = await startView(local);site = await journeyRelaySite(linked, localView.base);@@ -1068,8 +1104,49 @@ test('the hosted page lists linked and local boards together [N26,H5]', {'C board events use C’s local view despite its paired relay copy');assert.equal(localReads.some((entry) => new URL(entry.url).pathname.includes(linkedId)), false,'the local view never receives A’s relay board id');++ // Hold only delivery of a real local API response after the write has completed. Switching to a relay board+ // while it is in flight must not reinterpret the local response as a sealed request or clear that board's form.+ await press(chrome, localRow);+ await chrome.waitFor("view.root === data.projects.find(row => row.name === 'local-machine-b').root && !readOnly && !requests");+ await chrome.stable("window.__priorAct = act; window.__actOutcome = null; act = async (...args) => { const result = await window.__priorAct(...args); window.__actOutcome = result; return result; }; true");+ await chrome.stable("document.querySelector('#new-item').click(); document.querySelector('#add-title').value = 'held local action'; true");+ const firstHeld = stopOrigins.holdNextResponse(({ method, path }) => method === 'POST' && path === '/api/v1/boards/' + localId + '/moves');+ await chrome.stable("document.querySelector('#add-title').value = 'held local action'; document.querySelector('#add-form').requestSubmit(); true");+ const firstResponse = await firstHeld;+ heldMoves.push(firstResponse.release);+ assert.ok(firstResponse.status >= 200 && firstResponse.status < 300, 'the local board accepted the real move before response delivery was held');+ await press(chrome, remoteRow);+ await chrome.waitFor("view.root === data.projects.find(row => row.id === " + JSON.stringify(linkedId) + ").root && readOnly && requests");+ await chrome.stable("document.querySelector('#new-item').click(); document.querySelector('#add-title').value = 'relay draft survives local completion'; true");+ 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');++ // Switching away and back can leave the same root selected. A successful old submit must still preserve a new+ // draft entered in that board's form while the response was held.+ await press(chrome, localRow);+ await chrome.waitFor("view.root === data.projects.find(row => row.name === 'local-machine-b').root && !readOnly && !requests");+ await chrome.stable("document.querySelector('#new-item').click(); document.querySelector('#add-title').value = 'second held local action'; true");+ const secondHeld = stopOrigins.holdNextResponse(({ method, path }) => method === 'POST' && path === '/api/v1/boards/' + localId + '/moves');+ await chrome.stable('window.__actOutcome = null; true');+ await chrome.stable("document.querySelector('#add-form').requestSubmit(); true");+ const secondResponse = await secondHeld;+ heldMoves.push(secondResponse.release);+ assert.ok(secondResponse.status >= 200 && secondResponse.status < 300, 'the second real local write completes before delivery');+ await press(chrome, remoteRow);+ await chrome.waitFor("view.root === data.projects.find(row => row.id === " + JSON.stringify(linkedId) + ").root && readOnly && requests");+ await press(chrome, localRow);+ await chrome.waitFor("view.root === data.projects.find(row => row.name === 'local-machine-b').root && !readOnly && !requests");+ await chrome.stable("document.querySelector('#new-item').click(); document.querySelector('#add-title').value = 'replacement local draft'; true");+ secondResponse.release();+ await chrome.waitFor('window.__actOutcome !== null');+ 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.deepEqual(chrome.exceptions, [], 'the hosted mixed-board page reports no uncaught browser exceptions');} finally {+ for (const release of heldMoves) release();try { if (stopOrigins) await stopOrigins(); }finally {try { if (chrome) await closeSnapshotChrome(chrome); }