{"record":{"id":"63749b14656ba2bc","repo":"plandex-ai/plandex","slug":"refresh-failed-save-w","errorCode":null,"errorMessage":"refresh failed - save: %w","messagePattern":"refresh failed - save: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/claude_max.go","lineNumber":334,"sourceCode":"\t\t\treturn nil, 0, fmt.Errorf(\"refresh failed - read body: %w\", err)\n\t\t}\n\t\treturn nil, resp.StatusCode, fmt.Errorf(\"refresh failed - status %d: %s\", resp.StatusCode, b)\n\t}\n\n\tvar r types.OauthResponse\n\tif err := json.NewDecoder(resp.Body).Decode(&r); err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"refresh failed - decode: %w\", err)\n\t}\n\n\tnewCreds := &types.OauthCreds{\n\t\tOauthResponse: r,\n\t\tExpiresAt:     time.Now().Add(time.Duration(r.ExpiresIn) * time.Second),\n\t}\n\n\t// persist updated creds\n\taccountCreds.ClaudeMax = newCreds\n\tif err := SetAccountCredentials(accountCreds); err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"refresh failed - save: %w\", err)\n\t}\n\n\treturn newCreds, resp.StatusCode, nil\n}\n","sourceCodeStart":316,"sourceCodeEnd":339,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/claude_max.go#L316-L339","documentation":"refreshCreds wraps an error from SetAccountCredentials after a successful token refresh — the new Claude Max credentials could not be persisted to local account storage. The refresh itself succeeded, so the session works but the new tokens are at risk of not being saved.","triggerScenarios":"SetAccountCredentials(accountCreds) returns an error while persisting the refreshed OauthCreds — typically a filesystem permission error, read-only disk, corrupt or unwritable credentials file, or serialization failure.","commonSituations":"Home directory or ~/.config permissions changed (running as a different user/container), disk full or read-only filesystem, credentials file corrupted or locked by another process, or HOME env var unset so the path resolves unexpectedly.","solutions":["Check permissions and ownership of the credentials file/directory; ensure the process user can write it (chown/chmod as needed).","Check free disk space and that the filesystem is not mounted read-only.","Verify HOME/XDG paths resolve to the expected directory when running in containers or CI.","If the file is corrupt, back it up and remove it so a fresh one can be written, then re-login.","Proceed with the in-memory newCreds even if persistence fails, and log a warning prompting re-auth."],"exampleFix":"// before\nif err := SetAccountCredentials(accountCreds); err != nil {\n    return nil, 0, fmt.Errorf(\"refresh failed - save: %w\", err)\n}\n// after\nif err := SetAccountCredentials(accountCreds); err != nil {\n    log.Printf(\"warning: could not persist refreshed credentials: %v; using in-memory creds\", err)\n    return newCreds, resp.StatusCode, nil // still usable this session\n}","handlingStrategy":"fallback","validationCode":"// preflight: can we write where credentials live?\nf, err := os.OpenFile(credsPath, os.O_CREATE|os.O_WRONLY, 0o600)\nif err != nil {\n    log.Printf(\"credential path not writable: %v\", err)\n}\nif f != nil { f.Close() }","typeGuard":null,"tryCatchPattern":"if err := SetAccountCredentials(accountCreds); err != nil {\n    log.Printf(\"warning: persisting refreshed creds failed: %v; continuing with in-memory creds\", err)\n    return newCreds, resp.StatusCode, nil // degrade gracefully\n}","preventionTips":["Ensure the process user owns or can write the credentials directory (check after container/user changes).","Monitor free disk space where credentials are stored.","Write atomically (temp file + rename) to avoid corrupt credential files.","Set HOME explicitly in containers/CI so the path resolves predictably."],"tags":["filesystem","persistence","permissions","credentials"],"backgroundTag":"credentials-file-write-failed","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"}