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

docs: attribute fail-closed to readStoreAtPathResult; drop over-strong pool claim (#3708)

Adam Eivy233e7d4fd77c
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 8c7bfb4072..f045006732 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -36,7 +36,7 @@
## Fixed
-- **iCloud materialization logs now say a download was *requested*, not that the file is local.** `brctl download` returns exit 0 the moment it accepts and queues the request — it does not block until the bytes arrive, and it returns 0 even when the sync layer ultimately can't fetch the file. The on-demand materialize path logged that exit 0 as "materialized from iCloud", so an operator reading these lines during an iCloud outage would conclude a file was readable when it was still dataless. The logs now report the request, and the code comments spell out that the authoritative check is the `stat()` re-screen in `readIfMaterialized` — the reason the subsequent re-read stays safe and must not be removed. No behavior change.
+- **iCloud materialization logs now say a download was *requested*, not that the file is local.** `brctl download` returns exit 0 the moment it accepts and queues the request — it does not block until the bytes arrive, and it returns 0 even when the sync layer ultimately can't fetch the file. The on-demand materialize path logged that exit 0 as "materialized from iCloud", so an operator reading these lines during an iCloud outage would conclude a file was readable when it was still dataless. The logs now report the request, and the code comments spell out that the read path (`readStoreAtPathResult`/`readIfMaterialized`) fails closed — rejecting a dataless file rather than reading it — which is the reason the subsequent re-read stays safe and must not be removed. No behavior change.
- Preserve a Series Autopilot run's reasoning-effort override when the foundation gate delegates a worldbuilding repair to Universe Builder.
diff --git a/server/services/mortalLoomStore.js b/server/services/mortalLoomStore.js
index 22268f24e7..32042a9c9f 100644
--- a/server/services/mortalLoomStore.js
+++ b/server/services/mortalLoomStore.js
@@ -160,13 +160,17 @@ function icloudPlaceholderPath(path) {
// when the sync layer ultimately can't fetch the file (device offline / iCloud
// wedged); under a wedged iCloud it can instead hang, which is why we await it
// with a timeout below. So a `true` here is NOT proof the file is readable. What
-// keeps the caller's subsequent re-read safe is that it routes through
-// `readIfMaterialized` (see readStoreAtPathResult), which returns a store it could
-// NOT actually read as null instead of issuing a blocking read: a still-dataless
-// file rejects on the `Stats.blocks` re-screen with ICLOUD_NOT_MATERIALIZED, and
-// an absent path shadowed by a legacy `.icloud` placeholder rejects on ENOENT.
-// Either way the store stays null and the caller refuses to overwrite, so a
-// false-positive `true` from here can never truncate data (nor hang the pool).
+// 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
+// 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
+// strand one threadpool slot per path — see server/lib/icloudFile.js — but this
+// path never makes that worse.)
//
// We await brctl's exit (bounded by a timeout) and let the caller re-read.
// Resolves `true` only on a clean exit-0 — non-darwin, missing brctl, spawn
@@ -447,11 +451,12 @@ export async function updateStore(mutator) {
// `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`
- // routes through `readIfMaterialized`, which returns null for a store it could
- // not actually read instead of issuing a blocking read — a still-dataless file
+ // → `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
- // rejects on ENOENT. Either way store stays null and we refuse to overwrite
- // rather than issuing a read that would hang the threadpool.
+ // surfaces as ENOENT — and `readStoreAtPathResult` catches both and returns
+ // `store: null`. Either way store stays null and we refuse to overwrite rather
+ // than reading blindly (which is what would risk stranding a threadpool slot).
const materialized = await materializeNow(path);
if (materialized) {
store = await readStoreAtPath(path);