Skip to content

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

fix(handoff-files): say when the record of passed files could not be saved

DeryFerd1660e8d5c48b
diff --git a/server/host/handoff-files.test.ts b/server/host/handoff-files.test.ts
index c6c77a8973..0ed725a855 100644
--- a/server/host/handoff-files.test.ts
+++ b/server/host/handoff-files.test.ts
@@ -622,6 +622,29 @@ describe("one coordinate_bots call", () => {
expect(files.reserveDay("ana", HANDOFF_FILES_PER_DAY, 0)).toBeNull();
});
+ it("says the record of the files could not be saved, so nobody is promised a notice that will not come", async () => {
+ const files = setup();
+ write("report.pdf");
+ // A full disk, a quota, a read-only data dir: the ledger cannot be replaced. A folder in its place refuses the rename
+ // on every platform without needing to take permissions away from the test's own user.
+ const ledger = join(DATA, "handoff-files.json");
+ rmSync(ledger, { recursive: true, force: true });
+ mkdirSync(ledger, { recursive: true });
+ try {
+ const result = await files.coordinate({
+ paths: ["report.pdf"], senderId: "ana", recipients: 1, saveOne: saver(),
+ send: async (passed) => {
+ files.sent("a1", ANA, passed!);
+ return { status: 200, body: { receipts: [{ botId: "ben", botName: "Ben", outcome: "queued", requestId: "a1" }] } };
+ },
+ });
+ expect(result.body.files).toContain("Passed report.pdf to @Ben");
+ expect(result.body.files).toContain("could not be saved");
+ } finally {
+ rmSync(ledger, { recursive: true, force: true });
+ }
+ });
+
it("stores nothing for a call that is refused or reaches nobody", async () => {
const files = setup();
write("report.pdf", `unique ${serial}`);
diff --git a/server/host/handoff-files.ts b/server/host/handoff-files.ts
index 7f9fd5678b..6a7aa422c4 100644
--- a/server/host/handoff-files.ts
+++ b/server/host/handoff-files.ts
@@ -137,7 +137,9 @@ export function createHandoffFiles(deps: HandoffFilesDeps) {
for (const batch of batches) for (const path of Object.keys(batch.placed ?? {})) removeInboxCopy(path);
}
- function save(): void {
+ /** Writes the ledger and reports whether it landed: a caller that tells the person what happened must not promise a
+ * notice the record will not carry across a restart. */
+ function save(): boolean {
const state = load(), oldest = now() - KEPT_MS, today = new Date(now()).toISOString().slice(0, 10);
const kept = state.batches.filter((batch) => batch.at >= oldest).slice(-KEPT_BATCHES);
if (kept.length !== state.batches.length) removeCopies(state.batches.filter((batch) => !kept.includes(batch)));
@@ -145,8 +147,10 @@ export function createHandoffFiles(deps: HandoffFilesDeps) {
for (const [botId, day] of Object.entries(state.days)) if (day.day !== today) delete state.days[botId];
try {
writeFileAtomic(file, JSON.stringify(state), { mode: 0o600 });
+ return true;
} catch (error) {
deps.log?.(`handoff files: could not save the record: ${error instanceof Error ? error.message : String(error)}`);
+ return false;
}
}
@@ -435,12 +439,13 @@ export function createHandoffFiles(deps: HandoffFilesDeps) {
// Only a teammate that got the files costs the sender's day.
const unused = Math.max(0, call.recipients - got.length);
if (unused) releaseDay(call.senderId, count * unused, bytes * unused);
- save();
+ const recorded = save();
if (!got.length) drop(staged.fresh);
const names = staged.files.map((passed) => passed.name).join(", ");
const open = missed.filter((receipt) => /^already sent\b/.test(receipt.detail ?? "")), elsewhere = missed.filter((receipt) => !open.includes(receipt));
const said = [
...(got.length ? [`Passed ${names} to ${got.map(who).join(", ")}: copied into their own inbox, shown to the person on the hand-off line.`] : []),
+ ...(recorded ? [] : ["The record of these files could not be saved, so their inbox notice may not appear after a restart and the day's limit may not remember them."]),
...(open.length ? [`Not passed to ${open.map(who).join(", ")}: the same work is already with them and was not sent again, so these files did not go. Pass them in a message of its own, or with rework true once that work has finished.`] : []),
...(elsewhere.length ? [`Not passed to ${elsewhere.map(who).join(", ")}: that message went as an answer, a relay or a post, which carry no files. Send them in a new coordinate_bots message.`] : []),
].join(" ");