Skip to content

[Bug][gh-copilot] collectOrgMetrics fails with "error parsing response" for organization-1-day endpoint #8789

Closed

Description

@breymander

Search before asking

  • I had searched in the issues and found no similar issues.

What happened

The collectOrgMetrics subtask in the gh-copilot plugin fails immediately with error parsing response when collecting organization-level Copilot usage metrics via the organization-1-day report endpoint. The error occurs for every configured organization, blocks the entire pipeline, and prevents other tasks (Jenkins, Jira, etc.) from completing.

Error from logs:

level=error msg=" [pipeline service] [pipeline #24] [task #5234] subtask collectOrgMetrics ended unexpectedly
    Wraps: (2) error parsing response from orgs/REDACTED_ORG/copilot/metrics/reports/organization-1-day
    Error types: (1) *hintdetail.withDetail (2) *errors.errorString"

The subtask completes in ~1 second (not a timeout), suggesting the GitHub API responds successfully but the response body cannot be unmarshalled into the expected reportMetadataResponse struct.

Environment:

  • DevLake version: v1.0.3-beta10
  • Database: MySQL (CloudSQL)
  • Authentication: Classic PAT with scopes manage_billing:copilot, read:enterprise, read:org
  • Copilot Metrics API policy: enabled
  • PAT owner: organization owner
  • Deployment: Helm on GKE

What do you expect to happen

The collectOrgMetrics subtask should either:

  1. Successfully parse the response from GET /orgs/{org}/copilot/metrics/reports/organization-1-day, or
  2. Provide a clear error message including the HTTP status code and response body when parsing fails (e.g., "unexpected response format, expected JSON object with download_links")

How to reproduce

  1. Deploy DevLake v1.0.3-beta10
  2. Create a gh-copilot connection with a classic PAT and an organization
  3. Add the connection to a blueprint and trigger a pipeline
  4. Observe collectOrgMetrics fails with "error parsing response"

Analysis

The ResponseParser in org_metrics_collector.go expects the response to unmarshal into a reportMetadataResponse struct (containing DownloadLinks). The GitHub API at GET /orgs/{org}/copilot/metrics/reports/organization-1-day?day=YYYY-MM-DD may be returning a response in a format that doesn't match this struct.

Additionally, this error is fatal — it causes the entire pipeline to fail, blocking unrelated tasks like Jenkins and Jira collection that run in the same pipeline stage.

Suggested improvements

  1. Add verbose logging of the raw response body (or at least the HTTP status code and first N bytes) when parsing fails, to make debugging easier
  2. Validate the response format and provide a clear error message (e.g., "unexpected response format, expected JSON object with download_links")

Version

v1.0.3-beta10

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    component/pluginsThis issue or PR relates to plugins
    priority/highThis issue is very important
    severity/p0This bug blocks key user journey and function
    type/bugThis issue is a bug
    on Mar 21, 2026
  2. breymander commented on Mar 23, 2026

    @breymander
    ContributorAuthor

    Root Cause

    Figured out what's going on. On first run, computeReportDateRange in report_download_helper.go iterates 365 days back (reportMaxDays = 365), but the Copilot Usage Metrics Reports API only has data going back to around Deccember 2025. For dates before that, GitHub doesn't return a 404 — it returns a 200 with body "":

    HTTP 200
    Content-Length: 3
    
    ""
    

    The ignore404 callback in report_download_helper.go only handles 404s, so this 200 passes straight through to the ResponseParser in org_metrics_collector.go, which does:

    var meta reportMetadataResponse
    if jsonErr := json.Unmarshal(body, &meta); jsonErr != nil {
        return nil, errors.Default.Wrap(jsonErr, "failed to parse report metadata")
    }

    Unmarshaling "" into a struct fails, and the framework wraps it as the generic "error parsing response" message.

    Suggested fix: Check for empty/non-object bodies ("", null, empty) before the unmarshal and skip the day instead of erroring out. Same issue applies to user_metrics_collector.go and enterprise_metrics_collector.go.

  3. breymander commented on Mar 23, 2026

    @breymander
    ContributorAuthor

    I've created PR #8804 for review.

  4. added a commit that references this issue on Mar 30, 2026
    2e9cca0
  5. added a commit that references this issue on Jul 21, 2026
    c05201d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    component/pluginsThis issue or PR relates to pluginspriority/highThis issue is very importantseverity/p0This bug blocks key user journey and functiontype/bugThis issue is a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions