Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

review: leave the worker's own work order out of the report to god; one line per subject

Gastón Péchieud59155dc5719
diff --git a/src/main/hive.ts b/src/main/hive.ts
index efbf8062..9830f6bd 100644
--- a/src/main/hive.ts
+++ b/src/main/hive.ts
@@ -60,8 +60,10 @@ export interface SettledInbox {
/** Unread messages left pending because they arrived after the cut-off. */
kept: number;
/** The filed messages that asked for something — their sender never gets
- * an answer, and deserves to hear so instead of waiting on a dead worker. */
- unanswered: Array<{ id: string; act: MessageAct; from: string; subject: string }>;
+ * an answer, and deserves to hear so instead of waiting on a dead worker.
+ * `conversation` lets the caller tell the worker's own work order (which
+ * it just completed) from a genuinely unanswered request. */
+ unanswered: Array<{ id: string; act: MessageAct; from: string; subject: string; conversation: string }>;
}
export interface HiveMessage {
@@ -1066,10 +1068,13 @@ export class HiveManager {
let at = Date.parse(msg.created_at ?? '');
if (!Number.isFinite(at)) { try { at = statSync(fp).mtimeMs; } catch { at = 0; } }
if (at > before) { out.kept++; continue; }
- try { renameSync(fp, join(done, f)); out.moved++; } catch { continue; /* skip; a later settle retries */ }
+ // A rename that fails (EPERM on a file another process holds) leaves the
+ // message where it was — still pending, exactly the pre-settle state.
+ try { renameSync(fp, join(done, f)); out.moved++; } catch { continue; }
if (msg.act === 'request' || msg.act === 'query') {
out.unanswered.push({
- id: msg.id ?? f, act: msg.act, from: msg.from ?? 'unknown', subject: msg.subject ?? ''
+ id: msg.id ?? f, act: msg.act, from: msg.from ?? 'unknown', subject: msg.subject ?? '',
+ conversation: msg.conversation ?? ''
});
}
}
diff --git a/src/main/index.ts b/src/main/index.ts
index df333c9a..b5d80946 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -4901,8 +4901,15 @@ async function ephemeralWorkerTick(): Promise<void> {
const settled = hive.settleInbox(workerId, doneAt);
if (settled.moved > 0) console.log(`[worker] ${workerId}: filed ${settled.moved} unread inbox message(s) under inbox/.done`);
if (settled.kept > 0) console.log(`[worker] ${workerId}: left ${settled.kept} message(s) that arrived after its done signal pending`);
- if (settled.unanswered.length > 0) {
- const lines = settled.unanswered.map((m) => `- ${m.act} ${m.id} from ${m.from}: "${m.subject}"`);
+ // The worker's own work order is dispatched in conversation
+ // `worker-<reqId>` (processSpawnRequest) and is exactly what it just
+ // completed: reporting it "filed unread" on every release would cost
+ // god a turn each time for nothing. Only OTHER requests/queries count.
+ // Subjects are agent-written: keep each on its own line.
+ const unanswered = settled.unanswered.filter((m) => m.conversation !== `worker-${rec.reqId}`);
+ if (unanswered.length > 0) {
+ const oneLine = (s: string): string => s.replace(/[\r\n]+/g, ' ');
+ const lines = unanswered.map((m) => `- ${m.act} ${oneLine(m.id)} from ${oneLine(m.from)}: "${oneLine(m.subject)}"`);
informGod(
`[worker released — mail filed unread] ${workerId}`,
`Worker ${workerId} signaled done and was released. These messages were still unread in its inbox and were filed under inbox/.done without an answer:\n`
diff --git a/test/worker-inbox-settle.test.cjs b/test/worker-inbox-settle.test.cjs
index e980844d..d9b828bd 100644
--- a/test/worker-inbox-settle.test.cjs
+++ b/test/worker-inbox-settle.test.cjs
@@ -57,6 +57,8 @@ test('settling files every unread message under inbox/.done and names the reques
assert.deepEqual(settled.unanswered.map((m) => [m.act, m.from, m.subject]), [['request', 'god-1', 'Phyllis']],
'the request is reported (its sender is owed an answer); the inform is not');
assert.ok(settled.unanswered[0].id, 'the report carries the message id so god can find it');
+ assert.equal(typeof settled.unanswered[0].conversation, 'string',
+ 'and the conversation, so the release path can leave the worker\'s own work order out of the report');
assert.deepEqual(hive.inbox('worker-phyllis'), [], 'nothing reads as pending any more');
assert.deepEqual(jsonFiles(path.join(inboxDir(hive, 'worker-phyllis'), '.done')), before,
@@ -126,6 +128,9 @@ test('the ephemeral-worker tick settles the inbox on the done path, up to the do
assert.ok(settle < kill, 'the settle happens before the PTY is killed (the worker dir still exists either way, but the order keeps the log readable)');
const report = source.indexOf('settled.unanswered', settle);
assert.ok(report > 0 && report < kill, 'the filed requests/queries are reported to god before the kill');
+ const ownOrder = source.indexOf('m.conversation !== `worker-${rec.reqId}`', settle);
+ assert.ok(ownOrder > 0 && ownOrder < kill,
+ 'the worker\'s own work order (dispatched in conversation worker-<reqId>) is left out of the report — it is what the worker just completed');
assert.ok(source.indexOf('informGod(', report) < kill, 'the report goes through informGod');
assert.equal(source.indexOf('hive.settleInbox', kill), -1, 'neither the token-cap nor the idle reap settles — they never signaled completion');
});