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
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
fix(webhook): dispatch through atomic addTask to avoid stale-ledger overwrite
Zhen Luo3f1878b58b0e
diff --git a/src/main/index.ts b/src/main/index.tsindex 45d288e4..0a7f0a83 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -1680,8 +1680,6 @@ function dispatchWebhookWork(arg: {origin: 'webhook' | 'org';}): boolean {try {- const ledger = hive.tasks() as { tasks?: HiveTask[] };- const existing = Array.isArray(ledger?.tasks) ? ledger.tasks : [];const card: HiveTask = {id: arg.taskId,title: arg.title,@@ -1692,7 +1690,11 @@ function dispatchWebhookWork(arg: {createdAt: new Date().toISOString(),...(arg.tokenHash ? { webhook: { tokenHash: arg.tokenHash } } : {})};- hive.writeTasks([...existing, card]);+ // addTask appends against the latest on-disk ledger and is idempotent by task+ // id, so a concurrent card writer (Slack, god, voice, another webhook) can't+ // have its card lost to our stale whole-ledger overwrite. (writeTasks(...existing)+ // recreated exactly that race.) A fresh taskId never collides, so this always adds.+ hive.addTask(card);} catch (e) {console.error('[webhook] could not create task card:', e instanceof Error ? e.message : e);return false;diff --git a/test/hive-task-mutation.test.cjs b/test/hive-task-mutation.test.cjsindex 3c94ce07..d8568366 100644--- a/test/hive-task-mutation.test.cjs+++ b/test/hive-task-mutation.test.cjs@@ -108,3 +108,18 @@ test('renderer task actions never send a whole stale ledger back to main', () =>assert.match(sources[2], /hiveDeleteTask\s*\(/);assert.match(sources[3], /hiveAddTask\s*\(/);});++test('webhook dispatch appends via atomic addTask, not a stale whole-ledger rewrite', () => {+ const root = path.resolve(__dirname, '..');+ const main = fs.readFileSync(path.join(root, 'src/main/index.ts'), 'utf8');+ const fn = main.slice(main.indexOf('function dispatchWebhookWork'),+ main.indexOf('function handleWebhookMessage'));+ // The card must be appended through hive.addTask(card) — which reads the LATEST+ // on-disk ledger and is idempotent by task id — never through a re-read of a+ // snapshot the caller happened to hold, which would overwrite a concurrently+ // added card (the 2026-08-15 regression this suite guards).+ assert.match(fn, /hive\.addTask\s*\(card\)/,+ 'dispatchWebhookWork must add the card via the atomic addTask');+ assert.doesNotMatch(fn, /writeTasks\s*\(\[\s*\.\.\.existing/,+ 'dispatchWebhookWork must not rebuild a stale whole-ledger snapshot');+});