feat: suggest t3 doctor when the database has space to reclaim #19437
Mergedjuliusmarmingemerged 4 commits into
t3/db-compaction-2-doctor fromrefs/pull/19437/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsmacroscope-review
- apps/server/src/persistence/DatabaseStorage.ts line 121OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -60,12 +105,17 @@60105 yield* forkParked(61106 Effect.sleep("1 minute").pipe(62- Effect.andThen(compact.pipe(Effect.repeat(Schedule.spaced("6 hours")))),107+ Effect.andThen(108+ compact.pipe(Effect.andThen(publishStatus), Effect.repeat(Schedule.spaced("6 hours"))),109+ ),63110 ),64111 );65112 yield* forkParked(66- Effect.sleep("1 minute").pipe(67- Effect.andThen(reclaim.pipe(Effect.repeat(Schedule.spaced("1 minute")))),113+ publishStatus.pipe(114+ Effect.andThen(Effect.sleep("1 minute")),115+ Effect.andThen(116+ reclaim.pipe(Effect.andThen(publishStatus), Effect.repeat(Schedule.spaced("1 minute"))),117+ ),68118 ),69119 );7012071- return DatabaseStorage.of({ reclaim });121+ return DatabaseStorage.of({ reclaim, status: SubscriptionRef.changes(statusRef) });
- apps/server/src/cli/invocation.ts lines 155 to 156OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -147,3 +147,10 @@147147 const shellWord = (value: string) =>148148 /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;149149150+/**151+ * Quotes `value` for PowerShell, the default Windows terminal. Always quoted,152+ * so a path reads the same whether or not it holds a space. Inside double153+ * quotes `"` doubles, and `$` and the backtick are escaped so nothing expands.154+ */155+const powershellWord = (value: string) =>156+ `"${value.replaceAll("`", "``").replaceAll("$", "`$").replaceAll('"', '""')}"`;
- apps/web/src/components/settings/DatabaseStorageNotice.tsx line 43Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +23,21 @@23+ false,24+ Schema.Boolean,25+ );26+ const { copyToClipboard } = useCopyToClipboard({ target: "command" });27+ const status = result._tag === "Success" ? result.value : null;28+ if (dismissed || status === null || !shouldRecommendDatabaseCompaction(status)) return null;29+ return (30+ <SettingsSection id={`storage-database-${environmentId}`} title="Database">31+ <SettingsGroup>32+ <SettingsRow33+ title={`Reclaim ${(status.reclaimableBytes / 1024 ** 3).toFixed(1)} GiB on ${label}`}34+ description={35+ <>36+ Old history is cleaned up automatically, but this database still holds the freed37+ space. Run the command on {label} to return it to disk; it pauses and restarts the38+ background service. Quit the desktop app first if it hosts this environment.39+ <code className="mt-2 block select-text break-all">{status.compactCommand}</code>40+ </>41+ }42+ control={43+ <div className="flex flex-wrap items-center gap-1.5">
- apps/server/src/cli/invocation.test.ts lines 222 to 223OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -181,0 +203,21 @@203+ // the PowerShell way: no POSIX single quotes anywhere.204+ expect((yield* hostCommand("win32", { T3CODE_CLI_PATH: shim })).command).toBe(205+ `& "${shim}" doctor "--base-dir" "C:\\Users\\Jane Doe\\.t3"`,206+ );207+ // Without a launcher, plain `t3` with PowerShell-quoted arguments.208+ expect((yield* hostCommand("win32", {})).command).toBe(209+ 't3 doctor "--base-dir" "C:\\Users\\Jane Doe\\.t3"',210+ );211+ // Typographic quotes also delimit PowerShell strings; doubling keeps them.212+ expect(213+ (yield* resolveHostCliCommand("doctor", ["--base-dir", "C:\\T3\\\u201CArchive\u201D"]).pipe(214+ Effect.provideService(HostProcess.Platform, "win32"),215+ Effect.provideService(HostProcess.Environment, { PATH: "" }),216+ Effect.provideService(HostProcess.ExecutablePath, "C:\\t3.exe"),217+ Effect.provideService(HostProcess.Arguments, ["C:\\t3.exe", "C:\\bin.mjs"]),218+ Effect.provideService(HostProcess.IsExecutable, false),219+ )).command,220+ ).toBe('t3 doctor "--base-dir" "C:\\T3\\\u201C\u201CArchive\u201D\u201D"');221+ // POSIX hosts keep single quotes for the same input.222+ expect((yield* hostCommand("linux", { T3CODE_CLI_PATH: shim })).command).toBe(223+ `${shim} doctor --base-dir 'C:\\Users\\Jane Doe\\.t3'`,apps/server/src/persistence/DatabaseStorage.test.ts line 72OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -31,3 +55,18 @@3155 yield* storage.reclaim;3256 assert.equal(yield* freePages, 0);3357 assert.deepEqual(yield* sql`SELECT value FROM retained`, [{ value: "keep" }]);58+ }).pipe(Effect.provide(storageLayer(testConfig))),59+);60+61+it.effect("publishes file accounting and the doctor command after each pass", () =>62+ Effect.gen(function* () {63+ const sql = yield* SqlClient.SqlClient;64+ const config = yield* ServerConfig.ServerConfig;65+ yield* sql`CREATE TABLE discarded (value BLOB)`;66+ yield* sql`INSERT INTO discarded VALUES (zeroblob(1048576))`;67+ yield* TestClock.adjust("1 minute");68+ const before = (yield* currentStatus).pipe(Option.getOrThrow);69+ assert.isNotNull(before);70+ assert.isAbove(before!.databaseBytes, 1048576);71+ assert.isTrue(before!.incrementalVacuumEnabled);72+ assert.include(before!.compactCommand, "doctor --base-dir");
juliusmarminge merged this65d390f
juliusmarminge closed this
Sign in to join this conversation.




Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
2eb44ab· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.