fix(webui): build the inbox hire form after the read; pass through only pre-insert hire codes (#1873)

D4 review fix round.

P2: the org inbox took the hire form's HTML before its workspace read, so typing or a
submit result that landed during a slow read was painted over with the older draft.
inboxPage now takes a function and calls it while building the page after the read.
Two browser cases hold the inbox read: typing during it, and a refused start that
resolves during it, both survive the repaint (both fail on the previous commit).

P3: a hire start passes a bus code through only when the broker raises it before it
records the decision (hire-decisions prepare: the model route codes,
definition-not-hireable, definition-shared, no-chief-of-staff). Every other code,
including revision-conflict-revoked, request-timeout, invalid-envelope,
incomplete-request and codes the resolve or apply steps can raise, stays
outcome-unknown. Messages are worded for hire, fire and change alike.
This commit was merged in pull request #1935.
This commit is contained in:
jason.woltje committed 2026-11-11 13:01:54 -06:00
1 parent c3293ef4ef
commit 70504ddddb
5 files changed
+80 -28

No files matched your search

+15 -12
View File
@@ -42,18 +42,21 @@ const BUS_CODES = {
'decision-closed': 'decision-closed', 'decision-stale': 'decision-stale', 'invalid-choice': 'decision-stale',
'invalid-request': 'invalid-request', 'hire-owner-required':'hire-owner-required','right-required':'right-required','decision-expired':'decision-expired','hire-resolution-required':'hire-resolution-required',
};
// D4 (#1873, P1-2): a hire start the bus definitely refused keeps its own code. The broker can
// refuse before it records the decision (a model route the catalogue does not offer) or after
// (a check or apply that fails), so the message never claims that nothing was recorded. A lost
// or unreadable reply stays outcome-unknown. The model route codes get a next step; any other code is named.
// D4 (#1873, P1-2): a hire, fire or change start the bus definitely refused keeps its own code,
// but only for codes the broker raises before it records the decision: the proposal checks in
// hire-decisions.mjs prepare(), which #raiseHire runs before its INSERT. hire.start.console then
// resolves the decision and applies it in #hireConsole, and those steps can raise other codes (and
// some of the same generic ones) after the decision exists or is consumed, so every code not listed
// here stays outcome-unknown. Review P3: an allowlist, not a pass-through of any well-formed code.
const HIRE_START_REFUSALS = {
'model-provider-unavailable': [409, 'The model proxy does not offer this model, or its catalogue is not ready. Pick a model it offers, or ask the owner to check Settings > Model proxy. The hire was not applied.'],
'model-catalogue-unavailable': [503, 'The model catalogue could not be read, so this model could not be checked. Check Settings > Model proxy, then try again. The hire was not applied.'],
'model-harness-incompatible': [409, 'This model does not run on the chosen harness. Pick another model or harness. The hire was not applied.'],
'thinking-unsupported': [409, 'The chosen harness does not apply this thinking level. Clear Thinking or pick a level it applies. The hire was not applied.'],
'model-provider-unavailable': [409, 'The model proxy does not offer this model, or its catalogue is not ready. Pick a model it offers, or ask the owner to check Settings > Model proxy. Nothing was applied.'],
'model-catalogue-unavailable': [503, 'The model catalogue could not be read, so this model could not be checked. Check Settings > Model proxy, then try again. Nothing was applied.'],
'model-harness-incompatible': [409, 'This model does not run on the chosen harness. Pick another model or harness. Nothing was applied.'],
'thinking-unsupported': [409, 'The chosen harness does not apply this thinking level. Clear Thinking or pick a level it applies. Nothing was applied.'],
'definition-not-hireable': [409, 'This organization does not hire agents from this role template. Pick another template. Nothing was applied.'],
'definition-shared': [409, 'Another agent uses the same role definition, so this change cannot replace it. Nothing was applied.'],
'no-chief-of-staff': [409, 'This organization has no chief of staff, so a hire, fire or change cannot be checked against it. Nothing was applied.'],
};
const OPEN = ['outcome-unknown', 'invalid-response', 'response-too-large', 'outcome-unknown-revoked'];
const BUS_CODE = /^[a-z][a-z-]{0,63}$/;
const BODY_MAX = 4096;
const TOKEN = /^[a-f0-9]{64}$/;
const DIGEST = /^[a-f0-9]{64}$/;
@@ -149,9 +152,9 @@ export async function decisionHTTP(req, res, { path, decide, session, live, conf
line(step==='start'?'hire=recorded':'templates=read');
return json(res,200,step==='start'?{id:result.id,op:result.op,choice:result.choice}:result);
} catch(err) {
if(step!=='start' || !(err instanceof BusReadError) || BUS_CODES[err.code] || OPEN.includes(err.code) || !BUS_CODE.test(err.code ?? ''))
if(step!=='start' || !(err instanceof BusReadError) || !Object.hasOwn(HIRE_START_REFUSALS,err.code))
return refuse(busCode(err,step==='start'?'outcome-unknown':'confirmation-unavailable'));
const [status,message]=HIRE_START_REFUSALS[err.code] ?? [409, `The bus refused this hire (${err.code}). Refresh the inbox to see whether a hire decision is open before trying again.`];
const [status,message]=HIRE_START_REFUSALS[err.code];
line(`error=${err.code}`);
return json(res,status,{error:err.code,message});
}
+1 -1
View File
@@ -1530,7 +1530,7 @@
if (n === 0 && window.MosaicOrg) return window.MosaicWorkspace.home();
if (a === 'projects' && n === 1 && window.MosaicOrg) return window.MosaicWorkspace.projectsPage(q);
if (a === 'organization' && n === 1 && window.MosaicOrg) return window.MosaicWorkspace.dashboard();
if (a === 'inbox' && n === 1 && window.MosaicOrg) return configRead.then(() => window.MosaicWorkspace.inboxPage(q, { hire: hireStartHtml() }));
if (a === 'inbox' && n === 1 && window.MosaicOrg) return configRead.then(() => window.MosaicWorkspace.inboxPage(q, { hire: hireStartHtml }));
if (a === 'tasks' && n === 1 && window.MosaicOrg) return window.MosaicTasksBoard.view();
if (a === 'inbox' && n === 1) return inboxView(get);
if (a === 'inbox' && n === 2) return SAFE.test(b) ? decisionView(get, b, current) : notFound(`${txt(b)} is not a decision id.`);
+4 -2
View File
@@ -663,7 +663,9 @@
}
// ---- inbox across organizations (sample 05) ----
// `opts.hire`: the hire, fire and change form bus.js builds for the current organization (D4, P0-1).
// `opts.hire`: a function that returns the hire, fire and change form bus.js builds for the current
// organization (D4, P0-1). It is called after the workspace read so typing or a submit result that
// lands during the read is not painted over with an older draft.
async function inboxPage(q, opts = {}) {
const org = listParam(q, 'org', id => ORG_ID.test(id));
const want = String(q?.get?.('d') || '');
@@ -724,7 +726,7 @@
<div class="ws-ibx-grid${insp ? ' with-insp' : ''}"><div class="ws-ibx-list">${table}
${secH('Answered today', 'kept for 24 hours, then in the trail')}
<p class="ws-panel tight note" data-ws-answered>Answered and expired items are not built yet.</p>
${typeof opts?.hire === 'string' ? opts.hire : ''}</div>
${typeof opts?.hire === 'function' ? opts.hire() : ''}</div>
${insp}
</div>
</section>`;
+17 -8
View File
@@ -293,8 +293,9 @@ test('A4 confirmation holds the exact human adjustment, so resolve cannot substi
assert.equal(r.status,200,r.text);assert.deepEqual(s.calls[1].args.adjust,adjust);
});
// D4 (#1873, P1-2): a hire start the bus definitely refused keeps its own code and a next step; a
// lost or unreadable reply is still outcome-unknown, and the other steps keep their mapping.
// D4 (#1873, P1-2): a hire start the bus definitely refused before it recorded the decision keeps its
// own code and a next step; every other code, a lost or unreadable reply among them, is still
// outcome-unknown, and the other steps keep their mapping.
const START_HIRE={op:'hire',level:'org',name:'scout',reason:'Need help',role:{template:'coder',sha256:DIGEST},route:{harness:'pi',model:'gone-model'}};
const startWith=async err=>{
const s=setup({resolve:()=>{throw err;}});
@@ -308,20 +309,28 @@ test('D4 hire start: model-provider-unavailable keeps its code and names Setting
const body=r.json();
assert.equal(body.error,'model-provider-unavailable');
assert.match(body.message,/Settings > Model proxy/);
assert.match(body.message,/not applied/);
assert.match(body.message,/Nothing was applied/);
assert.equal(r.headers['cache-control'],'no-store');
assert.match(s.lines.at(-1),/step=start error=model-provider-unavailable$/);
});
test('D4 hire start: the other model route codes keep their code with a next step',async()=>{
for(const [code,status] of [['model-catalogue-unavailable',503],['model-harness-incompatible',409],['thinking-unsupported',409]]) {
const {r}=await startWith(new BusReadError(code));
assert.equal(r.status,status,`${code}: ${r.text}`);assert.equal(r.json().error,code);assert.match(r.json().message,/not applied/);
assert.equal(r.status,status,`${code}: ${r.text}`);assert.equal(r.json().error,code);assert.match(r.json().message,/Nothing was applied/);
}
});
test('D4 hire start: any other definite code is named and never claims nothing was recorded',async()=>{
const {r}=await startWith(new BusReadError('definition-not-hireable'));
assert.equal(r.status,409,r.text);
assert.deepEqual(r.json(),{error:'definition-not-hireable',message:'The bus refused this hire (definition-not-hireable). Refresh the inbox to see whether a hire decision is open before trying again.'});
test('D4 hire start: the other proposal checks that run before the decision insert keep their code',async()=>{
for(const code of ['definition-not-hireable','definition-shared','no-chief-of-staff']) {
const {r}=await startWith(new BusReadError(code));
assert.equal(r.status,409,`${code}: ${r.text}`);assert.equal(r.json().error,code);assert.match(r.json().message,/Nothing was applied/);
assert.doesNotMatch(r.json().message,/\bhire was\b/,'worded for hire, fire and change alike');
}
});
// Review P3: a code the broker can raise after the decision exists or is consumed, or one the bus
// server raises about the request itself, is not a definite refusal of the start.
test('D4 hire start: a code that can follow the decision insert, or a transport code, stays outcome-unknown',async()=>{
for(const code of ['revision-conflict-revoked','request-timeout','invalid-envelope','incomplete-request','instance-kept','organization-instance-exists','organization-unknown-instance','root-fire-shared','fire-in-progress','some-future-code'])
refused((await startWith(new BusReadError(code))).r,'outcome-unknown');
});
test('D4 hire start: a lost or unreadable reply is still outcome-unknown',async()=>{
for(const err of [new BusReadError('outcome-unknown'),new BusReadError('invalid-response'),new BusReadError('response-too-large'),new BusReadError('outcome-unknown-revoked'),new BusReadError('Not A Code'),new BusReadError(''),new Error('socket closed'),Object.assign(new Error('x'),{code:'model-provider-unavailable'})])
@@ -17,10 +17,11 @@ const SHA = 'b'.repeat(64);
const DECISION = 'dec-acme-0001';
// One running organization. `decide` gives it the send and decision transports a --send Console has.
function organizations({ decide, calls }) {
// `gate.held`, when set, is a promise the workspace inbox read waits on: a slow read for the repaint race.
function organizations({ decide, calls, gate }) {
const LIST = [{ id: 'acme', label: 'Acme Studio', theme: 'cobalt', busHealthy: true }];
const inbox = [{ id: DECISION, question: 'Ship the hero?', class: 'gated', blocking: false, raised_by_role: 'coder', at: new Date(Date.now() - 600000).toISOString(), options: [{ key: 'yes', text: 'Ship it' }, { key: 'no', text: 'Hold' }] }];
const reads = { inbox: async () => inbox, agents: async () => [], 'thread.claims': async () => [], tasks: async () => [], usage: async () => ({}), limits: async () => ({}), decisions: async () => [] };
const reads = { inbox: async () => { gate.reads++; await gate.held; return inbox; }, agents: async () => [], 'thread.claims': async () => [], tasks: async () => [], usage: async () => ({}), limits: async () => ({}), decisions: async () => [] };
// The model name picks the bus answer: a refusal before the decision exists, a lost reply, or a hire.
const decisionWrite = async (verb, args, ctx) => {
calls.push({ verb, args, ctx });
@@ -44,14 +45,16 @@ function organizations({ decide, calls }) {
}
async function setup(t, { decide = true, viewport = [1440, 900] } = {}) {
const calls = [];
const server = await startServer({ port: 0, sso: createDevOwner(), organizations: organizations({ decide, calls }), log: () => {} });
const calls = [], gate = { held: null, reads: 0 };
const server = await startServer({ port: 0, sso: createDevOwner(), organizations: organizations({ decide, calls, gate }), log: () => {} });
t.after(() => close(server));
const b = await browser({ machine: false }); t.after(() => b.close());
await b.viewport(...viewport);
const base = `http://127.0.0.1:${server.address().port}`;
await b.navigate(`${base}/#/orgs/acme/inbox`);
return { b, calls, wait: waitFor(b), text: sel => b.evaluate(`document.querySelector(${JSON.stringify(sel)})?.innerText ?? null`) };
// hold() makes the next workspace inbox reads wait until the returned release() is called.
const hold = () => { let release; gate.held = new Promise(r => { release = r; }); return () => { gate.held = null; release(); }; };
return { b, calls, gate, hold, wait: waitFor(b), text: sel => b.evaluate(`document.querySelector(${JSON.stringify(sel)})?.innerText ?? null`) };
}
// MOSAIC_UX_SHOTS=<dir> also saves light and dark shots; `at` is the element centred in view.
const shots = async (b, name, width, at) => {
@@ -121,6 +124,41 @@ test('D4 a poll repaint of the inbox keeps the hire draft, focus and caret', { t
assert.equal(await b.evaluate('document.querySelector("[data-hire-field=reason]").value'), 'Need a coder');
});
// Review P2: the form is built after the workspace read, so what lands while the read is slow survives
// the repaint: typing into the draft, and the status of a submit that resolves during the read.
test('D4 a slow inbox read does not paint an older hire draft over typing done during the read', { timeout: 120000 }, async t => {
const { b, gate, hold, wait } = await setup(t);
await wait('document.querySelector("#hire-start-form")');
await fill(b, { name: 'sc' });
const release = hold(), before = gate.reads;
await b.evaluate('window.__marker = document.querySelector("[data-ws-inbox]"); document.dispatchEvent(new CustomEvent("mosaic-workspace-render"))');
for (let i = 0; i < 200 && gate.reads === before; i++) await new Promise(r => setTimeout(r, 30));
assert.ok(gate.reads > before, 'the repaint read reached the bus and is held');
await fill(b, { name: 'scout', reason: 'Typed during the read' });
release();
await wait('document.querySelector("[data-ws-inbox]") !== window.__marker && document.querySelector("#hire-start-form")');
assert.deepEqual(await b.evaluate('["name","reason"].map(k => document.querySelector("[data-hire-field=" + k + "]").value)'), ['scout', 'Typed during the read']);
});
test('D4 a hire answer that arrives during a slow inbox read keeps its status after the repaint', { timeout: 120000 }, async t => {
const { b, calls, gate, hold, wait } = await setup(t);
await wait('document.querySelector("#hire-start-form")');
await b.evaluate('document.querySelector("[data-hire-load]").click()');
await wait('document.querySelector("[data-hire-field=template] option[value=coder]")');
await fill(b, { name: 'scout', template: 'coder', harness: 'pi', model: 'gone-model', reason: 'Need a coder' });
const release = hold(), before = gate.reads;
await b.evaluate('window.__marker = document.querySelector("[data-ws-inbox]"); document.dispatchEvent(new CustomEvent("mosaic-workspace-render"))');
for (let i = 0; i < 200 && gate.reads === before; i++) await new Promise(r => setTimeout(r, 30));
assert.ok(gate.reads > before, 'the repaint read reached the bus and is held');
await b.evaluate('document.querySelector("#hire-start-form").requestSubmit()');
await wait('document.querySelector("#hire-start-status code")');
release();
await wait('document.querySelector("[data-ws-inbox]") !== window.__marker && document.querySelector("#hire-start-form")');
assert.equal(await b.evaluate('document.querySelector("#hire-start-status code")?.textContent ?? null'), 'model-provider-unavailable');
assert.match(await b.evaluate('document.querySelector("#hire-start-status").innerText'), /Settings > Model proxy/);
assert.equal(calls.filter(c => c.verb === 'hire.start.console').length, 1);
});
test('D4 without decision answers (no --send) the org-mode inbox shows no hire form', { timeout: 120000 }, async t => {
const { b, calls, wait } = await setup(t, { decide: false });
await wait('document.querySelector("[data-ws-inbox] [data-ws-item]")');