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): only the latest action writes or closes the output [N27]

Corey Olson07c0fec71f1d
diff --git a/src/cockpit.js b/src/cockpit.js
index faeceb7e..5d8fd9d3 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -769,25 +769,33 @@ function search() {
/**
* Run an action as its CLI command on the server, show what the command said, and redraw from the
- * board. A new action cancels the last one's pending close, so it can never hide this one's output.
+ * board. The console belongs to the latest action: one that answers after a later one has started
+ * writes nothing there and sets no close, and a close fires only while its action is still the
+ * latest, so a success can never hide a refusal that came after it.
*/
async function act(command, args, root = view.root) {
const out = $('console');
+ const run = (view.acting = (view.acting || 0) + 1);
+ const latest = () => run === view.acting;
clearTimeout(view.closing);
out.hidden = false;
out.className = 'console';
out.textContent = 'running…';
try {
const result = await api('/api/act', { root, command, args });
- out.className = 'console ' + (result.code === 0 ? 'ok' : 'no');
- out.textContent = '$ ' + result.command + '\\n' + (result.out + result.err).trim();
- // What went through says so and then steps aside; a refusal stays until the person closes it.
- if (result.code === 0) view.closing = setTimeout(() => { out.hidden = true; }, 6000);
+ if (latest()) {
+ out.className = 'console ' + (result.code === 0 ? 'ok' : 'no');
+ out.textContent = '$ ' + result.command + '\\n' + (result.out + result.err).trim();
+ // What went through says so and then steps aside; a refusal stays until the person closes it.
+ if (result.code === 0) view.closing = setTimeout(() => { if (latest()) out.hidden = true; }, 6000);
+ }
await refresh();
return result.code === 0;
} catch (error) {
- out.className = 'console no';
- out.textContent = String(error.message || error);
+ if (latest()) {
+ out.className = 'console no';
+ out.textContent = String(error.message || error);
+ }
return false;
}
}
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index 48225396..ecb88079 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -1245,7 +1245,7 @@ test("a finished action's output steps aside [N27]", async () => {
try {
const page = await openPage(view);
// The page's timers, held by the test: each pending close is recorded and fired at will.
- page.run('globalThis.closes = []; globalThis.setTimeout = (run, ms) => closes.push({ run, ms, live: true }); globalThis.clearTimeout = (id) => { if (closes[id - 1]) closes[id - 1].live = false; };');
+ page.run('globalThis.pause = setTimeout; globalThis.closes = []; globalThis.setTimeout = (run, ms) => closes.push({ run, ms, live: true }); globalThis.clearTimeout = (id) => { if (closes[id - 1]) closes[id - 1].live = false; };');
const pending = () => JSON.parse(page.run('JSON.stringify(closes.map((close) => [close.ms, close.live]))'));
const out = page.element('console');
const shout = async (to, text) => {
@@ -1266,6 +1266,17 @@ test("a finished action's output steps aside [N27]", async () => {
assert.match(out.textContent, /NO_READER/);
assert.deepEqual([out.className, out.hidden], ['console no', false]);
assert.deepEqual(pending().slice(1), [[6000, false]], 'the refusal cancelled the close the shout before it left, and set none');
+
+ // Two shouts in flight: the first goes through but answers only after the second, a refusal, has
+ // started. The first must not set a close that would hide the refusal.
+ page.run('const plain = fetch; let sent = 0; globalThis.fetch = (path, init) => path === "/api/act" ? new Promise((done) => pause(done, ++sent === 1 ? 300 : 900)).then(() => plain(path, init)) : plain(path, init);');
+ await shout('web', 'first, and slow to answer');
+ await shout('nobody-here', 'second, and refused');
+ await new Promise((done) => setTimeout(done, 2000));
+ await page.run('refresh()');
+ assert.match(out.textContent, /NO_READER/, 'the later action owns the console');
+ page.run('closes.filter((close) => close.live).forEach((close) => close.run())');
+ assert.deepEqual([out.className, out.hidden], ['console no', false], 'and no close from the earlier success hides it');
} finally {
await view.stop();
}