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

address review (claude): only a succeeded-but-unmoved download may arm the force-save override

[._.]/ Adam Eivyd237f9c28ecc
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 2bf6c562ad..489de5e900 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -56,7 +56,7 @@
## Fixed
-- **A note that iCloud wrongly reports as "not downloaded" can now be saved anyway.** The write guard screens for an offloaded note by looking for a real byte length with no local blocks — a shape an ordinary sparse or compressed file also has. When that misfired the lockout was permanent: asking iCloud to download an already-local file succeeds instantly and changes nothing, so every save was refused forever while the message told the user to try again shortly. The server now checks whether asking iCloud to download the note moved anything, so it can tell a real download in progress from a refusal that will never clear — and only the second of those, twice in a row on the same note, offers the Brain Notes and Wiki editors a deliberate "Save anyway" row that writes it regardless. While a download really is in flight you still just wait, and the ordinary Save button, ⌘S, and background mirrors always refuse, so nothing bypasses the guard without an explicit click. The message no longer says to try again shortly when trying again cannot help.
+- **A note that iCloud wrongly reports as "not downloaded" can now be saved anyway.** The write guard screens for an offloaded note by looking for a real byte length with no local blocks — a shape an ordinary sparse or compressed file also has. When that misfired the lockout was permanent: asking iCloud to download an already-local file succeeds instantly and changes nothing, so every save was refused forever while the message told the user to try again shortly. The server now checks whether the download both succeeded and actually moved the file, so it can tell a download still in flight (or one that failed) from a refusal that will never clear — and only the second of those, twice in a row on the same note, offers the Brain Notes and Wiki editors a deliberate "Save anyway" row that writes it regardless. While a download really is in flight you still just wait, and the ordinary Save button, ⌘S, and background mirrors always refuse, so nothing bypasses the guard without an explicit click. The message no longer says to try again shortly when trying again cannot help.
- **Complete LLM answers no longer fail on recoverable JSON serialization mistakes.** Long foundation calls could begin as normal JSON, then emit the complete remaining objects as escaped `\\n` / `\\"` text, leave quotation marks inside prose unescaped, or omit a prose field's closing quote immediately before its structural `}` line. The shared parser now decodes an escaped tail only from the JSON parser's exact failure position, repairs quotes only at structurally unambiguous boundaries, and accepts repairs only when the entire reconstructed response parses—preserving expensive completed work without making partial or arbitrary text look valid.
diff --git a/client/src/components/ForceSaveNoteRow.jsx b/client/src/components/ForceSaveNoteRow.jsx
index f4642e3189..e079db5bbc 100644
--- a/client/src/components/ForceSaveNoteRow.jsx
+++ b/client/src/components/ForceSaveNoteRow.jsx
@@ -9,6 +9,12 @@ import InlineConfirmRow from './ui/InlineConfirmRow';
* the guard, which is why this is a row the user has to answer and never an
* automatic retry.
*
+ * The copy names the cost of being wrong on purpose. `brctl` exit 0 means the
+ * download was accepted, not that the bytes are local, so even a stalled verdict
+ * does not PROVE the file is on this Mac — and if it isn't, the forced write
+ * blocks a libuv thread uninterruptibly. The user can only weigh "Save anyway"
+ * against "Keep waiting" if the prompt says that out loud.
+ *
* Renders nothing when not offered, so callers can drop it in unconditionally.
* Shared by Brain Notes and the Wiki browser — the same lockout is reachable
* from both, and the copy must not drift between them.
@@ -19,7 +25,7 @@ export default function ForceSaveNoteRow({ offered, onConfirm, onCancel }) {
<InlineConfirmRow
variant="separator"
tone="warning"
- question="iCloud keeps reporting this note as not downloaded, so saving is refused. Write it anyway?"
+ question="iCloud says this note isn't downloaded, but asking it to download changed nothing. If the note really is on this Mac, saving is safe — if it isn't, PortOS may stop responding until you restart it. Write it anyway?"
confirmText="Save anyway"
confirmTitle="Bypass the iCloud download check and write this note"
cancelText="Keep waiting"
diff --git a/client/src/hooks/useNoteSave.js b/client/src/hooks/useNoteSave.js
index 05841d1a54..00f6ddeaef 100644
Binary files a/client/src/hooks/useNoteSave.js and b/client/src/hooks/useNoteSave.js differ
diff --git a/client/src/hooks/useNoteSave.test.jsx b/client/src/hooks/useNoteSave.test.jsx
index 1c6d5e6af5..55c6151223 100644
--- a/client/src/hooks/useNoteSave.test.jsx
+++ b/client/src/hooks/useNoteSave.test.jsx
@@ -87,6 +87,70 @@ describe('useNoteSave', () => {
expect(result.current.forceOffered).toBe(false);
});
+ it('does not carry an armed override to a same-named note in another vault', async () => {
+ // Vaults routinely share basenames (index.md, README.md, daily notes). Keying
+ // on the path alone would render the override over a different file that was
+ // never screened, and confirming it would force-write THAT one.
+ api.updateNote.mockRejectedValue(evicted());
+ const { result, rerender } = renderHook(props => useNoteSave(props), {
+ initialProps: { vaultId: 'v1', notePath: 'index.md', content: 'body' },
+ });
+
+ await failTwice(result);
+ expect(result.current.forceOffered).toBe(true);
+
+ rerender({ vaultId: 'v2', notePath: 'index.md', content: 'body' });
+
+ expect(result.current.forceOffered).toBe(false);
+ });
+
+ it('disarms when the editor reopens the note, so a stale override never greets the user', async () => {
+ api.updateNote.mockRejectedValue(evicted());
+ const { result, rerender } = setup('a.md');
+ await failTwice(result);
+ expect(result.current.forceOffered).toBe(true);
+
+ // Close the note, then reopen it — no save has been attempted since.
+ rerender({ vaultId: 'v1', notePath: null, content: '' });
+ rerender({ vaultId: 'v1', notePath: 'a.md', content: 'body' });
+
+ expect(result.current.forceOffered).toBe(false);
+ });
+
+ it('refuses to stack a second write while one is in flight', async () => {
+ // The click that matters is "Save anyway" on a note that may genuinely be
+ // evicted: that write blocks uninterruptibly, so a second one strands another
+ // libuv thread for the life of the process. `saving` can't guard this — the
+ // setState hasn't repainted the disabled button yet.
+ let release;
+ api.updateNote.mockReturnValue(new Promise(resolve => { release = resolve; }));
+ const { result } = setup();
+
+ let first;
+ let second;
+ await act(async () => {
+ first = result.current.save({ force: true });
+ second = result.current.save({ force: true });
+ });
+
+ expect(api.updateNote).toHaveBeenCalledTimes(1);
+ await expect(second).resolves.toBeNull();
+
+ await act(async () => { release({ path: 'a.md' }); await first; });
+ expect(api.updateNote).toHaveBeenCalledTimes(1);
+ });
+
+ it('accepts a new save once the previous one settles', async () => {
+ api.updateNote.mockResolvedValue({ path: 'a.md' });
+ const { result } = setup();
+
+ await act(async () => { await result.current.save(); });
+ await act(async () => { await result.current.save(); });
+
+ // The re-entrancy guard must release on settle, or the editor is save-once.
+ expect(api.updateNote).toHaveBeenCalledTimes(2);
+ });
+
it('closes the override on a successful save', async () => {
api.updateNote.mockRejectedValue(evicted());
const { result } = setup();
diff --git a/server/services/obsidian.js b/server/services/obsidian.js
index daedfd6601..6eb75b9734 100644
--- a/server/services/obsidian.js
+++ b/server/services/obsidian.js
@@ -320,14 +320,17 @@ export async function updateNote(vaultId, notePath, content, { force = false } =
console.warn(`⚠️ force-save bypassing the iCloud dataless screen for note: ${notePath}`);
} else if (await isSuspectedDataless(fullPath)) {
// Snapshot before/after so the refusal can say something TRUE about retrying.
- // This is deliberately messaging-only: the verdict stays the re-screen below,
- // which is already the strictest form of "did it actually materialize" —
+ // This does NOT gate the server's own write decision — that stays the
+ // re-screen below — but it IS the client's sole arming signal for the
+ // force-save override (see `throwOnError` in server/routes/notes.js), so
+ // loosening how `stalled` is computed widens the bypass. The re-screen is
+ // already the strictest form of "did it actually materialize" —
// `blocks` moving off zero IS the completion signal, so gating the write on
// `mtime` too would only let a still-dataless file through when a metadata
// sync touched it (#3717 option 1, taken for the message and rejected for the
// guard).
const before = await stat(fullPath).catch(() => null);
- await materializeAndWait(fullPath, { label: 'Obsidian note' });
+ const materialized = await materializeAndWait(fullPath, { label: 'Obsidian note' });
if (await isSuspectedDataless(fullPath)) {
const after = await stat(fullPath).catch(() => null);
// Unknown (a stat failed) counts as "moved": never claim a download is
@@ -335,12 +338,21 @@ export async function updateNote(vaultId, notePath, content, { force = false } =
const moved = !before || !after
|| before.blocks !== after.blocks
|| before.mtimeMs !== after.mtimeMs;
+ // Only "brctl succeeded AND nothing changed" proves retrying is futile —
+ // that is the signature of a download with nothing to fetch. A `false`
+ // here means the heal did NOT succeed (timed out against a wedged iCloud,
+ // exited non-zero, `brctl` missing, or a non-iCloud File Provider path
+ // brctl can't speak to), and every one of those also leaves blocks/mtime
+ // untouched. Reporting those as stalled would arm the force-save override
+ // on a genuinely evicted note and hand the user the uninterruptible write
+ // this guard exists to prevent — so they stay retryable.
+ const stalled = materialized && !moved;
return {
error: 'NOTE_EVICTED',
- stalled: !moved,
- message: moved
- ? 'This note is stored in iCloud and has not been downloaded to this Mac yet. A download is in progress — try again shortly.'
- : 'This note looks offloaded to iCloud, but asking iCloud to download it changed nothing, so waiting will not help. If the note really is on this Mac, save it again and choose "Save anyway".'
+ stalled,
+ message: stalled
+ ? 'This note looks offloaded to iCloud, but asking iCloud to download it changed nothing, so waiting will not help. If the note really is on this Mac, save it again and choose "Save anyway".'
+ : 'This note is stored in iCloud and has not been downloaded to this Mac yet. A download was requested — try again shortly.'
};
}
}
diff --git a/server/services/obsidianEvicted.test.js b/server/services/obsidianEvicted.test.js
index 5abc06d92e..b6f8b0ea3e 100644
--- a/server/services/obsidianEvicted.test.js
+++ b/server/services/obsidianEvicted.test.js
@@ -272,6 +272,23 @@ describe('obsidian updateNote against an evicted note', () => {
expect(result.message).toMatch(/Save anyway/);
});
+ it('is not stalled when the materialize itself failed', async () => {
+ const icloud = await import('../lib/icloudFile.js');
+ icloud.isSuspectedDataless.mockResolvedValue(true);
+ // `materializeAndWait` resolves false for a timeout against a wedged iCloud,
+ // a non-zero exit, a missing `brctl`, or a File Provider path brctl can't
+ // speak to. Every one of those ALSO leaves blocks/mtime untouched, so
+ // "nothing moved" alone would call a genuinely evicted note hopeless and arm
+ // the force-save override on it — handing the user the uninterruptible write.
+ icloud.materializeAndWait.mockResolvedValue(false);
+
+ const result = await updateNote(vaultId, NOTE, 'REPLACEMENT');
+
+ expect(result.error).toBe('NOTE_EVICTED');
+ expect(result.stalled).toBe(false);
+ expect(result.message).toMatch(/try again shortly/i);
+ });
+
it('still says "try again shortly" when the download actually moved the file', async () => {
const icloud = await import('../lib/icloudFile.js');
icloud.isSuspectedDataless.mockResolvedValue(true);