{"record":{"id":"9041bd0f097b596f","repo":"gastownhall/beads","slug":"reclaimexpiredleases-w","errorCode":null,"errorMessage":"ReclaimExpiredLeases: %w","messagePattern":"ReclaimExpiredLeases: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/issue.go","lineNumber":1937,"sourceCode":"\n// WakeExpiredDefers returns every expired DATED defer to open (see\n// issueops.WakeExpiredDefersInTx) and reports how many permanent issues and\n// wisps woke. The caller owns persistence: commit with a wake message iff\n// issues > 0, and with the ephemeral plain-COMMIT form iff only wisps woke\n// (wisp tables are dolt_ignored, so their wake needs a SQL commit but must\n// mint no version commit).\nfunc (u *issueUseCaseImpl) WakeExpiredDefers(ctx context.Context) (issues, wisps int, err error) {\n\tissues, wisps, err = u.issueRepo.WakeExpiredDefers(ctx)\n\tif err != nil {\n\t\treturn 0, 0, fmt.Errorf(\"WakeExpiredDefers: %w\", err)\n\t}\n\treturn issues, wisps, nil\n}\n\nfunc (u *issueUseCaseImpl) ReclaimExpiredLeases(ctx context.Context, olderThan time.Duration, filter types.ReclaimFilter, actor string) ([]types.ReclaimedLease, error) {\n\tout, err := u.issueRepo.ReclaimExpiredLeases(ctx, olderThan, filter, actor)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"ReclaimExpiredLeases: %w\", err)\n\t}\n\treturn out, nil\n}\n","sourceCodeStart":1919,"sourceCodeEnd":1941,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/issue.go#L1919-L1941","documentation":"ReclaimExpiredLeases wraps any error returned by the underlying issue repository's lease-reclaim operation. The use-case layer adds the 'ReclaimExpiredLeases:' prefix so callers can tell which storage operation failed while preserving the original driver/DB error via %w. It indicates lease reclaim (taking over expired leases on issues/wisps) could not be completed.","triggerScenarios":"Calling issueUseCaseImpl.ReclaimExpiredLeases(ctx, olderThan, filter, actor) when the underlying issueRepo.ReclaimExpiredLeases query fails — e.g. Dolt/DB connection error, SQL error in the reclaim UPDATE/SELECT, or storage layer unavailable.","commonSituations":"Background lease-reclaim sweeps running while the Dolt database is restarting or unreachable; schema drift between beads versions causing SQL errors; concurrent write contention during a batch reclaim.","solutions":["Inspect the wrapped error chain (errors.Unwrap / %v of the error) to find the underlying driver failure","Verify the Dolt database is reachable and the server is up (bd dolt status / connection settings)","Retry the reclaim after the storage layer recovers; the operation is safe to re-run","If SQL/schema errors appear, run the beads migration/upgrade path to reconcile the schema"],"exampleFix":"// before\nissues, err := uc.ReclaimExpiredLeases(ctx, ttl, filter, actor)\nif err != nil {\n\treturn err // loses context\n}\n// after\nif err != nil {\n\tlog.Printf(\"lease reclaim failed: %v\", err) // log full wrapped chain\n\tvar recov bool\n\tif errors.As(err, &driverErr) { recov = retryReclaim(ctx) }\n\treturn fmt.Errorf(\"reclaim: %w\", err)\n}","handlingStrategy":"retry","validationCode":"// check storage reachability before reclaim\nif err := pingDolt(ctx); err != nil {\n\treturn fmt.Errorf(\"storage unavailable, skipping reclaim: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"out, err := uc.ReclaimExpiredLeases(ctx, ttl, filter, actor)\nif err != nil {\n\tvar wrapped error\n\tif errors.As(err, &wrapped) { log.Printf(\"reclaim failed, driver says: %v\", wrapped) }\n\treturn fmt.Errorf(\"reclaim: %w\", err) // safe to retry later\n}","preventionTips":["Run lease reclaim in a retry loop with backoff","Monitor Dolt server health before scheduled sweeps","Keep beads and its schema on matching versions"],"tags":["go","storage","lease-reclaim","wrapped-error"],"backgroundTag":"storage-operation-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}