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): a page holds one event stream, not one per repo [N26,A2]
Corey Olson364e73f4f6fb
diff --git a/src/cockpit.js b/src/cockpit.jsindex ac50fccd..79d80ea1 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -1043,10 +1043,12 @@ async function refresh() {$('live').textContent = snapshot ? 'read-only snapshot' : liveLine();}-// The local view follows each shown board's event stream instead of a timer (#545): it reads the board once, waits+// The local view follows the shown board's event stream instead of a timer (#545): it reads the board once, waits// on the board's events after that read's latest one, and reads again only when an event or the stream's changed// signal (#554) arrives, so a page whose board is quiet makes no requests. The relay transport keeps its own stream.-const streams = new Map();+// A page holds at most one stream: Chrome allows six connections per host, a held stream keeps one for good, and the+// catch-up read needs the rest. Six held streams left none, and the page waited forever for its own read.+let stream = null;let catching = null;let catchAgain = false;let catchWhenShown = false;@@ -1059,37 +1061,38 @@ const canStream = () => typeof AbortController === 'function' && typeof Readable/** The latest event a board state already shows; its events are newest first. */const latestEvent = (state) => Number(state?.events?.[0]?.event_id ?? 0);-/** Whether every board on screen has its stream up or opening, so nothing needs a timed read. */-const connected = () => streams.size > 0 && [...streams.values()].every((entry) => entry.status !== 'down');+/** Whether the page's stream is up or opening, so nothing needs a timed read. */+const connected = () => Boolean(stream) && stream.status !== 'down';-/** Say nothing while every shown board's stream is up, and why the page is not live while one is down. */+/** Say nothing while the page's stream is up, and why the page is not live while it is down. */function liveLine() {- const down = [...streams.values()].filter((entry) => entry.status === 'down');- if (!down.length) return '';- if (down.some((entry) => entry.offline)) return 'offline: is pullboard view still running?';+ if (!stream || stream.status !== 'down') return '';+ if (stream.offline) return 'offline: is pullboard view still running?';return (canStream() ? 'reconnecting' : 'no live stream in this browser') + ': refreshing every ' + FALLBACK_MS / 1000 + 's';}-/** Follow each board the page shows and stop following the rest, starting a new stream after the state just read. */+/** Stop following a board: close its stream and any retry waiting to reopen it. */+function unfollow() {+ if (!stream) return;+ stream.controller?.abort();+ clearTimeout(stream.retry);+ stream = null;+}++/**+ * Follow the one board the page shows, or a shown group's first repo, starting a new stream after the state just+ * read. Every catch-up reads every board, so the group's other repos and the sidebar's boards update with it, and on+ * a project switch, without a stream of their own.+ */function follow() {- const shown = new Map(data.group ? data.group.repos.map((repo) => [repo.root, repo.board]) : data.project ? [[view.root, data.project]] : []);- for (const [root, entry] of streams) {- if (shown.has(root)) continue;- entry.controller?.abort();- clearTimeout(entry.retry);- streams.delete(root);- }- for (const [root, state] of shown) {- const board = data.projects.find((entry) => entry.root === root && entry.ok);- const entry = streams.get(root);- // A board's events after the latest one this page shows are what changed it since.- if (entry && entry.id === board?.id) { entry.shown = Math.max(entry.shown, latestEvent(state)); continue; }- if (entry) { entry.controller?.abort(); clearTimeout(entry.retry); streams.delete(root); }- if (!board) continue;- const next = { root, id: board.id, after: latestEvent(state), shown: latestEvent(state), status: 'opening', offline: false, failures: 0, controller: null, retry: 0 };- streams.set(root, next);- void listen(next);- }+ const repo = data.group ? data.group.repos[0] : data.project ? { root: view.root, board: data.project } : null;+ const board = repo && data.projects.find((entry) => entry.root === repo.root && entry.ok);+ // The board's events after the latest one this page shows are what changed it since.+ if (stream && board && stream.id === board.id) { stream.shown = Math.max(stream.shown, latestEvent(repo.board)); return; }+ unfollow();+ if (!board) return;+ stream = { root: repo.root, id: board.id, after: latestEvent(repo.board), shown: latestEvent(repo.board), status: 'opening', offline: false, failures: 0, controller: null, retry: 0 };+ void listen(stream);}/** Read one server-sent message: its event name, its data and its numeric id. */@@ -1154,13 +1157,13 @@ async function listen(entry) {}throw new Error('the board stream ended');} catch (error) {- if (controller?.signal.aborted || streams.get(entry.root) !== entry) return;+ if (controller?.signal.aborted || stream !== entry) return;entry.status = 'down';// A request that never reached the view is a TypeError; a refusal or an ended stream is not.entry.offline = error instanceof TypeError;entry.failures += 1;$('live').textContent = liveLine();- if (controller) entry.retry = setTimeout(() => { if (streams.get(entry.root) === entry) void listen(entry); }, Math.min(FALLBACK_MS, 1000 * 2 ** Math.min(entry.failures - 1, 4)));+ if (controller) entry.retry = setTimeout(() => { if (stream === entry) void listen(entry); }, Math.min(FALLBACK_MS, 1000 * 2 ** Math.min(entry.failures - 1, 4)));}}diff --git a/test/cockpit/live.test.js b/test/cockpit/live.test.jsindex f5d3d6b6..feab8dde 100644--- a/test/cockpit/live.test.js+++ b/test/cockpit/live.test.js@@ -5,7 +5,7 @@ import { createServer, request as forward } from 'node:http';import { tmpdir } from 'node:os';import { join } from 'node:path';import { test } from 'node:test';-import { browserPause, boardId, boardOf, chromeExecutable, closeSnapshotChrome, fetchLive, machine, openSnapshotChrome, project, startView } from './fixture.js';+import { SPEC, browserPause, boardId, boardOf, chromeExecutable, closeSnapshotChrome, fetchLive, machine, openSnapshotChrome, pickProject, project, startView } from './fixture.js';/** The page's HTTP requests from a mark on, as method and path, leaving out data: URLs. */function sent(chrome, mark = 0) {@@ -174,3 +174,39 @@ test('a dropped stream reconnects from its last event [N26,A2]', { timeout: 120_await close();}});++// core-188's six-repo case (#545 review): one held stream per repo took all six of Chrome's connections to the view,+// so the catch-up read for a committed claim never left the page.+test('a group of six repos catches up on one stream [N26,A2]', { timeout: 120_000 }, async (t) => {+ const executable = chromeExecutable();+ assert.ok(executable, 'Chrome is required for the live view checks');+ const box = machine();+ const repos = [];+ for (let index = 0; index < 6; index++) repos.push(project(box, `capacity-${index}`, SPEC, { project: 'Stream capacity', name: `Capacity ${index}` }));+ box.run(repos[0].repo, 'add', 'web', 'Group catch-up', '--specs', 'G1', '--criterion', 'updates');+ const view = await startView(box);+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-live-group-chrome-'));+ let chrome;+ try {+ chrome = await openSnapshotChrome(executable, view.link.href, profile);+ const group = 'document.querySelector(\'#proj-list [data-root="group:Stream capacity"]\')';+ await chrome.waitFor(`data?.projects?.length === 6 && !!${group}`);+ await pickProject(chrome, group);+ await chrome.waitFor('data?.group?.repos?.length === 6 && document.querySelector(\'#live\').textContent === \'\'');+ const opened = streamReads(chrome).length;+ // The group shows each repo's board; the first repo's item is the one that moves.+ const shown = `data?.group?.repos?.find(repo => repo.root === ${JSON.stringify(repos[0].repo)})?.board.items.find(item => item.id === 1)?.status`;+ await watchFor(chrome, '__groupClaimAt', `${shown} === 'claimed'`);+ box.run(repos[0].web, 'claim', '1');+ assert.equal((await boardOf(view, repos[0].repo)).items.find((item) => item.id === 1).status, 'claimed', 'the board has the claim');+ await chrome.waitFor('window.__groupClaimAt !== null', 15_000); // budget: hang ceiling for the claim to arrive; the latency is judged below.+ const latency = await chrome.stable('window.__groupClaimAt') - await eventAt(view, repos[0].repo, 'claim', 1);+ t.diagnostic(`the group showed the claim ${latency} ms after the board recorded it, with ${opened} stream read(s) opened`);+ assert.ok(latency <= 2_000, `the group shows the claim ${latency} ms after the board recorded it`); // budget: declared by #545's frozen criterion: a move appears within 2000 ms.+ assert.deepEqual(chrome.exceptions, [], 'the page raises no uncaught exception');+ } finally {+ if (chrome) await closeSnapshotChrome(chrome);+ rmSync(profile, { recursive: true, force: true });+ await view.stop();+ }+});