fix(webui): a triage reply settles its entry only when it is the runner's RESULT answer; a progress note that names the message leaves it queued, so a session that dies after the note still reports it unanswered (#1873, lane triage-p3s)

This commit is contained in:
jason.woltje committed 2026-11-18 10:52:53 -06:00
1 parent 4b5d027361
commit eb1146ebad
3 files changed
+42 -13

No files matched your search

+14 -9
View File
@@ -75,14 +75,15 @@ const ENV_VALUE_MAX = 4096;
const HARNESS_ENV_MAX = 64;
// Refused in harnessEnv even when the harness module declares them: the runner's own MOSAIC_*
// values, loader, libc and interpreter hooks, the shell's start files, a tool's config directory
// and the founder's, an askpass program, a CA bundle or a base URL. A provider name (every ANTHROPIC_* among them) goes through route env or nowhere.
// and the founder's, an askpass program, a CA bundle or a base URL, Lua's start code, curl's config
// home and a TLS key log. A provider name (every ANTHROPIC_* among them) goes through route env or nowhere.
const REFUSED_PREFIX = /^(MOSAIC_|NODE_|LD_|DYLD_|PYTHON|BASH_|GIT_|MALLOC_|NPM_CONFIG_|XDG_)/;
const REFUSED_SUFFIX = /_(DIR|CONF|CONFIG|ASKPASS|CA_BUNDLE|BASE_URL)$/;
const REFUSED_NAMES = new Set([
"PATH", "HOME", "TMPDIR", "BASH_ENV", "ENV", "SSH_AUTH_SOCK", "SHELL", "SHELLOPTS", "BASHOPTS", "PS4", "IFS", "CDPATH",
"GLOBIGNORE", "PROMPT_COMMAND", "ZDOTDIR", "PERL5OPT", "PERL5LIB", "RUBYOPT", "RUBYLIB", "PERLLIB", "LESSOPEN", "LESSCLOSE", "HOSTALIASES", "HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY",
"GCONV_PATH", "GLIBC_TUNABLES", "LOCPATH", "OPENSSL_CONF", "OPENSSL_ENGINES", "OPENSSL_MODULES", "SSL_CERT_FILE", "SSL_CERT_DIR",
"JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "JDK_JAVA_OPTIONS",
"JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "JDK_JAVA_OPTIONS", "LUA_INIT", "CURL_HOME", "SSLKEYLOGFILE",
...FOUNDER_ENV,
]);
export const refusedHarnessName = (k) => typeof k !== "string" || !ENV_NAME.test(k) || REFUSED_PREFIX.test(k) || REFUSED_SUFFIX.test(k) || REFUSED_NAMES.has(k) || isProviderVariable(k);
@@ -175,8 +176,9 @@ function sameCap(a, b) {
return timingSafeEqual(Buffer.from(a), Buffer.from(b));
}
// The relay server. `onSend(body)` keeps a human-bound send; `take()` returns the queued owner
// messages; `read(id)` drops one that was answered.
// The relay server. `onSend({ body, in_reply_to, result })` keeps a human-bound send, `result` true
// only for class RESULT, the class the runner gives its answer to a turn; `take()` returns the
// queued owner messages; `read(id)` drops one that was answered.
export function createRelay({ socket, cap, take, read, onSend, log = () => {} }) {
const answer = (conn, value) => { try { conn.end(JSON.stringify(value) + "\n"); } catch {} };
const refuse = (conn) => answer(conn, { ok: false, error: RELAY_REFUSED, reason: "the Triage host answers only a message to the person" });
@@ -203,7 +205,7 @@ export function createRelay({ socket, cap, take, read, onSend, log = () => {} })
if (verb === "message.read") { read(args.id); return answer(conn, { ok: true, result: {} }); }
if (verb === "message.send" && args.to === "human" && typeof args.body === "string" && args.body.length <= 32768) {
// Only an id the host issued is kept. The model writes this field, and the transcript serves it.
onSend({ body: args.body, in_reply_to: typeof args.in_reply_to === "string" && OWNER_ID.test(args.in_reply_to) ? args.in_reply_to : null });
onSend({ body: args.body, in_reply_to: typeof args.in_reply_to === "string" && OWNER_ID.test(args.in_reply_to) ? args.in_reply_to : null, result: args.class === "RESULT" });
return answer(conn, { ok: true, result: { id: `triage-${randomBytes(6).toString("hex")}` } });
}
} catch (e) {
@@ -380,12 +382,15 @@ export function createTriageHost({ dataRoot, route = null, readSnapshot = async
const i = queue.findIndex((m) => m.id === id);
if (i >= 0) queue.splice(i, 1);
},
// A reply that names a queued message answers it: the message leaves the queue here, so a
// session that ends before its message.read leaves no "unanswered" line under an answer.
onSend: ({ body, in_reply_to }) => {
// An answer (class RESULT) that names a queued message answers it: the message leaves the queue
// here, so a session that ends before its message.read leaves no "unanswered" line under an
// answer. A note in any other class stays in the transcript but leaves the message queued, so
// a session that ends after a progress note still gets the "unanswered" line. The model's tool
// can also pick class RESULT; such a note settles the message as the runner's answer would.
onSend: ({ body, in_reply_to, result }) => {
const { text, cards, dropped } = extractCards(body, orgIds(), { devOwner: devOwner === true });
append({ at: now().toISOString(), from: "triage", text, cards, dropped, ...(in_reply_to ? { in_reply_to } : {}) });
const i = in_reply_to ? queue.findIndex((m) => m.id === in_reply_to) : -1;
const i = in_reply_to && result === true ? queue.findIndex((m) => m.id === in_reply_to) : -1;
if (i >= 0) queue.splice(i, 1);
},
log,
+7 -2
View File
@@ -6,7 +6,8 @@
// CARDS answer a reply with a cards fence: one valid card, one unknown step
// TOOL <to> call send_message to <to> through the tool socket and answer the raw reply
// SLEEP hang until killed
// REPLY-SLEEP send the person an answer to this message through the tool socket, then hang until killed
// REPLY-SLEEP send the person an answer (class RESULT) to this message through the tool socket, then hang until killed
// NOTE-SLEEP send the person a progress note (class INFO) on this message through the tool socket, then hang until killed
// anything else answer "echo: <body>"
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { connect } from "node:net";
@@ -57,7 +58,11 @@ if (body === "PROBE") {
process.stdout.write(await toolCall("send_message", { to: body.slice(5), body: "from the tool", class: "INFO" }));
} else if (body === "REPLY-SLEEP") {
const id = request.match(/^Message (\S+) from /m)?.[1];
await toolCall("send_message", { to: "human", body: "answered early", class: "INFO", in_reply_to: id });
await toolCall("send_message", { to: "human", body: "answered early", class: "RESULT", in_reply_to: id });
setInterval(() => {}, 1000);
} else if (body === "NOTE-SLEEP") {
const id = request.match(/^Message (\S+) from /m)?.[1];
await toolCall("send_message", { to: "human", body: "still looking", class: "INFO", in_reply_to: id });
setInterval(() => {}, 1000);
} else if (body === "SLEEP") {
setInterval(() => {}, 1000);
+21 -2
View File
@@ -65,13 +65,20 @@ test("the relay refuses every verb but a message to the person, and any call wit
assert.deepEqual(await client.call("message.receive"), [{ id: "owner-0123456789ab", from_role: "human", class: "REQUEST", body: "hello", at: "2026-11-16T12:00:00.000Z" }]);
assert.match((await client.call("message.send", { to: "human", body: "answer", class: "RESULT", in_reply_to: "owner-0123456789ab" })).id, /^triage-/);
await client.call("message.read", { id: "owner-0123456789ab" });
assert.deepEqual(sent, [{ body: "answer", in_reply_to: "owner-0123456789ab" }]);
assert.deepEqual(sent, [{ body: "answer", in_reply_to: "owner-0123456789ab", result: true }]);
assert.deepEqual(read, ["owner-0123456789ab"]);
// Only the class RESULT send, the runner's answer to its turn, says the message is answered. A note
// in any other class, or with no class, is kept but does not.
for (const cls of ["INFO", "REQUEST", "result", undefined, 7]) {
sent.length = 0;
await client.call("message.send", { to: "human", body: "note", class: cls, in_reply_to: "owner-0123456789ab" });
assert.deepEqual(sent, [{ body: "note", in_reply_to: "owner-0123456789ab", result: false }], String(cls));
}
// The model writes in_reply_to. Anything but an id the host issued is dropped, never stored.
for (const bad of ["<img src=x onerror=1>", "owner-1", "owner-0123456789ab\u202e", "owner-0123456789abc", "x".repeat(60000)]) {
sent.length = 0;
await client.call("message.send", { to: "human", body: "b", in_reply_to: bad });
assert.deepEqual(sent, [{ body: "b", in_reply_to: null }], bad.slice(0, 24));
assert.deepEqual(sent, [{ body: "b", in_reply_to: null, result: false }], bad.slice(0, 24));
}
const refused = [
["decision.raise", { kind: "hire", body: "x" }], ["event.emit", { kind: "action.allowed", body: {} }],
@@ -222,6 +229,7 @@ test("fence 1: a harnessEnv name the host refuses is refused even when the harne
"LOCPATH", "MALLOC_CHECK_", "OPENSSL_CONF", "SSL_CERT_FILE", "ZDOTDIR", "PROMPT_COMMAND", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "NPM_CONFIG_PREFIX",
"CLAUDE_CONFIG_DIR", "XDG_DATA_HOME", "ANY_CONF", "ANY_CONFIG", "PERLLIB", "LESSOPEN", "LESSCLOSE", "HOSTALIASES",
"SSH_ASKPASS", "SUDO_ASKPASS", "CURL_CA_BUNDLE", "REQUESTS_CA_BUNDLE", "OPENAI_BASE_URL", "ANY_BASE_URL",
"LUA_INIT", "CURL_HOME", "SSLKEYLOGFILE",
]) assert.equal(refusedHarnessName(name), true, name);
for (const name of ["FAKE_OK", "PI_MODEL", "TRIAGE_PROBE"]) assert.equal(refusedHarnessName(name), false, name);
});
@@ -635,6 +643,17 @@ test("a reply that names its message answers it: a session killed after replying
assert.deepEqual((await h.state()).transcript.filter((e) => e.from === "host"), []);
});
test("a progress note that names its message does not answer it: a session killed after the note leaves an unanswered line", { skip, timeout: 120000 }, async (t) => {
const root = scratch();
const { h } = host(t, root, { route: stubRoute(root) });
const sent = await h.message("NOTE-SLEEP");
const [noted] = await repliesOf(h, 1);
assert.deepEqual([noted.text.replace(/\n\n.*$/s, ""), noted.in_reply_to], ["still looking", sent.id]);
process.kill(-h.pid, "SIGKILL");
const [note] = await repliesOf(h, 1, "host");
assert.deepEqual([note.in_reply_to, note.text], [sent.id, UNANSWERED]);
});
test("a message the session never read gets a host line when it ends and leaves the queue", { skip, timeout: 120000 }, async (t) => {
const root = scratch();
const { h, dataRoot } = host(t, root, { route: stubRoute(root) });