{"record":{"id":"18b44a171c37cf41","repo":"gastownhall/beads","slug":"failed-to-get-current-commit-for-state-w","errorCode":null,"errorMessage":"failed to get current commit for state: %w","messagePattern":"failed to get current commit for state: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/backup_export.go","lineNumber":175,"sourceCode":"\t\t// interval (checked by maybeAutoBackup via state.Timestamp)\n\t\t// applies to the next command. Without this, a sync that keeps\n\t\t// failing — e.g. a slow/overloaded shared Dolt server — retries\n\t\t// on EVERY bd command instead of once per interval, turning a\n\t\t// transient slowdown into a self-amplifying storm (the 2026-07\n\t\t// shared-dolt CPU-pin incident). LastDoltCommit is deliberately\n\t\t// left unchanged so change-detection still sees pending work and\n\t\t// a real backup runs once the failure clears.\n\t\tstate.Timestamp = time.Now().UTC()\n\t\tif saveErr := saveBackupState(dir, state); saveErr != nil {\n\t\t\tdebug.Logf(\"backup: failed to persist throttle state after error: %v\\n\", saveErr)\n\t\t}\n\t\treturn nil, err\n\t}\n\n\t// Update watermarks\n\tcurrentCommit, err := store.GetCurrentCommit(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get current commit for state: %w\", err)\n\t}\n\tstate.LastDoltCommit = currentCommit\n\tstate.Timestamp = time.Now().UTC()\n\n\tif err := saveBackupState(dir, state); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn state, nil\n}\n\n// truncateHash returns the first 8 characters of a hash, or the full string if shorter.\nfunc truncateHash(h string) string {\n\tif len(h) > 8 {\n\t\treturn h[:8]\n\t}\n\treturn h\n}","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/backup_export.go#L157-L193","documentation":"During 'bd backup' export, after creating the backup, the code reads the current Dolt commit hash via store.GetCurrentCommit(ctx) to record it as a watermark in the backup state. If that read fails, the export is aborted and this wrapped error is returned. It indicates the Dolt storage layer could not report its HEAD commit despite the backup itself succeeding up to that point.","triggerScenarios":"store.GetCurrentCommit(ctx) returns an error inside runBackupExport, e.g. the Dolt database has no commits (empty/uninitialized dolt_dir), the Dolt session/engine is corrupted, or an underlying SQL/driver failure occurs while querying the commit log. Called from maybeAutoBackup and tests like TestRunBackupExport_PersistsThrottleOnFailure.","commonSituations":"Backing up a beads workspace whose .beads database directory exists but has never been committed; disk corruption or partial clone leaving the Dolt log unreadable; transient driver/IO errors during auto-backup after sync.","solutions":["Inspect the wrapped underlying error (%w) for the actual Dolt/driver failure and fix that first","Run 'bd dolt' style checks or re-initialize the database: ensure at least one commit exists (bd init / a sync creates commits)","Delete or repair the corrupted .beads/dolt state and restore from a previous backup","If auto-backup keeps failing, fix the DB then run 'bd backup sync' manually to refresh watermarks"],"exampleFix":"// before\nstate.LastDoltCommit = state.LastDoltCommit // stale value on failure\n// after\ncurrentCommit, err := store.GetCurrentCommit(ctx)\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to get current commit for state: %w\", err)\n}\nstate.LastDoltCommit = currentCommit","handlingStrategy":"retry","validationCode":"// ensure the DB has at least one commit before backup\nif out, err := exec.Command(\"bd\", \"list\", \"--limit\", \"1\").Output(); err != nil || len(out) == 0 {\n\treturn fmt.Errorf(\"database has no commits; run bd init / bd sync first\")\n}","typeGuard":"if store == nil || store.GetCurrentCommit == nil { /* cannot read commit watermark */ }","tryCatchPattern":"currentCommit, err := store.GetCurrentCommit(ctx)\nif err != nil {\n\tvar derr *driver.Error\n\tif errors.As(err, &derr) { /* repair/reinit DB */ }\n\treturn nil, fmt.Errorf(\"failed to get current commit for state: %w\", err)\n}","preventionTips":["Never back up a workspace that has never been committed; run bd init + a sync first","Monitor disk health and Dolt directory integrity on backup hosts","Retry transient commit-read failures with backoff before failing the backup","Keep watermarks optional so a watermark read failure can degrade to a warning"],"tags":["dolt","backup","storage","go"],"backgroundTag":"dolt-commit-read-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}