{"record":{"id":"af6965cf03417051","repo":"gastownhall/beads","slug":"s-s-af6965","errorCode":null,"errorMessage":"%s; %s","messagePattern":"%s; %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/bd/backup_restore.go","lineNumber":145,"sourceCode":"\t\tfmt.Fprintf(os.Stderr, \"Warning: failed to register backup remote: %v\\n\", err)\n\t\treturn\n\t}\n\tif err := saveDoltBackupConfig(backupURL); err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"Warning: backup registered but failed to save config: %v\\n\", err)\n\t}\n}\n\n// syncProjectIDFromDB reads _project_id from the restored database and\n// updates metadata.json to match, preventing identity mismatch errors.\nfunc syncProjectIDFromDB(ctx context.Context, s storage.DoltStorage) error {\n\tdbID, err := s.GetMetadata(ctx, \"_project_id\")\n\tif err != nil || dbID == \"\" {\n\t\treturn err\n\t}\n\n\tbeadsDir := beads.FindBeadsDir()\n\tif beadsDir == \"\" {\n\t\treturn fmt.Errorf(\"%s; %s\", activeWorkspaceNotFoundError(), diagHint())\n\t}\n\n\tcfg, err := configfile.Load(beadsDir)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif cfg.ProjectID == dbID {\n\t\treturn nil // already in sync\n\t}\n\n\tcfg.ProjectID = dbID\n\treturn cfg.Save(beadsDir)\n}\n\nfunc validateBackupRestoreDir(dir string) error {\n\tif _, err := os.Stat(dir); os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"backup directory not found: %s\\nRun 'bd backup' first to create a backup\", dir)","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/backup_restore.go#L127-L163","documentation":"syncProjectIDFromDB aligns the project ID stored in the workspace config with the one read from the restored database. If reading the DB project ID fails or the workspace's beads directory cannot be located (FindBeadsDir returns \"\"), it combines the active-workspace error with a diagnostic hint via fmt.Errorf(\"%s; %s\", ...). It signals the restored DB is fine but the local workspace config could not be updated.","triggerScenarios":"Called after a successful restore (and in tests). The beads directory lookup fails — running outside any beads workspace / no .beads found up the tree — while fetching the DB project ID also returned no usable value (dbID == \"\").","commonSituations":"Restoring into a scratch/temp directory that has no .beads; running the command from a subdirectory outside the project; BEADS_DIR env var unset and workspace detection failing; partially initialized workspace.","solutions":["Run the restore from within the project root containing .beads so FindBeadsDir resolves","Run 'bd init' in the target directory to create the beads workspace","Set BEADS_DIR (or the equivalent config) to point at the workspace explicitly","Read the first %s segment of the message — it carries the activeWorkspaceNotFoundError cause"],"exampleFix":"// before\nbd backup restore /path/to/backup   # run from ~/scratch (no .beads)\n// after\ncd /path/to/project                 # directory containing .beads\nbd backup restore /path/to/backup","handlingStrategy":"validation","validationCode":"if beads.FindBeadsDir() == \"\" {\n\treturn fmt.Errorf(\"run this command inside a beads workspace (bd init) before syncing project ID\")\n}","typeGuard":"beadsDir := beads.FindBeadsDir(); beadsDir != \"\"","tryCatchPattern":"if err := syncProjectIDFromDB(ctx, bs); err != nil {\n\tif strings.Contains(err.Error(), \"workspace\") {\n\t\t// cd to project root or bd init, then retry\n\t}\n\treturn err\n}","preventionTips":["Always execute restore/sync from the project root that contains .beads","Set BEADS_DIR explicitly in CI to avoid workspace-detection ambiguity","Run 'bd init' on any fresh target directory before restoring into it","Treat this as a post-restore config step; verify cfg.ProjectID after restore"],"tags":["config","workspace","project-id","go"],"backgroundTag":"beads-dir-not-found","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}