Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

remove the unreachable legacy .icloud placeholder probe from mortalLoomStore

[._.]/ Adam Eivy87579f328230
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index d2905000a0..8e65dd2379 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -176,3 +176,7 @@
- **Synchronous Codex TUI stages stay single-agent.** A machine-consumed pipeline prompt could inherit Codex's general multi-agent feature, fan out work it never needed, and then spend its entire timeout waiting on those agents before repeating the same request on a fallback provider. The one-shot TUI runner now disables that feature only for Codex prompt calls; long-running CoS coding agents keep their configured collaboration posture, and other TUI providers are unchanged.
- **A foundation repair no longer sends the entire episode list, and no longer takes the whole autopilot run down with it when it fails.** The foundation-quality gate's repair prompt carried the full synopsis-level plan — every volume *and* every episode synopsis — with no size limit, so it grew with the series forever. On a long-running series that section reached 28KB of a 35KB prompt, and the primary AI provider burned its entire ten-minute timeout on it without producing a single word; the fallback provider then repeated the same request and burned ten more. Twenty minutes spent, nothing written, and the whole autonomous run ended in an error that discarded every step it had already completed. The repair prompt is now bounded the same way the judge prompt beside it always was: the plan spine (arc, volumes, authored character arcs) is always sent in full, and the episode list fills the remaining budget by whole lines, oldest first, saying how many were left out — so the model reads a coherent outline instead of one cut mid-sentence. And a repair whose AI call fails outright now **pauses** the run rather than erroring it: the failure is a provider timeout or a dead CLI, not a verdict on your story, so the run keeps every step it finished, tells you which provider failed, and resumes from where it stopped. Autopilot also stopped quietly losing the reason it paused — "nothing to fix", "budget reached" and this new "provider failed" were all being emitted and then dropped before they reached the screen, leaving a bare "Paused" with no explanation; each now carries its own badge.
+
+## Internal
+
+- **[issue-3716] Dropped the unreachable legacy `.icloud` placeholder probe from the MortalLoom store.** macOS has two possible representations for an iCloud file evicted by "Optimize Mac Storage": the modern APFS *dataless* vnode (path stays put, `stat` reports a real size with zero blocks) and the pre-APFS `.<name>.icloud` sibling stub that *replaces* the file. `mortalLoomStore` guarded both — the stub probe added speculatively alongside a real dataless incident, never observed firing — and the Obsidian vault adapter guarded only the first, so `createNote` would have written a fresh note beside a stub-shadowed one. Before copying the probe into a second adapter, the representation was measured: across 223 iCloud ubiquity containers holding 373 evicted files (macOS 26, APFS), every evicted file was dataless and zero `.icloud` placeholders existed anywhere under the iCloud root or the home directory. The probe is dead code, so it was deleted rather than duplicated — an absent path is now unambiguously absent on both read and write, and `updateStore`'s overwrite guard makes one `existsSync` call instead of three. The finding, and where the probe would have to go if a placeholder is ever actually observed, is recorded in `server/lib/icloudFile.js`. No user-visible behavior change: refusing to overwrite an evicted (dataless) store, and the on-demand `brctl download` pre-warm, are untouched.
diff --git a/server/lib/icloudFile.js b/server/lib/icloudFile.js
index 25d197f5c0..d916efa786 100644
--- a/server/lib/icloudFile.js
+++ b/server/lib/icloudFile.js
@@ -77,6 +77,27 @@
* persistent read/write outage for that one file, not corruption. Callers that
* must degrade gracefully (a vault walk) skip the file and report a skipped
* count; callers that must not silently succeed (a store write) fail loudly.
+ *
+ * ## There is only ONE representation to screen for (measured, #3716)
+ *
+ * macOS' pre-APFS eviction mechanism did not leave the path in place: it
+ * *replaced* `Foo.json` with a hidden sibling `.Foo.json.icloud` stub, so
+ * `existsSync(Foo.json)` reported false while real data sat there offloaded.
+ * That representation needs a completely different guard — an `existsSync` on
+ * the sibling — because the dataless `stat()` screen above can never see it.
+ *
+ * It does not occur. Measured on macOS 26 (Darwin 25.5, APFS): across 223 iCloud
+ * ubiquity containers holding 373 evicted files, **every** evicted file was
+ * dataless and **zero** `.icloud` placeholders existed anywhere under the iCloud
+ * root (or under the home dir at large). `mortalLoomStore` used to carry a
+ * placeholder probe — added speculatively as belt-and-suspenders alongside a real
+ * *dataless* incident, never observed firing — and #3716 removed it rather than
+ * copying it into `obsidian.js` as a second unreachable branch.
+ *
+ * So: an absent path is genuinely absent, and ENOENT is a trustworthy "no file."
+ * If a placeholder is ever actually observed on a supported macOS, the probe
+ * belongs HERE as a shared helper wired into `mortalLoomStore.updateStore` and
+ * `obsidian.createNote` together — never in only one of them.
*/
import { readFile, stat } from 'fs/promises';
diff --git a/server/services/mortalLoomStore.js b/server/services/mortalLoomStore.js
index 2b85a06fad..5d32c43691 100644
--- a/server/services/mortalLoomStore.js
+++ b/server/services/mortalLoomStore.js
@@ -9,7 +9,7 @@
*/
import { homedir } from 'os';
-import { join, dirname, basename } from 'path';
+import { join } from 'path';
import { stat } from 'fs/promises';
import { existsSync } from 'fs';
import { randomUUID } from 'crypto';
@@ -137,22 +137,18 @@ function pinAgainstEviction(path) {
// === On-demand (blocking) materialization for the write path ===
-// macOS' older eviction mechanism renames `Foo.json` to a hidden
-// `.Foo.json.icloud` placeholder, after which `existsSync(Foo.json)` reports
-// false even though real data is sitting there evicted. Detecting the
-// placeholder lets updateStore() refuse to seed a fresh store on top of it
-// (which would shadow the real data) and materialize it instead. Modern macOS
-// uses dataless files (path stays present) so this is belt-and-suspenders, but
-// the silent-data-loss cost if it ever fires is exactly what this module's
-// overwrite guard exists to prevent.
-function icloudPlaceholderPath(path) {
- return join(dirname(path), `.${basename(path)}.icloud`);
-}
+// Eviction has exactly ONE representation this module has to handle: the modern
+// APFS dataless vnode, where the path stays present and `readIfMaterialized`'s
+// `stat()` screen catches it. This module used to also probe for macOS' pre-APFS
+// `.MortalLoom.json.icloud` sibling stub; #3716 measured that representation as
+// non-occurring and removed the probe — see the "only ONE representation"
+// section in server/lib/icloudFile.js. An absent path is therefore genuinely
+// absent here, safe to seed.
// Unlike the fire-and-forget pinAgainstEviction() at boot, the write path needs
// to KNOW an evicted file is materialized before deciding whether refusing to
// overwrite is warranted. `brctl download <path>` asks iCloud to materialize a
-// dataless (Optimize-Mac-Storage-evicted) file or an `.icloud` placeholder.
+// dataless (Optimize-Mac-Storage-evicted) file.
//
// CRITICAL: exit 0 means the download was ACCEPTED/QUEUED, NOT that the bytes are
// local. brctl can return 0 before materialization completes, and returns 0 even
@@ -162,9 +158,8 @@ function icloudPlaceholderPath(path) {
// keeps the caller's subsequent re-read safe is `readStoreAtPathResult`: it calls
// `readIfMaterialized`, which REJECTS rather than issuing a blocking read for a
// file it can't safely read — a still-dataless file rejects with
-// ICLOUD_NOT_MATERIALIZED (its `Stats.blocks` screen); an absent path shadowed by
-// a legacy `.icloud` placeholder surfaces as ENOENT — and `readStoreAtPathResult`
-// catches both and yields `store: null` (which `readStoreAtPath` unwraps). Either
+// ICLOUD_NOT_MATERIALIZED (its `Stats.blocks` screen) — and `readStoreAtPathResult`
+// catches that and yields `store: null` (which `readStoreAtPath` unwraps). Either
// way the store stays null and the caller refuses to overwrite, so a false-
// positive `true` from here can't truncate data. (It does not eliminate the
// bounded eviction race documented in `readIfMaterialized`, which can still
@@ -348,23 +343,18 @@ async function readStoreAtPathResult(path) {
// `brctl download` so the next cycle succeeds.
const raw = await withTransientRetry(() => readIfMaterialized(path, { label: 'MortalLoom store' })).catch((err) => {
if (err.code === ICLOUD_NOT_MATERIALIZED) {
- // Present but evicted — never a trustworthy empty. Same classification as
- // the legacy `.icloud` placeholder case below, so a strict read reports
+ // Present but evicted — never a trustworthy empty, so a strict read reports
// `unavailable` and updateStore's guard refuses to seed over real data.
console.warn(`⚠️ MortalLoom store evicted from local storage; skipping read until iCloud materializes it: ${path}`);
unreadable = true;
return null;
}
if (err.code === 'ENOENT') {
- // Genuinely absent — UNLESS a legacy `.MortalLoom.json.icloud` placeholder
- // shadows the real path, which means the store EXISTS but is offloaded under
- // macOS's older rename-based eviction (the case updateStore's overwrite
- // guard also checks). Treat that as present-but-unreadable so a strict read
- // refuses to report a trustworthy empty for a store it has not actually
- // read. This also covers an offload that races in after the read began.
- // Silent either way — a missing store is normal, not warn-worthy. The read
- // side never blocks on `brctl` to materialize (that stays updateStore's job).
- if (existsSync(icloudPlaceholderPath(path))) unreadable = true;
+ // Genuinely absent, and trustworthy as such: eviction cannot surface here.
+ // A dataless file keeps its path and rejects with ICLOUD_NOT_MATERIALIZED
+ // above, and the pre-APFS placeholder representation that WOULD read as
+ // ENOENT does not occur (#3716 — see server/lib/icloudFile.js). Silent —
+ // a missing store is normal, not warn-worthy.
return null;
}
// Any other error (EACCES/EIO/EAGAIN/EDEADLK/unknown errno) is a store we could
@@ -386,8 +376,8 @@ async function readStoreAtPathResult(path) {
/**
* Store object or `null` — the pre-#2742 shape, kept for callers (readStore,
* updateStore) that only need the parsed store and derive their own
- * absent-vs-unreadable handling (updateStore does its own existsSync +
- * placeholder check for the overwrite guard).
+ * absent-vs-unreadable handling (updateStore does its own existsSync check for
+ * the overwrite guard).
*/
async function readStoreAtPath(path) {
return (await readStoreAtPathResult(path)).store;
@@ -410,19 +400,18 @@ export async function updateStore(mutator) {
const path = await resolvePath();
let store = await readStoreAtPath(path);
// The overwrite guard is based solely on post-read state, not a pre-read
- // snapshot. readStoreAtPath returns null for four reasons; we only care
+ // snapshot. readStoreAtPath returns null for several reasons; we only care
// about the *currently observable* state when deciding whether it's safe
// to write:
- // (1) file does not exist now (and no `.icloud` placeholder shadows it) →
- // safe to seed a fresh store (whether it was absent the whole time,
- // disappeared mid-call, or never appeared in the first place).
+ // (1) file does not exist now → safe to seed a fresh store (whether it was
+ // absent the whole time, disappeared mid-call, or never appeared in the
+ // first place). An absent path is unambiguously absent: the only eviction
+ // representation that would hide real data behind a false `existsSync` is
+ // the pre-APFS `.icloud` placeholder, which does not occur (#3716).
// (2) file exists now but parsed to a non-plain-object value → unreadable
// (transient iCloud read failure, corrupt JSON, or unexpected shape
// like a top-level array which JSON.stringify would silently drop).
- // (3) the real path is absent but an `.icloud` placeholder is shadowing it
- // → the file was evicted under the legacy rename mechanism and real
- // data is sitting there unmaterialized; seeding fresh would bury it.
- // For (2) and (3) the most common cause on macOS is iCloud eviction
+ // For (2) the most common cause on macOS is iCloud eviction
// (Optimize-Mac-Storage made the file dataless and the sub-200ms transient
// retry isn't long enough to materialize it). Before refusing — which blocks
// the user's write — force a BLOCKING `brctl download` and re-read once. This
@@ -432,18 +421,15 @@ export async function updateStore(mutator) {
// survive to the throw. Without this guard, the iCloud transient-failure
// tolerance in readStoreAtPath would let updateStore silently truncate a
// momentarily unreadable iCloud file.
- const unsafeToSeed = existsSync(path)
- ? !isPlainObject(store)
- : existsSync(icloudPlaceholderPath(path));
+ const unsafeToSeed = existsSync(path) && !isPlainObject(store);
if (unsafeToSeed) {
// `materializeNow` resolving `true` only means brctl ACCEPTED the download
// request (exit 0), NOT that the bytes are local — see its docblock. Do NOT
// remove the re-read's screening on the strength of that `true`: `readStoreAtPath`
// → `readStoreAtPathResult` calls `readIfMaterialized`, which REJECTS instead of
// issuing a blocking read for a file it can't safely read — a still-dataless file
- // rejects on the `stat()` re-screen, an absent-but-placeholder-shadowed path
- // surfaces as ENOENT — and `readStoreAtPathResult` catches both and returns
- // `store: null`. Either way store stays null and we refuse to overwrite rather
+ // rejects on the `stat()` re-screen — and `readStoreAtPathResult` catches that
+ // and returns `store: null`. Either way store stays null and we refuse rather
// than reading blindly (which is what would risk stranding a threadpool slot).
const materialized = await materializeNow(path);
if (materialized) {
diff --git a/server/services/mortalLoomStore.test.js b/server/services/mortalLoomStore.test.js
index f65b951f9f..cca299c009 100644
--- a/server/services/mortalLoomStore.test.js
+++ b/server/services/mortalLoomStore.test.js
@@ -90,9 +90,9 @@ afterEach(() => {
});
describe('readStore', () => {
- it('returns null when the store is absent (readFile ENOENT, no placeholder)', async () => {
+ it('returns null when the store is absent (readFile ENOENT)', async () => {
readFileMock.mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }));
- existsResult = false; // no `.icloud` placeholder shadowing the path
+ existsResult = false;
const result = await store.readStore();
expect(result).toBeNull();
expect(console.warn).not.toHaveBeenCalled(); // a missing store is normal, not warn-worthy
@@ -189,7 +189,7 @@ describe('mlArrayIfEnabled', () => {
});
it('returns null (no throw) when the store is genuinely absent, even under strict', async () => {
- // ENOENT + no placeholder shadow: never written by either device → trustworthy empty.
+ // ENOENT: never written by either device → trustworthy empty.
readFileMock.mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }));
existsResult = false;
await expect(store.mlArrayIfEnabled('goals', { strict: true })).resolves.toBeNull();
@@ -225,21 +225,17 @@ describe('mlArrayIfEnabled', () => {
await expect(store.mlArrayIfEnabled('goals')).resolves.toBeNull();
});
- it('throws under strict when a legacy .icloud placeholder shadows an offloaded store', async () => {
- // readFile reports ENOENT (real path offloaded) but the `.MortalLoom.json.icloud`
- // placeholder is present: the store exists, just evicted. Must not read as
- // trustworthy-absent — the read is attempted first, then the placeholder probe
- // reclassifies it as unreadable.
+ it('treats ENOENT as trustworthy-absent under strict regardless of sibling paths (#3716)', async () => {
+ // The read path no longer probes for a pre-APFS `.MortalLoom.json.icloud`
+ // sibling — that representation does not occur on supported macOS (measured:
+ // zero placeholders across 223 iCloud containers holding 373 evicted files).
+ // ENOENT is therefore an unqualified "no file," never a reclassify-to-
+ // unreadable. Eviction cannot reach this branch: a dataless file keeps its
+ // path and rejects with ICLOUD_NOT_MATERIALIZED instead.
readFileMock.mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }));
- existsResult = true; // the placeholder existsSync probe returns true
- await expect(store.mlArrayIfEnabled('goals', { strict: true }))
- .rejects.toThrow(/unreadable/i);
- });
-
- it('non-strict treats a placeholder-shadowed store as null (fall through)', async () => {
- readFileMock.mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }));
- existsResult = true;
- await expect(store.mlArrayIfEnabled('goals')).resolves.toBeNull();
+ existsResult = true; // what the removed placeholder probe would have read as "present"
+ await expect(store.mlArrayIfEnabled('goals', { strict: true })).resolves.toBeNull();
+ expect(console.warn).not.toHaveBeenCalled();
});
it('non-strict swallows an unreadable store (unchanged): returns null', async () => {
@@ -355,12 +351,12 @@ describe('updateStore', () => {
});
it('seeds a fresh store when the file disappears between existsSync and read (ENOENT race)', async () => {
- // existsSync sequence: (1) inside readStoreAtPath → true (read attempted),
- // (2) post-read check in updateStore's guard → false (file vanished),
- // (3) `.icloud` placeholder probe → false (no shadowing placeholder).
- // The post-read recheck must discriminate this from a transient/corrupt
- // case so we don't reject a legitimate seed.
- existsQueue.push(true, false, false);
+ // The read is attempted unconditionally (no existsSync gate — see
+ // readStoreAtPathResult) and reports ENOENT, so updateStore's guard makes the
+ // only existsSync call in the path: → false (file vanished). The post-read
+ // recheck must discriminate this from a transient/corrupt case so we don't
+ // reject a legitimate seed.
+ existsQueue.push(false);
readFileMock.mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }));
writeFileMock.mockResolvedValue(undefined);
const result = await store.updateStore((s) => {
@@ -372,12 +368,12 @@ describe('updateStore', () => {
});
it('refuses to overwrite when file was absent initially but appears unreadable mid-call (reverse race)', async () => {
- // existsSync sequence: (1) inside readStoreAtPath → false (file absent at
- // the start of the read), (2) post-read check in updateStore's guard →
- // true (iCloud just finished downloading the file). Even though we'd be
- // happy to seed a fresh store, the now-present file's content is unknown,
- // so we must not blindly clobber it.
- existsQueue.push(false, true);
+ // The read runs first and finds nothing (file absent at the start of the
+ // read); updateStore's guard then makes the only existsSync call → true
+ // (iCloud just finished downloading the file). Even though we'd be happy to
+ // seed a fresh store, the now-present file's content is unknown, so we must
+ // not blindly clobber it.
+ existsQueue.push(true);
writeFileMock.mockResolvedValue(undefined);
await expect(
store.updateStore((s) => { s.goals.push({ id: 'should-not-write' }); })
@@ -476,31 +472,32 @@ describe('updateStore — iCloud on-demand materialize (darwin)', () => {
);
});
- it('materializes an `.icloud` placeholder shadowing the real path instead of seeding fresh', async () => {
- // Legacy eviction renamed MortalLoom.json → .MortalLoom.json.icloud, so the
- // real path reads absent. Seeding a fresh store would bury real data — we
- // must download the placeholder and write the recovered store instead.
- // existsSync order: (1) readStoreAtPath path=false, (2) ternary path=false,
- // (3) placeholder=true, (4) post-materialize re-read path=true.
- existsQueue.push(false, false, true, true);
- let materialized = false;
- readFileMock.mockImplementation(async () => {
- if (!materialized) throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
- return JSON.stringify({ goals: [{ id: 'recovered' }] });
- });
- spawnMock.mockReturnValue(makeMaterializeChild(0, () => { materialized = true; }));
+ it('seeds an absent path without a second existsSync probe for an `.icloud` placeholder (#3716)', async () => {
+ // The overwrite guard used to fall back to `existsSync(.MortalLoom.json.icloud)`
+ // whenever the real path was absent, and refuse the seed (paying a brctl
+ // download) if that sibling existed. That representation does not occur on
+ // supported macOS, so the probe is gone and an absent path just seeds.
+ //
+ // existsSync consumption is the assertion. The guard now makes exactly ONE
+ // call (path → false, seed). The old code made three — a placeholder probe in
+ // the read path, the guard's path check, then the guard's placeholder probe —
+ // so it would consume the queued `true` last, refuse the seed and spawn brctl.
+ // Restoring the old ternary makes this test fail (spawn called, no write),
+ // which is what makes it a bypass probe rather than a restatement.
+ existsQueue.push(false, false, true);
+ readFileMock.mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }));
+ writeFileMock.mockResolvedValue(undefined);
const result = await store.updateStore((s) => {
- s.goals.push({ id: 'added' });
+ s.goals.push({ id: 'seeded' });
return s.goals.length;
});
- // brctl is asked to download the REAL path, not the placeholder.
- expect(spawnMock).toHaveBeenCalledWith('brctl', ['download', '/icloud/MortalLoom.json'], expect.objectContaining({ shell: false }));
- expect(result).toBe(2);
+ expect(result).toBe(1);
+ expect(spawnMock).not.toHaveBeenCalled();
expect(writeFileMock).toHaveBeenCalledTimes(1);
const written = JSON.parse(writeFileMock.mock.calls[0][1]);
- expect(written.goals).toEqual([{ id: 'recovered' }, { id: 'added' }]);
+ expect(written.goals).toEqual([{ id: 'seeded' }]);
});
it('does not materialize (no spawn) when seeding a genuinely new file', async () => {
diff --git a/server/services/obsidian.js b/server/services/obsidian.js
index 5296c78485..653a925d42 100644
--- a/server/services/obsidian.js
+++ b/server/services/obsidian.js
@@ -330,13 +330,14 @@ export async function createNote(vaultId, notePath, content = '') {
// The overwrite case is `updateNote`, which is guarded. Don't add a screen here
// "for symmetry"; it would cost a stat per created note and can never fire.
//
- // This covers the modern APFS representation only. The LEGACY representation —
- // an evicted file replaced by a sibling `.<name>.md.icloud` placeholder, which
- // `mortalLoomStore` still checks for (`icloudPlaceholderPath`) — is NOT handled:
- // `existsSync(fullPath)` is false for a placeholder-shadowed note, so this
- // creates a fresh file beside the placeholder rather than refusing. Tracked
- // separately; it predates #3706 and needs its own decision about whether vaults
- // ever see placeholders on current macOS.
+ // The modern APFS dataless vnode is the ONLY eviction representation there is
+ // to handle (#3716). macOS' pre-APFS mechanism instead replaced the note with a
+ // sibling `.<name>.md.icloud` stub, which `existsSync(fullPath)` cannot see — so
+ // this would create a fresh file beside it and shadow the offloaded note. That
+ // representation was measured as non-occurring (zero placeholders across 223
+ // iCloud containers holding 373 evicted files, macOS 26 / APFS), and the probe
+ // `mortalLoomStore` used to carry for it was deleted rather than copied here.
+ // See the "only ONE representation" section in server/lib/icloudFile.js.
await writeFile(fullPath, content, 'utf-8');
console.log(`📓 Created note: ${notePath} in vault ${vault.name}`);
return await getNote(vaultId, notePath, { includeBacklinks: false });