{"record":{"id":"0f9d35124ff91fc3","repo":"gastownhall/beads","slug":"dolt-gc-w","errorCode":null,"errorMessage":"dolt gc: %w","messagePattern":"dolt gc: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/gc.go","lineNumber":14,"sourceCode":"package versioncontrolops\n\nimport (\n\t\"context\"\n\t\"fmt\"\n)\n\n// DoltGC runs Dolt garbage collection to reclaim disk space. Archive level 0\n// writes classic Snappy table files instead of zstd archives.\n// conn must be a non-transactional database connection since\n// DOLT_GC cannot run inside an explicit transaction.\nfunc DoltGC(ctx context.Context, conn DBConn) error {\n\tif _, err := conn.ExecContext(ctx, \"CALL DOLT_GC('--archive-level', '0')\"); err != nil {\n\t\treturn fmt.Errorf(\"dolt gc: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/gc.go#L1-L18","documentation":"DoltGC executes `CALL DOLT_GC('--archive-level', '0')` to reclaim disk space. The wrapped \"dolt gc: %w\" error means the stored procedure itself failed. The most common cause is calling it on a connection with an active explicit transaction — DOLT_GC cannot run inside one — or on a Dolt version/engine that lacks the procedure or the --archive-level flag.","triggerScenarios":"Calling DoltGC with a *sql.Tx or a connection inside BEGIN/COMMIT; running against an old Dolt server that predates DOLT_GC or the --archive-level option; the server refusing GC while other sessions hold the database.","commonSituations":"Post-flatten cleanup where the caller reused a transactional connection; mixed bd/Dolt versions where archive-level 0 is unsupported; concurrent bd processes keeping the database busy.","solutions":["Ensure conn is a plain autocommit connection (pinned *sql.Conn or *sql.DB), never a *sql.Tx or a session inside an explicit transaction","Commit/rollback any open transaction before calling DoltGC","Check the Dolt server version supports DOLT_GC with --archive-level; drop the flag or upgrade if not","Inspect the wrapped error for 'cannot run in a transaction' vs 'unknown procedure' to distinguish the causes"],"exampleFix":"// before: fails — tx connection\nerr := versioncontrolops.DoltGC(ctx, tx)\n// after: use a non-transactional connection\ntx.Rollback()\nconn, _ := db.Conn(ctx)\ndefer conn.Close()\nerr := versioncontrolops.DoltGC(ctx, conn)","handlingStrategy":"try-catch","validationCode":"// DOLT_GC cannot run inside an explicit transaction — verify autocommit first\nvar inTx int\n_ = conn.QueryRowContext(ctx, \"SELECT @@autocommit\").Scan(&inTx)\nif inTx != 1 {\n\treturn errors.New(\"DoltGC requires a non-transactional autocommit connection\")\n}","typeGuard":"func isTxErr(err error) bool { return strings.Contains(err.Error(), \"transaction\") }\nfunc isUnknownProc(err error) bool { return strings.Contains(err.Error(), \"DOLT_GC\") && strings.Contains(err.Error(), \"not found\") }","tryCatchPattern":"err := versioncontrolops.DoltGC(ctx, conn)\nif err != nil {\n\tif isTxErr(err) {\n\t\treturn fmt.Errorf(\"call DoltGC outside any transaction: %w\", err)\n\t}\n\treturn fmt.Errorf(\"gc failed: %w\", err)\n}","preventionTips":["Never pass a *sql.Tx or in-transaction conn to DoltGC","Run GC after operations complete and transactions are closed","Confirm Dolt version supports DOLT_GC --archive-level before use","Schedule GC during idle periods to avoid concurrent-session conflicts"],"tags":["dolt","garbage-collection","transaction"],"backgroundTag":"dolt-gc-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}