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(config): notify with the config as read, not as written
HundredBillion34adb6d209de
diff --git a/src/main/config.ts b/src/main/config.tsindex d0f4255f..6cd130f6 100644--- a/src/main/config.ts+++ b/src/main/config.ts@@ -646,11 +646,19 @@ function persistConfig(next: HarnessConfig): HarnessConfig {const p = configPath();mkdirSync(dirname(p), { recursive: true });writeFileSync(p, JSON.stringify(next, null, 2), 'utf8');+ // Subscribers get the config in the same shape `readConfig` hands out, NOT the+ // object we just wrote. They are the second source feeding a renderer that also+ // calls config:get, and a patch touching one nested key persists a half-filled+ // sub-object — `withTriggerDefaults` is what deep-fills it on the way out, so+ // skipping it here would let a consumer read `undefined` from a trigger it had+ // read a number from a moment earlier. The migration is deliberately not run:+ // it persists, and it has already been applied to the config this patch built on.+ const view = normalizeStoredHomes(withTriggerDefaults({ ...DEFAULTS, ...next }));// A listener is a renderer send, which can fail while a window is closing.// The config is already on disk by this point, so a throwing subscriber must// neither fail the write for its caller nor starve the subscribers after it.for (const listener of configWriteListeners) {- try { listener(next); } catch { /* a broken listener is not a failed write */ }+ try { listener(view); } catch { /* a broken listener is not a failed write */ }}return next;}diff --git a/test/config-write-notify.test.cjs b/test/config-write-notify.test.cjsindex 9a59c704..6460eedc 100644--- a/test/config-write-notify.test.cjs+++ b/test/config-write-notify.test.cjs@@ -23,18 +23,25 @@ const { writeConfig, readConfig, onConfigWritten, setAgentTokenCap, resetConfigtest.after(() => fs.rmSync(userData, { recursive: true, force: true }));+// The app has a config on disk and reads it during start-up, which is what runs+// the one-shot trigger migration. Reproduce both here before any test subscribes,+// so these compare a write against a settled config rather than racing the+// migration — on a bare directory readConfig short-circuits and never runs it.+writeConfig({});+readConfig();++test('a config write notifies subscribers with the persisted config', () => {const seen = [];const off = onConfigWritten((next) => seen.push(next));- const returned = writeConfig({ orchestratorMaySpawn: true });+ writeConfig({ orchestratorMaySpawn: true });// A single logical write can persist more than once — reading the config runs- // any pending migration, which persists in its own right. The contract is- // that subscribers end up holding what the caller was handed back, not that- // exactly one notification arrives.+ // any pending migration, which persists in its own right. The contract is what+ // subscribers end up holding, not that exactly one notification arrives.assert.ok(seen.length >= 1);- assert.deepEqual(seen[seen.length - 1], returned);+ assert.deepEqual(seen[seen.length - 1], readConfig());assert.equal(seen[seen.length - 1].orchestratorMaySpawn, true);off();});@@ -47,10 +54,10 @@ test('a token-cap write notifies too, not just writeConfig', () => {const seen = [];const off = onConfigWritten((next) => seen.push(next));- const returned = setAgentTokenCap('jim', 100);+ setAgentTokenCap('jim', 100);assert.ok(seen.length >= 1);- assert.deepEqual(seen[seen.length - 1], returned);+ assert.deepEqual(seen[seen.length - 1], readConfig());assert.equal(seen[seen.length - 1].agentTokenCaps.jim, 100);off();});@@ -95,3 +102,18 @@ test('a listener that throws neither fails the write nor starves the next listenassert.ok(reached.length >= 1);offBad(); offGood();});++// The renderer keeps one `config` in state fed from two sources: config:get and+// this notification. If they disagree in shape, a consumer reads a deep-filled+// object one moment and a half-filled one the next. A patch that touches part of+// a trigger is where that bites, because the merge on the way in is one level+// deep (see withTriggerDefaults).+test('subscribers receive the same shape a config read returns', () => {+ const seen = [];+ const off = onConfigWritten((next) => seen.push(next));++ writeConfig({ contextTrigger: { compact: { enabled: true } } });++ assert.deepEqual(seen[seen.length - 1], readConfig());+ off();+});