{"record":{"id":"a5fbf25819aff44c","repo":"router-for-me/CLIProxyAPI","slug":"post-auth-persist-hook-failed-w","errorCode":null,"errorMessage":"post-auth persist hook failed: %w","messagePattern":"post-auth persist hook failed: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/api/handlers/management/auth_files_fields.go","lineNumber":755,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"token record is nil\")\n\t}\n\th.mergeExistingAuthFileMetadata(record)\n\tstore := h.tokenStoreWithBaseDir()\n\tif store == nil {\n\t\treturn \"\", fmt.Errorf(\"token store unavailable\")\n\t}\n\tif h.postAuthHook != nil {\n\t\tif err := h.postAuthHook(ctx, record); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"post-auth hook failed: %w\", err)\n\t\t}\n\t}\n\tsavedPath, errSave := store.Save(ctx, record)\n\tif errSave != nil {\n\t\treturn savedPath, errSave\n\t}\n\tif h.postAuthPersistHook != nil {\n\t\tif errHook := h.postAuthPersistHook(ctx, record); errHook != nil {\n\t\t\treturn savedPath, fmt.Errorf(\"post-auth persist hook failed: %w\", errHook)\n\t\t}\n\t}\n\treturn savedPath, nil\n}\n","sourceCodeStart":737,"sourceCodeEnd":760,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/api/handlers/management/auth_files_fields.go#L737-L760","documentation":"The post-persist hook h.postAuthPersistHook, run after store.Save already succeeded, returned an error. The credential itself is durably stored (savedPath is returned alongside the error), but follow-up side effects — typically config hot-reload or notification of the new auth — failed, leaving the running process potentially unaware of the new record until a reload.","triggerScenarios":"Saving an auth record when the persist hook that triggers watcher/config reload errors — unwritable config snapshot, watcher not running, or an embedder's custom post-persist logic failing after the file write.","commonSituations":"Config hot-reload infrastructure disabled or broken; embedders hooking cache invalidation that hits a dead dependency; transient errors during shutdown races.","solutions":["Treat the record as saved: verify with a GET on the auth list rather than re-saving blindly","Fix the hook's underlying failure using its wrapped error (watcher running, config writable)","Trigger a manual config reload or restart so the new credential is picked up","If the hook's work is retryable, retry just the reload rather than the whole save"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"savedPath, err := h.saveTokenRecord(ctx, record)\nif err != nil && strings.HasPrefix(err.Error(), \"post-auth persist hook\") && savedPath != \"\" {\n    // record IS persisted; trigger a manual reload instead of re-saving\n    log.Warnf(\"auth persisted to %s but reload hook failed: %v\", savedPath, err)\n    err = nil\n}","preventionTips":["Check savedPath before retrying — a re-save may duplicate side effects","Keep watcher/config-reload infra running whenever the management API is enabled"],"tags":["hooks","state-sync","watcher","auth"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}