Skip to content

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

feat(config): keep the dated copies out of workspace backups, share the unreadable-file helper, document them

David Neyra8b389d66dcbd
diff --git a/apps/docs/content/docs/self-hosting/data-and-backups.mdx b/apps/docs/content/docs/self-hosting/data-and-backups.mdx
index da812a435a..ef182dbc68 100644
--- a/apps/docs/content/docs/self-hosting/data-and-backups.mdx
+++ b/apps/docs/content/docs/self-hosting/data-and-backups.mdx
@@ -118,6 +118,25 @@ and reconnect accounts on the new machine instead.
Restore with the server stopped, preserving the original paths and ownership, then start it again. The [VPS backup instructions](/docs/self-hosting/deploy-vps#back-up) show the app-data archive and stop/start commands.
+## The settings file and its dated copies
+
+Every save of `~/.openmausbot/config.json` keeps a copy of the file as it was,
+named `config.json.bak.YYYYMMDD-HHMMSS`, beside it; the last ten are kept. A
+save never replaces a settings file it could not read or understand: it fails
+and says so, so a file that cannot be read is never overwritten by a partial
+one.
+
+To go back to an earlier copy, stop the server and run:
+
+```
+openmausbot config backups
+openmausbot config restore latest
+```
+
+The file a restore replaces is kept as a dated copy too, so the restore can be
+undone. These copies hold the saved keys and connections of the settings file:
+they stay on that computer and are not part of a workspace backup.
+
## Do not copy secrets casually
Packaged desktop builds protect credentials using operating-system secure storage.
diff --git a/server/cli-usage.ts b/server/cli-usage.ts
index 584c841acf..35b7e61e2d 100644
--- a/server/cli-usage.ts
+++ b/server/cli-usage.ts
@@ -43,6 +43,7 @@ export const USAGE = `openmausbot — your team of AI bots, ready in a few steps
openmausbot service install [the same way-in options as serve] [--port N] [--data-dir DIR] | uninstall
[--sentinel] (the health scan below, every two minutes, instead of the server)
openmausbot sentinel [--data-dir DIR] [--out DIR] [--once] [--json] (read-only health scan; see --help)
+ openmausbot config backups | restore NAME (dated copies of the settings file; see --help)
openmausbot browser install [--with-deps] | status
openmausbot fleet init --domain HOST [--operator USER] | create NAME --admin EMAIL [--member EMAIL] [--brand FILE]
[--anthropic-key-file FILE] [--cap USD] [--license-key KEY] [--memory 1G]
diff --git a/server/routine-file.ts b/server/routine-file.ts
index a0280a5255..2a948cf982 100644
--- a/server/routine-file.ts
+++ b/server/routine-file.ts
@@ -1,9 +1,7 @@
// routines.json as it is read at start, and again while it cannot be read. A file that is there but unreadable is never
// taken for an empty one: the caller refuses every save while it stays so, a copy is set aside the first time each
// unreadable content is seen, and the read is tried again until it works.
-import { createHash } from "node:crypto";
-import { chmodSync, constants, copyFileSync, existsSync, readdirSync, readFileSync } from "node:fs";
-import { basename, dirname } from "node:path";
+import { readFileSync } from "node:fs";
import type { RoutineHoldCause } from "../shared/routines.ts";
import { attachmentsMalformed } from "./routine-attachments.ts";
@@ -15,9 +13,6 @@ import type { Routine, RoutineRequestReceipt, RoutineRun } from "./routines.ts";
/** While routines.json cannot be read, the read is tried again this often. */
export const UNREADABLE_RETRY_MS = 60_000;
-/** Copies of unreadable content kept beside the file; a further one is not copied. */
-const ASIDE_COPIES = 5;
-
export interface RoutineFileContents {
text: string;
routines: Routine[];
@@ -71,17 +66,4 @@ export function readRoutineFile(file: string, now: number): RoutineFileRead {
}
}
-/** Copies the unreadable file beside itself, named by its content so the same content is copied once. Returns the copy's
- * path, or null when there is nothing to copy or the copy cannot be made. The file itself stays where it is. */
-export function keepUnreadableAside(file: string): string | null {
- try {
- const aside = `${file}.unreadable-${createHash("sha256").update(readFileSync(file)).digest("hex").slice(0, 12)}`;
- if (existsSync(aside)) return aside;
- if (readdirSync(dirname(file)).filter((name) => name.startsWith(`${basename(file)}.unreadable-`)).length >= ASIDE_COPIES) return null;
- copyFileSync(file, aside, constants.COPYFILE_EXCL);
- chmodSync(aside, 0o600);
- return aside;
- } catch {
- return null;
- }
-}
+export { keepUnreadableAside } from "./unreadable-aside.ts";
diff --git a/server/workspace-backup-policy.ts b/server/workspace-backup-policy.ts
index 8f8f61d8f9..f2baec5e97 100644
--- a/server/workspace-backup-policy.ts
+++ b/server/workspace-backup-policy.ts
@@ -46,6 +46,9 @@ export function excludedWorkspaceAuthPath(path: string): boolean {
if (/^team-policy\.json(?:$|\.\d+\.[0-9a-f-]+\.tmp$)/.test(path)) return true;
// A Team Cloud member's own installation, keys and sign-ins: theirs, never in the team's backup.
if (/^people-connections(?:\/|$)/.test(path)) return true;
+ // A dated copy of the settings file, and the copy of one that could not be understood: they hold the credentials
+ // the settings file holds, so they never leave the computer they were taken on.
+ if (/^config\.json\.(?:bak\.\d{8}-\d{6}(?:-\d+)?|unreadable-[0-9a-f]{12})(?:\.\d+\.[0-9a-f-]+\.tmp)?$/.test(path)) return true;
return /^(?:(?:providers|caddy|chrome-profile|\.agent-browser)(?:\/|$)|workspace-credentials\.json$|external-runtimes\.json$|browser-engine-key$)/.test(path) ||
/^(?:config\.json|webhooks\.json|workspace-credentials\.json|external-runtimes\.json|browser-engine-key|sessions\.json|tunnel-account\.json)\.\d+(?:\.[0-9a-f-]+)?\.tmp$/.test(path) ||
/^(?:vm-home|vm-homes\/[^/]+)\/\.browser-profiles(?:\/|$)/.test(path);