feat(server): t3 doctor reclaims database space #19436
Mergedjuliusmarmingemerged 3 commits into
t3/db-compaction-1-background fromrefs/pull/19436/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/persistence/DatabaseMaintenance.ts line 17OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,17 @@1+import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";2+import * as Context from "effect/Context";3+import * as Effect from "effect/Effect";4+import * as FileSystem from "effect/FileSystem";5+import * as Layer from "effect/Layer";6+import * as Schema from "effect/Schema";7+import * as SqlClient from "effect/sql/SqlClient";8+import { isSqlError } from "effect/sql/SqlError";9+10+import * as EventStore from "../orchestration-v2/EventStore.ts";11+import * as ProjectionMaintenance from "../orchestration-v2/ProjectionMaintenance.ts";12+import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts";13+14+export class DatabaseMaintenanceError extends Schema.TaggedError<DatabaseMaintenanceError>()(15+ "DatabaseMaintenanceError",16+ {17+ reason: Schema.Literals(["running", "missing", "invalid-projections", "compact"]),apps/server/src/persistence/DatabaseMaintenance.ts line 85OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +65,21 @@65+ const free = yield* sql<{ readonly freelist_count: number }>`PRAGMA freelist_count`;66+ const size = yield* sql<{ readonly page_size: number }>`PRAGMA page_size`;67+ const mode = yield* sql<{ readonly auto_vacuum: number }>`PRAGMA auto_vacuum`;68+ const pageSize = size[0]?.page_size ?? 0;69+ return {70+ databaseBytes: (pages[0]?.page_count ?? 0) * pageSize,71+ reclaimableBytes: (free[0]?.freelist_count ?? 0) * pageSize,72+ incrementalVacuumEnabled: mode[0]?.auto_vacuum === 2,73+ };74+});75+76+const make = Effect.gen(function* () {77+ const fs = yield* FileSystem.FileSystem;78+79+ const locate = Effect.fn("DatabaseMaintenance.locate")(function* (databasePath: string) {80+ if (!(yield* fs.exists(databasePath))) {81+ return yield* new DatabaseMaintenanceError({ reason: "missing" });82+ }83+ });84+85+ const asMaintenanceError = Effect.mapError((cause: unknown) =>
juliusmarminge merged this2b6611c
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
64f397e· 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.