{"record":{"id":"a819e3b1bc323c93","repo":"plandex-ai/plandex","slug":"error-writing-model-settings-file-v","errorCode":null,"errorMessage":"error writing model settings file: %v","messagePattern":"error writing model settings file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/model_settings.go","lineNumber":192,"sourceCode":"\t}\n\n\tsettings, apiErr := api.Client.GetSettings(CurrentPlanId, CurrentBranch)\n\tif apiErr != nil {\n\t\treturn false, fmt.Errorf(\"error getting settings: %v\", apiErr)\n\t}\n\n\tserverHash, err := settings.GetModelPack().ToModelPackSchema().ModelPackSchemaRoles.Hash()\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"error hashing model pack: %v\", err)\n\t}\n\n\tif localHash == serverHash {\n\t\treturn false, nil\n\t}\n\n\terr = WriteModelSettingsFile(path, settings)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"error writing model settings file: %v\", err)\n\t}\n\n\treturn true, nil\n}\n\n// save settings in file to server\nfunc SyncPlanModelSettings() error {\n\tsettings, err := api.Client.GetSettings(CurrentPlanId, CurrentBranch)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting settings: %v\", err)\n\t}\n\n\tupdatedSettings, apiErr := ApplyModelSettings(GetPlanModelSettingsPath(CurrentPlanId), settings)\n\tif apiErr != nil {\n\t\treturn fmt.Errorf(\"error applying model settings: %v\", err)\n\t}\n\n\tres, updateErr := api.Client.UpdateSettings(CurrentPlanId, CurrentBranch, shared.UpdateSettingsRequest{","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/model_settings.go#L174-L210","documentation":"When the local hash differs from the server hash, WriteModelSettingsFile(path, settings) overwrites the local file with the server settings. If that write fails (permission, serialization, or rename failure inside the helper), the error is wrapped as this message. The function then aborts with the local file left stale.","triggerScenarios":"WriteModelSettingsFile fails: the settings file or its directory is read-only or owned by another user, the disk is full, settings cannot be marshaled to JSON, or the parent directory does not exist.","commonSituations":"Running the CLI as a different user than the one who owns the settings file (root vs user); read-only home mount in a container; full disk; settings directory deleted while the CLI was running.","solutions":["Fix permissions on the settings file and its directory: chown to the current user and ensure write access (chmod u+w).","Check disk space (df -h) and free space if the filesystem is full.","Ensure the parent directory returned by GetPlanModelSettingsPath exists (mkdir -p).","If marshaling fails (inner error mentions json), update the CLI so WriteModelSettingsFile supports the server settings schema."],"exampleFix":"// before\nerr = WriteModelSettingsFile(path, settings)\nif err != nil {\n    return false, fmt.Errorf(\"error writing model settings file: %v\", err)\n}\n// after: ensure the directory exists before writing\nif err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {\n    return false, fmt.Errorf(\"error creating settings dir: %w\", err)\n}\nif err := WriteModelSettingsFile(path, settings); err != nil {\n    return false, fmt.Errorf(\"error writing model settings file: %w\", err)\n}","handlingStrategy":"validation","validationCode":"path := lib.GetPlanModelSettingsPath(planID)\ndir := filepath.Dir(path)\nif fi, err := os.Stat(dir); err != nil || !fi.IsDir() {\n    os.MkdirAll(dir, 0o755)\n}\nif err := unix.Access(path, unix.W_OK); err != nil && os.Getenv(\"SKIP_CHECK\") == \"\" {\n    return fmt.Errorf(\"settings file not writable: %w\", err)\n}","typeGuard":"func writable(path string) bool {\n    f, err := os.OpenFile(path, os.O_WRONLY, 0)\n    if err == nil { f.Close(); return true }\n    return false\n}","tryCatchPattern":"updated, err := lib.SaveLatestPlanModelSettingsIfNeeded()\nif err != nil && strings.Contains(err.Error(), \"error writing model settings file\") {\n    log.Warnf(\"could not persist server settings locally (permissions/disk?): %v\", err)\n    // proceed; local file stays stale and will retry next run\n    return nil\n}","preventionTips":["Keep one owning user for the settings directory; avoid sudo-created files.","Monitor disk space on the volume holding the settings dir.","Ensure the settings directory exists before running sync commands.","Treat this as non-fatal when possible — the next sync will retry the write."],"tags":["go","filesystem","file-write","permissions"],"backgroundTag":"file-write-permission-denied","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}