{"record":{"id":"ae7f8b003d2eb923","repo":"cli/cli","slug":"failed-to-fetch-session-resources-w","errorCode":null,"errorMessage":"failed to fetch session resources: %w","messagePattern":"failed to fetch session resources: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/agent-task/capi/sessions.go","lineNumber":290,"sourceCode":"\t\t\tlatestSessions = append(latestSessions, s)\n\t\t\tif len(latestSessions) >= limit {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tif len(response.Sessions) < pageSize || len(latestSessions) >= limit {\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// Drop any above the limit\n\tif len(latestSessions) > limit {\n\t\tlatestSessions = latestSessions[:limit]\n\t}\n\n\tresult, err := c.hydrateSessionPullRequestsAndUsers(latestSessions)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to fetch session resources: %w\", err)\n\t}\n\n\treturn result, nil\n}\n\n// GetSession retrieves a specific agent session by ID.\nfunc (c *CAPIClient) GetSession(ctx context.Context, id string) (*Session, error) {\n\tif id == \"\" {\n\t\treturn nil, fmt.Errorf(\"missing session ID\")\n\t}\n\n\tu, err := safeurl.JoinPathWithHostPrefix(c.capiBaseURL, \"agents\", \"sessions\", id)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody)\n\tif err != nil {","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/cli/cli/blob/0eeec0b92edbe70199f9768522f831d3534f41ad/pkg/cmd/agent-task/capi/sessions.go#L272-L308","documentation":"Returned by CAPIClient.ListSessions after the pages are fetched and deduplicated: hydrating each session's pull request and user details (hydrateSessionPullRequestsAndUsers) failed. The list call itself worked; the follow-up batched GraphQL lookups for PR node IDs and user node IDs did not. The %w preserves the underlying GraphQL/API error for diagnosis.","triggerScenarios":"hydrateSessionPullRequestsAndUsers issues GraphQL/REST lookups for pullRequest node IDs or user details; these fail with token scope errors, rate limits, deleted/private repos referenced by sessions, or deleted users.","commonSituations":"Token lacks repo read scope so PR hydration 404s; secondary rate limits during large session lists; sessions referencing PRs in repos the token can no longer access; GitHub GraphQL incidents.","solutions":["Inspect the chained error to identify whether PR or user hydration failed and with which HTTP/GraphQL code","Run gh auth status and ensure the token has repo + Copilot scopes; refresh if expired","Wait for rate-limit reset (check X-RateLimit headers / gh api rate_limit) if the inner error is a limit","Retry the command; already-deleted PR/user references may resolve to a clean list on a narrower query"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"result, err := c.ListSessions(ctx, limit)\nif err != nil {\n\tif isRateLimitError(err) {\n\t\ttime.Sleep(backoff) // then retry once\n\t\tresult, err = c.ListSessions(ctx, limit)\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to fetch session resources: %w\", err)\n\t}\n}","preventionTips":["Keep hydration queries batched (the client already batches node IDs) rather than issuing per-session calls","Ensure the token has repo read scope before listing sessions tied to PRs","Wrap list operations in a single retry with backoff for transient GraphQL failures"],"tags":["go","graphql","copilot-api","hydration","rate-limit"],"backgroundTag":null,"analyzedSha":"0eeec0b92edbe70199f9768522f831d3534f41ad","analyzedAt":"2026-08-15T12:31:05.478Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}