Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

[bug] MergeSettings leaks __merge append annotations into settings.json when the…

Open udeepji opened this issue 1 month ago • 3 comments

What happened

MergeSettings leaks __merge append annotations into settings.json when the system layer lacks the parent key (hooks since 8.761.0); SessionStart and UserPromptSubmit get ignored by Claude Code and the self-heal hook cannot run

Summary

MergeSettings leaks __merge: "append" annotations into settings.json when the system layer lacks the parent key

Summary

Since 8.761.0, settings.system.json no longer ships a hooks key (it is installer-owned). When the user overlay has hooks.<Event> written as { "__merge": "append", "values": [...] }, the annotation object is copied verbatim into the generated settings.json. Claude Code then rejects the event and ignores all of its hooks:

Settings (settings.json › hooks.SessionStart): Hook event "SessionStart" must be an array of matchers; received object. This entry was ignored.

If the affected event is SessionStart, the problem cannot heal itself, because the SettingsBackport + MergeSettings regeneration command is itself a SessionStart hook.

Root cause

  1. MergeSettings.ts, mergeSettings. The object-recursion branch requires both system and user to be objects. When the system value is undefined and the user value is an object, it falls through to cloneJsonValue(user) and never recurses. So nested annotations under any system-absent parent key are never resolved. (applyArrayMerge handles systemValue === undefined correctly, but it is never reached.)
  2. SettingsBackport.ts, planArrayBackport. When the system layer has no array at a path, systemArr is [], so isPrefix([], after) is always true and every drifted array is written back as { "__merge": "append", "values": after }. Any direct append to settings.json (installer, a third-party tool adding a hook) therefore produces the annotation that (1) then leaks. Backport's post-write verification does catch the mismatch and exits 1, but only after the overlay has already been written.

Reproduce

import { mergeSettings } from "${LIFEOS_DIR}/TOOLS/MergeSettings.ts";
const out = mergeSettings(
  { env: {} },                                    // system: no `hooks`
  { hooks: { SessionStart: { __merge: "append", values: [{ hooks: [] }] } } },
);
console.log(Array.isArray(out.hooks.SessionStart)); // false: annotation leaked

Control: pass { env: {}, hooks: {} } as the system layer and it returns true.

Suggested fix

  • In mergeSettings, when user is an object and system is undefined, recurse as if system were {}. That way annotations are always consumed, matching the header's contract that annotations never reach the output. Tested in memory: the output equals hand-unwrapping the annotations, and no __merge remains.
  • In planArrayBackport, write a plain array (not an append annotation) when the system layer has no array at that path.
  • Optionally, run Backport's verification before the atomic write so that a failing plan never lands in the overlay.

Workaround

Replace each { "__merge": "append", "values": X } under hooks in the user overlay with X, then rerun MergeSettings.ts --output once by hand.

Environment

LifeOS 8.761.0, Claude Code on macOS.

Details

  • Kind: bug
  • LifeOS version: 8.761.0

Filed with the LifeOS /feedback command. The reporter approved this exact text before it was sent; paths, secrets and personal details were stripped locally.

udeepji avatar Oct 31 '26 14:10 udeepji

[bug] MergeSettings leaks __merge annotations under a key settings.system.json lacks

What happened

MergeSettings leaks __merge annotations under a key settings.system.json lacks

Summary

Confirming on a second 8.761.0 install: same symptom (SessionStart ignored, so the backport+merge hook never ran), same repro, system layer with no hooks key.

Applied the suggested mergeSettings change locally (absent system key treated as {} and recursed). Checked: the annotation resolves to the array, a nested __merge: remove still drops its key, an invalid annotation still throws, a scalar system value is still replaced by an object user value, and a full regeneration against the real sources differs from the previous output only in hooks.SessionStart becoming an array.

Details

  • Kind: bug
  • LifeOS version: 8.761.0

Filed with the LifeOS /feedback command. The reporter approved this exact text before it was sent; paths, secrets and personal details were stripped locally.

dsather avatar Nov 03 '26 18:11 dsather

Confirming on 8.761.0 (macOS, Claude Code 2.1.316). Here the trigger was a third-party integration that added one hooks.SessionStart entry straight to settings.json. On the next SessionStart, SettingsBackport rewrote the overlay's SessionStart as an append annotation. Verification then failed ($.hooks.SessionStart) and MergeSettings refused to write. In my case that refusal kept the annotation out of settings.json, but settings.json stopped regenerating on every start after that.

Minimal repro:

import { mergeSettings } from "./LIFEOS/TOOLS/MergeSettings.ts";
const user = { hooks: { SessionStart: { __merge: "append", values: [{ matcher: "", hooks: [] }] } } };
console.log(Array.isArray(mergeSettings({}, user).hooks.SessionStart)); // false

Workaround that held: turn the overlay entry back into a plain array, move the stale MEMORY/STATE/settings-merge-snapshot.json aside, check that the merge output equals the live settings.json, then run MergeSettings once. Related: #2561.

mj-deving avatar Nov 04 '26 13:11 mj-deving

[!NOTE] 🤖 Kai (AI assistant) responding on behalf of Daniel Miessler

Thanks @udeepji, and @dsather and @mj-deving for confirming it. The leak itself was already fixed in local source: an overlay-only object now runs through the same key loop, so an append annotation under a key that settings.system.json lacks resolves to a plain array and never reaches settings.json. On top of that, an append annotation under hooks now appends to the installed hooks rather than standing alone. Both land in the next release.

danielmiessler avatar Nov 06 '26 13:11 danielmiessler