{"record":{"id":"3d6391f57c64aca4","repo":"charmbracelet/crush","slug":"permission-request-failed-w","errorCode":null,"errorMessage":"permission request failed: %w","messagePattern":"permission request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/lsp_rename.go","lineNumber":71,"sourceCode":"\n\t\t\tedit, err := resolved.client.Rename(ctx, resolved.path, resolved.line, resolved.char, params.NewName)\n\t\t\tif err != nil {\n\t\t\t\tslog.Error(\"Failed to rename symbol\", \"error\", err, \"symbol\", params.Symbol)\n\t\t\t\treturn fantasy.NewTextErrorResponse(fmt.Sprintf(\"rename failed: %s\", err)), nil\n\t\t\t}\n\t\t\tif edit == nil {\n\t\t\t\treturn fantasy.NewTextResponse(fmt.Sprintf(\"No rename edits generated for symbol '%s'\", params.Symbol)), nil\n\t\t\t}\n\n\t\t\tsessionID := GetSessionFromContext(ctx)\n\t\t\tif sessionID != \"\" && permissions != nil {\n\t\t\t\tgranted, err := permissions.Request(ctx, permission.CreatePermissionRequest{\n\t\t\t\t\tSessionID:   sessionID,\n\t\t\t\t\tToolName:    RenameToolName,\n\t\t\t\t\tDescription: fmt.Sprintf(\"Rename '%s' to '%s'\", params.Symbol, params.NewName),\n\t\t\t\t})\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fantasy.ToolResponse{}, fmt.Errorf(\"permission request failed: %w\", err)\n\t\t\t\t}\n\t\t\t\tif !granted {\n\t\t\t\t\treturn NewPermissionDeniedResponse(), nil\n\t\t\t\t}\n\t\t\t}\n\n\t\t\taffectedFiles := collectAffectedFiles(edit)\n\n\t\t\tif files != nil && sessionID != \"\" {\n\t\t\t\tfor _, path := range affectedFiles {\n\t\t\t\t\tcontent, err := os.ReadFile(path)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tslog.Warn(\"Failed to read file for version tracking\", \"path\", path, \"error\", err)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif _, err := files.CreateVersion(ctx, sessionID, path, string(content)); err != nil {\n\t\t\t\t\t\tslog.Warn(\"Failed to create file version\", \"path\", path, \"error\", err)\n\t\t\t\t\t}","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/agent/tools/lsp_rename.go#L53-L89","documentation":"When an LSP rename targets a path outside the working directory, a permission request is created and submitted. If the permissions subsystem itself errors (store failure, context cancellation), the error is wrapped as 'permission request failed'. This is distinct from an explicit denial, which returns a permission-denied response instead.","triggerScenarios":"Invoking the LSP rename tool on an out-of-working-dir path while permissions.Request fails: DB (permission store) unavailable, context canceled mid-request, or a malformed session ID.","commonSituations":"Database locked or corrupted during permission persistence; user canceled the TUI prompt closing the context; running headless where the permission service isn't wired.","solutions":["Inspect the wrapped %w error for the underlying cause.","Ensure the SQLite database backing permissions is writable and not locked.","Retry the rename; transient DB or context issues resolve on a fresh attempt.","Keep the rename target inside the working directory to skip the permission path entirely."],"exampleFix":"// before\nRename(ctx, params) // db locked -> permission request failed\n// after\n// ensure no other process holds the DB lock, then retry\nRename(ctx, params)","handlingStrategy":"try-catch","validationCode":"// ensure DB-backed permission store reachable before tool call\nif err := permissions.Ping(ctx); err != nil { return err }","typeGuard":"null","tryCatchPattern":"_, err := renameTool(ctx, params)\nif err != nil {\n    if strings.Contains(err.Error(), \"permission request failed\") {\n        // retry once after checking DB health / context cancellation\n    }\n}","preventionTips":["Avoid canceling the context while a permission prompt is pending","Keep SQLite DB healthy (no locks/corruption) for permission storage","Prefer in-working-dir operations that skip permission requests"],"tags":["permissions","lsp","rename"],"backgroundTag":"permission-request-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}