{"record":{"id":"7cb6b0167e746d62","repo":"gastownhall/beads","slug":"remove-existing-remote-s-w","errorCode":null,"errorMessage":"remove existing remote %s: %w","messagePattern":"remove existing remote (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/dolt.go","lineNumber":1582,"sourceCode":"\t\tif err := st.AddRemote(ctx, name, url); err != nil {\n\t\t\treturn doltRemoteAddResult{}, fmt.Errorf(\"add remote %s: %w\", name, err)\n\t\t}\n\t\treturn doltRemoteAddResult{}, nil\n\t}\n\n\tif doltutil.RemoteURLsMatch(existingURL, url) {\n\t\treturn doltRemoteAddResult{}, nil\n\t}\n\n\tif !confirm(\"SQL server\", name, existingURL, url) {\n\t\treturn doltRemoteAddResult{Canceled: true}, nil\n\t}\n\tif err := st.RemoveRemote(ctx, name); err != nil {\n\t\t// A remote known only from disk may not be removable through a\n\t\t// cold-started server that doesn't see it yet; the confirmed add\n\t\t// below is what establishes the new URL either way.\n\t\tif !existingFromDiskOnly {\n\t\t\treturn doltRemoteAddResult{}, fmt.Errorf(\"remove existing remote %s: %w\", name, err)\n\t\t}\n\t}\n\tif err := st.AddRemote(ctx, name, url); err != nil {\n\t\treturn doltRemoteAddResult{}, fmt.Errorf(\"add remote %s: %w\", name, err)\n\t}\n\treturn doltRemoteAddResult{}, nil\n}\n\nvar doltRemoteCmd = &cobra.Command{\n\tUse:   \"remote\",\n\tShort: \"Manage Dolt remotes\",\n\tLong: `Manage Dolt remotes for push/pull replication.\n\nSubcommands:\n  add <name> <url>     Add a new remote\n  list                 List all configured remotes\n  remove <name>        Remove a remote\n  reset-data <name>    Replace a remote's data plane after a history squash`,","sourceCodeStart":1564,"sourceCodeEnd":1600,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/dolt.go#L1564-L1600","documentation":"When ensureDoltRemote finds an existing remote with the same name but a different URL, it removes the old remote before adding the new one. If RemoveRemote fails and the remote was visible in the live listing (not disk-only), the removal error is wrapped as 'remove existing remote <name>'. Disk-only remotes are tolerated because the subsequent confirmed add re-establishes the URL.","triggerScenarios":"Changing a remote's URL via `bd dolt remote add <name> <new-url>` where RemoveRemote fails: server write error, remote locked, or driver-level failure — only when the remote was already visible to the running server.","commonSituations":"Pointing an existing 'origin' at a new repo URL; stale server state after a database restore; another process mutating remotes concurrently.","solutions":["Read the wrapped cause; restart the Dolt server session (re-run the command) to clear stale state","Verify current remotes with `bd dolt remote -v`, remove the conflicting one explicitly, then add the new URL","Check for concurrent bd processes and serialize remote operations","If the server persistently cannot remove it, restore .beads dolt state from refs/dolt/data in git"],"exampleFix":"// before\nbd dolt remote add origin https://new-url  # fails if old origin unremovable\n// after\nbd dolt remote remove origin\nbd dolt remote add origin https://new-url","handlingStrategy":"try-catch","validationCode":"remotes, err := st.ListRemotes(ctx)\nif err == nil {\n  for _, r := range remotes {\n    if r.Name == name && r.URL != newURL {\n      fmt.Printf(\"remote %s will be replaced: %s -> %s\\n\", name, r.URL, newURL)\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"res, err := ensureDoltRemote(ctx, st, name, url, confirm)\nif err != nil {\n  if strings.Contains(err.Error(), \"remove existing remote \"+name) {\n    // stale server state: recreate the session or remove the remote explicitly, then retry\n    return res, err\n  }\n}","preventionTips":["Change remote URLs in a single explicit step, not while other bd operations run","Restart bd sessions after restoring dolt state from git to avoid stale remote views","Use the same remote name/URL scheme across the team to avoid constant replacements","Run `bd dolt remote -v` to confirm final state after any URL change"],"tags":["dolt","remote","replace","storage"],"backgroundTag":"dolt-remove-remote-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}