cli/cli · error

failed to fetch session resources: %w

Error message

failed to fetch session resources: %w

What it means

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.

Source

Thrown at pkg/cmd/agent-task/capi/sessions.go:290

			latestSessions = append(latestSessions, s)
			if len(latestSessions) >= limit {
				break
			}
		}

		if len(response.Sessions) < pageSize || len(latestSessions) >= limit {
			break
		}
	}

	// Drop any above the limit
	if len(latestSessions) > limit {
		latestSessions = latestSessions[:limit]
	}

	result, err := c.hydrateSessionPullRequestsAndUsers(latestSessions)
	if err != nil {
		return nil, fmt.Errorf("failed to fetch session resources: %w", err)
	}

	return result, nil
}

// GetSession retrieves a specific agent session by ID.
func (c *CAPIClient) GetSession(ctx context.Context, id string) (*Session, error) {
	if id == "" {
		return nil, fmt.Errorf("missing session ID")
	}

	u, err := safeurl.JoinPathWithHostPrefix(c.capiBaseURL, "agents", "sessions", id)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), http.NoBody)
	if err != nil {

View on GitHub (pinned to 0eeec0b92e)

Solutions

  1. Inspect the chained error to identify whether PR or user hydration failed and with which HTTP/GraphQL code
  2. Run gh auth status and ensure the token has repo + Copilot scopes; refresh if expired
  3. Wait for rate-limit reset (check X-RateLimit headers / gh api rate_limit) if the inner error is a limit
  4. Retry the command; already-deleted PR/user references may resolve to a clean list on a narrower query
Defensive patterns

Strategy: retry

Try / catch

result, err := c.ListSessions(ctx, limit)
if err != nil {
	if isRateLimitError(err) {
		time.Sleep(backoff) // then retry once
		result, err = c.ListSessions(ctx, limit)
	}
	if err != nil {
		return nil, fmt.Errorf("failed to fetch session resources: %w", err)
	}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15). Data as JSON: /api/errors/ae7f8b003d2eb923. Report an issue: GitHub.