{"record":{"id":"c64153511a075e33","repo":"sipeed/picoclaw","slug":"failed-to-save-config-w-c64153","errorCode":null,"errorMessage":"failed to save config: %w","messagePattern":"failed to save config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/picoclaw/internal/model/command.go","lineNumber":124,"sourceCode":"\t\tif model.Enabled && model.ModelName == modelName {\n\t\t\tmodelFound = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif !modelFound && modelName != LocalModel {\n\t\treturn fmt.Errorf(\"cannot found model '%s' in config\", modelName)\n\t}\n\n\t// Update the default model\n\t// Clear old model field and set new model_name\n\toldModel := cfg.Agents.Defaults.ModelName\n\n\tcfg.Agents.Defaults.ModelName = modelName\n\n\t// Save config back to file\n\tif err := config.SaveConfig(configPath, cfg); err != nil {\n\t\treturn fmt.Errorf(\"failed to save config: %w\", err)\n\t}\n\n\tfmt.Printf(\"✓ Default model changed from '%s' to '%s'\\n\",\n\t\tformatModelName(oldModel), modelName)\n\tfmt.Println(\"\\nThe new default model will be used for all agent interactions.\")\n\n\treturn nil\n}\n\nfunc formatModelName(name string) string {\n\tif name == \"\" {\n\t\treturn \"(none)\"\n\t}\n\treturn name\n}\n","sourceCodeStart":106,"sourceCodeEnd":140,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/cmd/picoclaw/internal/model/command.go#L106-L140","documentation":"picoclaw model <alias> validated the alias and updated cfg.Agents.Defaults.ModelName in memory, but config.SaveConfig failed to write the file — no change was persisted. The wrapped error names the cause: permission denied, read-only filesystem, disk full, or a save-time validation/marshal failure.","triggerScenarios":"Config file or directory not writable by the current user (often after running picoclaw under sudo earlier); read-only mounts (containers, WSL); disk-full; config content failing save-time validation.","commonSituations":"Root-owned config from mixed sudo/non-sudo use; containers with read-only home; runners out of disk.","solutions":["Read the wrapped error: 'permission denied' → sudo chown -R $(id -u):$(id -g) <config-dir>; 'no space left' → free space","Re-run picoclaw model <alias> after fixing — the failed save left no partial state","For validation failures, fix the field named in the error","Avoid mixing sudo and non-sudo picoclaw invocations against the same config"],"exampleFix":"# before\n$ picoclaw model custom-prefer\nfailed to save config: ... permission denied\n\n# after\n$ sudo chown -R $(id -u):$(id -g) ~/.config/picoclaw\n$ picoclaw model custom-prefer","handlingStrategy":"try-catch","validationCode":"f, err := os.OpenFile(configPath, os.O_WRONLY|os.O_APPEND, 0)\nif err != nil {\n  return fmt.Errorf(\"config %s not writable: %w — fix ownership before changing models\", configPath, err)\n}\nf.Close()","typeGuard":"func isConfigSaveError(err error) bool {\n  return err != nil && strings.Contains(err.Error(), \"failed to save config\")\n}","tryCatchPattern":"if err := config.SaveConfig(configPath, cfg); err != nil {\n  if errors.Is(err, os.ErrPermission) {\n    // nothing was persisted; fix chown/permissions, then re-run picoclaw model <alias>\n  }\n  return fmt.Errorf(\"failed to save config: %w\", err)\n}","preventionTips":["Fix config ownership after any sudo-run of picoclaw","Mount containers' home read-write, or point the config at a writable path","Treat save failures as atomic — safe to re-run the same command after repair"],"tags":["config","cli","filesystem","persistence"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}