{"record":{"id":"c2b1ebe3386887ad","repo":"gastownhall/beads","slug":"acquire-connection-for-compact-w","errorCode":null,"errorMessage":"acquire connection for compact: %w","messagePattern":"acquire connection for compact: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dolt/store.go","lineNumber":2922,"sourceCode":"// Flatten squashes all Dolt commit history into a single commit.\n// Pins a single connection because the stored procedures (DOLT_CHECKOUT,\n// DOLT_RESET, etc.) rely on session-scoped state that would be lost if\n// steps execute on different pooled connections.\nfunc (s *DoltStore) Flatten(ctx context.Context) error {\n\tconn, err := s.db.Conn(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"acquire connection for flatten: %w\", err)\n\t}\n\tdefer conn.Close()\n\treturn versioncontrolops.Flatten(ctx, conn)\n}\n\n// Compact squashes old Dolt commits while preserving recent ones.\n// Pins a single connection for session-scoped stored procedures.\nfunc (s *DoltStore) Compact(ctx context.Context, initialHash, boundaryHash string, oldCommits int, recentHashes []string) error {\n\tconn, err := s.db.Conn(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"acquire connection for compact: %w\", err)\n\t}\n\tdefer conn.Close()\n\treturn versioncontrolops.Compact(ctx, conn, initialHash, boundaryHash, oldCommits, recentHashes)\n}\n\n// UnderlyingDB returns the underlying *sql.DB connection\nfunc (s *DoltStore) UnderlyingDB() *sql.DB {\n\treturn s.db\n}\n\n// =============================================================================\n// Version Control Operations (Dolt-specific extensions)\n// =============================================================================\n\nfunc (s *DoltStore) commitAuthorString() string {\n\treturn fmt.Sprintf(\"%s <%s>\", s.committerName, s.committerEmail)\n}\n","sourceCodeStart":2904,"sourceCodeEnd":2940,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/store.go#L2904-L2940","documentation":"DoltStore.Compact pins one pooled connection because the versioncontrolops.Compact implementation runs session-scoped DOLT_ stored procedures. This error wraps a failure to acquire that connection from the pool, so the squash of old Dolt commits never starts. The real cause (timeout, canceled context, pool exhaustion) is wrapped via %w.","triggerScenarios":"Calling DoltStore.Compact when db.Conn(ctx) returns an error: no free connection in the pool within the context deadline, context canceled, or driver-level connection failure.","commonSituations":"Compacting history while many other operations hold pinned sessions; a background compaction job scheduled with a too-short timeout; CI environments where the Dolt process was torn down between steps.","solutions":["Inspect the wrapped error chain to distinguish pool exhaustion from context cancellation from driver failure.","Ensure all pinned-connection users (Flatten/Compact/commit paths) close connections promptly; leaks exhaust the pool and surface here.","Re-run Compact with a longer context timeout and during a quieter window of concurrent activity.","Confirm database connectivity and credentials if the wrapped error indicates the server is unreachable."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before calling Compact\nif err := ctx.Err(); err != nil { return err }\nstats := db.Stats()\nif stats.MaxOpenConnections > 0 && stats.InUse >= stats.MaxOpenConnections { /* wait or back off */ }","typeGuard":null,"tryCatchPattern":"err := store.Compact(ctx, init, boundary, old, recent)\nif errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n\t// reschedule with longer timeout\n}","preventionTips":["Schedule compaction with generous timeouts and low concurrency.","Close all pinned connections promptly to keep pool headroom.","Monitor sql.DBStats for pool saturation.","Retry compaction after transient driver errors rather than failing the whole job."],"tags":["go","database","connection-pool","dolt"],"backgroundTag":"db-connection-acquire-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}