Skip to content

fix(copilot): Use state field instead of status for task lifecycle#110793

Merged
JoshFerge merged 1 commit intomasterfrom
jferg/fix-copilot-status-field
Mar 16, 2026
Merged

fix(copilot): Use state field instead of status for task lifecycle#110793
JoshFerge merged 1 commit intomasterfrom
jferg/fix-copilot-status-field

Conversation

@JoshFerge
Copy link
Copy Markdown
Member

@JoshFerge JoshFerge commented Mar 16, 2026

The GitHub Copilot Tasks API returns task lifecycle values (queued, in_progress, completed, failed, timed_out) in the state field, while the status field is always an empty string. Our polling code was checking task_status.status == "completed" which was never true, so Copilot tasks would stay stuck in RUNNING state forever after completion — the PR URL and completion state were never synced back to Sentry.

Validated by hitting the live Copilot API: created a task, polled until completion, and confirmed that state carries the lifecycle values while status is always "". The partner API spec we were given listed status as the field, but the actual API uses state.

Changes:

  • Add state field to GithubCopilotTask model (keep status for forward-compat)
  • Switch polling logic to check task_status.state instead of task_status.status
  • Update test mocks to match real API response shapes (state, in_progress, github_resource, updated_at)

Agent transcript: https://claudescope.sentry.dev/share/7RfoUCo3OmihUbUrznGRpJ0bE9LXTfcbFamSXhLirtc

The GitHub Copilot Tasks API returns lifecycle values (queued,
in_progress, completed, failed, timed_out) in the `state` field,
while `status` is always an empty string. Our polling code was
checking `status == "completed"` which was never true, causing
Copilot tasks to stay stuck in RUNNING state after completion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Agent transcript: https://claudescope.sentry.dev/share/vTbrRfjeNDN7BIW1Jh2qaJrZCaAHBqqDMPUB-etq3w8
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 16, 2026
@JoshFerge JoshFerge marked this pull request as ready for review March 16, 2026 19:55
@JoshFerge JoshFerge requested review from a team as code owners March 16, 2026 19:55
@JoshFerge JoshFerge enabled auto-merge (squash) March 16, 2026 19:57
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Model field name doesn't match real API response
    • Renamed the model field from last_updated_at to updated_at to match the real GitHub Copilot API response shape that the test mock uses.

Create PR

Or push these changes by commenting:

@cursor push 3f7e5a5018
Preview (3f7e5a5018)
diff --git a/src/sentry/integrations/github_copilot/models.py b/src/sentry/integrations/github_copilot/models.py
--- a/src/sentry/integrations/github_copilot/models.py
+++ b/src/sentry/integrations/github_copilot/models.py
@@ -77,7 +77,7 @@
     session_count: int | None = None
     artifacts: list[GithubCopilotArtifact] | None = None
     archived_at: str | None = None
-    last_updated_at: str | None = None
+    updated_at: str | None = None
     created_at: str | None = None
     sessions: list[GithubCopilotSession] | None = None

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

repo_id: int | None = None
status: str | None = None # queued, in_progress, completed, failed, timed_out
status: str | None = None
state: str | None = None # queued, in_progress, completed, failed, timed_out
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model field name doesn't match real API response

Low Severity

The test mock was updated from "last_updated_at" to "updated_at" to match the real Copilot API response shape, but the GithubCopilotTask model field is still named last_updated_at. Since Pydantic ignores unknown fields by default, the API's updated_at value is silently dropped and last_updated_at will always be None when parsing real API responses. This is the same class of bug this PR fixes for status/state — just for a different field.

Additional Locations (1)
Fix in Cursor Fix in Web

@JoshFerge JoshFerge merged commit 7458e6f into master Mar 16, 2026
60 checks passed
@JoshFerge JoshFerge deleted the jferg/fix-copilot-status-field branch March 16, 2026 20:33
JonasBa pushed a commit that referenced this pull request Mar 16, 2026
#110793)

The GitHub Copilot Tasks API returns task lifecycle values (`queued`,
`in_progress`, `completed`, `failed`, `timed_out`) in the `state` field,
while the `status` field is always an empty string. Our polling code was
checking `task_status.status == "completed"` which was never true, so
Copilot tasks would stay stuck in RUNNING state forever after completion
— the PR URL and completion state were never synced back to Sentry.

Validated by hitting the live Copilot API: created a task, polled until
completion, and confirmed that `state` carries the lifecycle values
while `status` is always `""`. The partner API spec we were given listed
`status` as the field, but the actual API uses `state`.

Changes:
- Add `state` field to `GithubCopilotTask` model (keep `status` for
forward-compat)
- Switch polling logic to check `task_status.state` instead of
`task_status.status`
- Update test mocks to match real API response shapes (`state`,
`in_progress`, `github_resource`, `updated_at`)


Agent transcript:
https://claudescope.sentry.dev/share/7RfoUCo3OmihUbUrznGRpJ0bE9LXTfcbFamSXhLirtc
@github-actions github-actions bot locked and limited conversation to collaborators Apr 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants