{"record":{"id":"3d89623364d6e91e","repo":"gastownhall/beads","slug":"failed-to-get-rows-affected-w-3d8962","errorCode":null,"errorMessage":"failed to get rows affected: %w","messagePattern":"failed to get rows affected: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/unclaim.go","lineNumber":91,"sourceCode":"\t// oldIssue.RowVersion detects a claim that changed hands (or was released,\n\t// or closed) between that read and this write exactly as precisely as the\n\t// old `assignee = <actor>` predicate did, without embedding a\n\t// spelling-sensitive string comparison in SQL. force does not exempt this\n\t// check: force only widens WHO may unclaim, not whether the row is still\n\t// the one we read.\n\tresult, err := tx.ExecContext(ctx, fmt.Sprintf(`\n\t\tUPDATE %s\n\t\tSET assignee = '', status = 'open', updated_at = ?,\n\t\t    started_at = NULL, row_lock = ?\n\t\tWHERE id = ? AND status IN ('open', 'in_progress') AND row_lock = ?\n\t`, issueTable), now, freshRowLock(), id, oldIssue.RowVersion)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to unclaim issue: %w\", err)\n\t}\n\n\trowsAffected, err := result.RowsAffected()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get rows affected: %w\", err)\n\t}\n\n\tif rowsAffected == 0 {\n\t\t// The pre-checks passed, so a 0-row result means the row changed\n\t\t// underneath us: re-read to disambiguate an ownership change from a\n\t\t// status change. actorMatches, not verbatim, mirrors the precheck above.\n\t\tcurrent, gerr := GetIssueInTx(ctx, tx, id)\n\t\tif gerr != nil {\n\t\t\treturn fmt.Errorf(\"failed to unclaim issue %s: no matching row\", id)\n\t\t}\n\t\tif !force && !actorMatches(current.Assignee, actor) {\n\t\t\treturn fmt.Errorf(\"%w: %s is held by %s; coordinate with the holder — pass --force only if their claim is abandoned (crashed agent, expired lease)\",\n\t\t\t\tstorage.ErrNotOwner, id, current.Assignee)\n\t\t}\n\t\treturn fmt.Errorf(\"failed to unclaim issue %s: no matching row\", id)\n\t}\n\n\treturn finishUnclaimInTx(ctx, tx, eventTable, id, actor, oldIssue)","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/unclaim.go#L73-L109","documentation":"After the UPDATE, UnclaimIssueInTx calls result.RowsAffected() and wraps any driver error here. The library needs the affected-row count to detect a lost optimistic-lock race (0 rows), so a failure here means the driver could not report it and the unclaim outcome is indeterminate.","triggerScenarios":"Driver failing on RowsAffected() after the UPDATE: unsupported driver capability, connection reset, or driver bug mid-transaction.","commonSituations":"Custom/misbehaving storage driver lacking RowsAffected support; connection dropped between UPDATE and RowsAffected; backend not exposing affected-row counts.","solutions":["Inspect the wrapped driver error; treat as transient and retry the whole unclaim if connection-related.","Use the supported driver behind the storage driver interface rather than a custom backend.","Check driver version compatibility and upgrade if RowsAffected is known-buggy.","Verify the connection/transaction is still alive at the point of the call."],"exampleFix":"// before\ncustomStore := NewStore(myOddDriver) // driver lacks RowsAffected support\n// after\nstore := NewStore(supportedDoltDriver) // standard driver via storage boundary","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := store.ReleaseIssue(ctx, id); err != nil {\n\tif strings.Contains(err.Error(), \"rows affected\") {\n\t\t// driver-level failure: retry with fresh transaction or switch driver\n\t}\n}","preventionTips":["Stick to supported storage drivers via the driver interface boundary.","Retry whole transactions on transient driver failures.","Keep driver and database versions current and tested together."],"tags":["database","driver","transaction","optimistic-locking"],"backgroundTag":"db-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}