Skip to content

Conversation

@mafredri
Copy link
Member

@mafredri mafredri commented Nov 25, 2025

Description

This PR fixes an issue where GetLatestWorkspaceAppStatusesByAppID returned an unbounded number of rows for a given app ID, which could cause performance issues for noisy or long-running AI tasks.

Changes

  • Renamed GetLatestWorkspaceAppStatusesByAppID to GetLatestWorkspaceAppStatusByAppID (singular)
  • Changed SQL query from :many to :one
  • Added LIMIT 1 to the SQL query to only fetch the most recent status
  • Updated all usages to handle a single result instead of a slice
  • Changed empty result checks from len(latestAppStatus) == 0 to latestAppStatus.ID == uuid.Nil

Impact

This change reduces database query overhead for workspace app status updates, particularly for long-running AI tasks that update their status frequently. Previously, fetching the latest status would return all historical statuses; now it returns only the most recent one.

Fixes #20862


🤖 PR was written by Claude Sonnet 4.5 Thinking using mux and reviewed by a human 🏄🏻‍♂️.

GetLatestWorkspaceAppStatusesByAppID returned all app statuses for a
given app ID, which could be unbounded for long-running AI tasks. Only
the most recent status was used, so we now:

- Rename query to GetLatestWorkspaceAppStatusByAppID (singular)
- Change query type from :many to :one
- Add LIMIT 1 to SQL query
- Update usages to handle single result instead of slice

Fixes #20862

---

🤖 PR was written by Claude Sonnet 4.5 Thinking and reviewed by a human 🏄🏻‍♂️.
@mafredri mafredri force-pushed the fix-github-issue-20862 branch from d98e3ca to 066114f Compare November 25, 2025 13:05
@mafredri mafredri changed the title fix(database): limit GetLatestWorkspaceAppStatusByAppID to 1 row perf(coderd/database): limit GetLatestWorkspaceAppStatusByAppID to 1 row Nov 25, 2025
@mafredri mafredri marked this pull request as ready for review November 25, 2025 13:49
@mafredri mafredri merged commit 37fc664 into main Nov 25, 2025
32 checks passed
@mafredri mafredri deleted the fix-github-issue-20862 branch November 25, 2025 14:56
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: GetLatestWorkspaceAppStatusesByAppID returns an unbounded number of rows

3 participants