Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix: surface persistent file sync failures

Afloat56dcb495296d
diff --git a/electron/cloud-sync-engine.mjs b/electron/cloud-sync-engine.mjs
index 4607b7dfef..f533389a91 100644
--- a/electron/cloud-sync-engine.mjs
+++ b/electron/cloud-sync-engine.mjs
@@ -85,7 +85,7 @@ export async function shareFolder({ client, state, folder, local, now = Date.now
if (answer?.ok || answer?.conflict) state.dropBase(folder.id, wire);
});
}
- result.status = result.pendingDeletes ? "confirm-deletes" : result.waitingBytes ? "waiting" : result.done < result.files ? "copying" : result.problem ? "problem" : "synced";
+ result.status = result.pendingDeletes ? "confirm-deletes" : result.waitingBytes ? "waiting" : result.problem ? "problem" : result.done < result.files ? "copying" : "synced";
return result;
}
@@ -124,7 +124,7 @@ export async function fetchOutputs({ client, state, folder, local, platform = pr
if (await receive(ctx, action) === "full") { result.waitingBytes += action.size; return; }
result.done++;
});
- result.status = result.waitingBytes ? "waiting" : result.done < result.files ? "copying" : result.problem ? "problem" : "synced";
+ result.status = result.waitingBytes ? "waiting" : result.problem ? "problem" : result.done < result.files ? "copying" : "synced";
return result;
}
diff --git a/electron/cloud-sync-engine.node-test.mjs b/electron/cloud-sync-engine.node-test.mjs
index 8573a9f4a3..a4060c94cc 100644
--- a/electron/cloud-sync-engine.node-test.mjs
+++ b/electron/cloud-sync-engine.node-test.mjs
@@ -159,3 +159,20 @@ test("bots' work: a damaged download is thrown away, and a path from My Cloud ne
assert.equal(s.read("ok.md"), "fine");
assert.equal(existsSync(join(s.dir, "escape.md")), false);
});
+
+test("bots' work: a repeatedly failing file is a problem rather than endless copying", async (t) => {
+ const s = setup(t);
+ s.cloud.put("f1", "report.md", "the report");
+ const download = s.cloud.client.download;
+ s.cloud.client.download = async () => { throw new Error("File is locked"); };
+ assert.equal((await s.outputs()).status, "copying");
+ assert.equal((await s.outputs()).status, "copying");
+ const failed = await s.outputs();
+ assert.equal(failed.status, "problem");
+ assert.equal(failed.problem, "report.md: File is locked");
+ s.cloud.client.download = download;
+ const recovered = await s.outputs();
+ assert.equal(recovered.status, "synced");
+ assert.equal(recovered.problem, null);
+ assert.deepEqual(s.state.failures(), []);
+});
diff --git a/electron/cloud-sync.mjs b/electron/cloud-sync.mjs
index a9808bc7fd..7ff7b057d8 100644
--- a/electron/cloud-sync.mjs
+++ b/electron/cloud-sync.mjs
@@ -250,7 +250,8 @@ export function createCloudFilesService({
for (const [id, local] of places) {
if (only && !only.has(id)) continue;
try {
- await fetchOutputs({ client: cloud, state, folder: { id }, local, platform, now, trashItem, markDownloaded, ...(freeBytes ? { freeBytes } : {}), report });
+ const result = await fetchOutputs({ client: cloud, state, folder: { id }, local, platform, now, trashItem, markDownloaded, ...(freeBytes ? { freeBytes } : {}), report });
+ outputsProblem ??= result.problem;
} catch (error) {
if (passStopper(error)) throw error;
if (error?.status !== 410) outputsProblem = String(error?.message ?? error);
diff --git a/electron/cloud-sync.node-test.mjs b/electron/cloud-sync.node-test.mjs
index 5bf0aa2e4c..793ba8dd98 100644
--- a/electron/cloud-sync.node-test.mjs
+++ b/electron/cloud-sync.node-test.mjs
@@ -61,6 +61,42 @@ test("shares a folder: registered on My Cloud, copied there, and up to date", as
assert.deepEqual(state.shared.map(({ id, name, status, files, done }) => ({ id, name, status, files, done })), [{ id: cloudFolder.id, name: "Clients", status: "synced", files: 1, done: 1 }]);
});
+test("repeated upload failures become a folder problem and clear after a successful retry", async (t) => {
+ const s = setup(t);
+ const upload = s.cloud.client.upload;
+ s.cloud.client.upload = async () => { throw new Error("The file is locked"); };
+ await s.service.share(s.project);
+ assert.equal(s.service.state().shared[0].status, "copying");
+ await s.service.pass();
+ assert.equal(s.service.state().shared[0].status, "copying");
+ await s.service.pass();
+ assert.equal(s.service.state().shared[0].status, "problem");
+ assert.equal(s.service.state().shared[0].problem, "brief.md: The file is locked");
+ s.cloud.client.upload = upload;
+ await s.service.pass();
+ assert.equal(s.service.state().shared[0].status, "synced");
+ assert.equal(s.service.state().shared[0].problem, null);
+});
+
+test("repeated output failures reach the Files state and clear after a successful retry", async (t) => {
+ const s = setup(t);
+ s.cloud.setBots({ bots: [{ id: "owl", name: "Owl", tasks: [{ threadId: "t1", title: "Report" }] }], groups: [] });
+ const folder = s.cloud.addFolder({ id: "bot-owl-t1", kind: "bot", botId: "owl", threadId: "t1", cloudPath: "/work/owl", newestMs: AT + 120_000 });
+ s.cloud.put(folder.id, "report.md", "the report");
+ const download = s.cloud.client.download;
+ s.cloud.client.download = async () => { throw new Error("Could not write this file"); };
+ await s.service.pass();
+ assert.equal(s.service.state().outputs.problem, null);
+ await s.service.pass();
+ assert.equal(s.service.state().outputs.problem, null);
+ await s.service.pass();
+ assert.equal(s.service.state().outputs.problem, "report.md: Could not write this file");
+ s.cloud.client.download = download;
+ await s.service.pass();
+ assert.equal(s.service.state().outputs.problem, null);
+ assert.equal(readFileSync(join(s.home, "Documents", "MausBot", "Owl", "Report", "report.md"), "utf8"), "the report");
+});
+
test("only a folder this computer shared is ever synced: one My Cloud names for it is never read or written", async (t) => {
const s = setup(t);
const ssh = join(s.home, ".ssh");