Skip to content

Devcontainers: As a side-effect of deleting agents, it's possible for the stats collector to become sad #685

Open
@mafredri

Description

@mafredri

I did not investigate how this state was achieved, but it happened in my dev environment and it seems plausible that customer could trigger it as well.

[API] 2025-06-10 14:27:13.146 [erro]  coderd.workspaceapps.stats_collector: failed to flush workspace app stats ...
[API] error= report workspace app stats from backlog failed:
[API] github.com/coder/coder/v2/coderd/workspaceapps.(*StatsCollector).flush
[API] /home/coder/coder/coderd/workspaceapps/stats.go:263
[API] - insert workspace app stats failed:
[API] github.com/coder/coder/v2/coderd/workspacestats.(*Reporter).ReportAppStats
[API] /home/coder/coder/coderd/workspacestats/reporter.go:116
[API] - execute transaction:
[API] github.com/coder/coder/v2/coderd/database.(*sqlQuerier).runTx
[API] /home/coder/coder/coderd/database/db.go:213
[API] - pq: insert or update on table "workspace_app_stats" violates foreign key constraint "workspace_app_stats_agent_id_fkey"

Steps to reproduce (somewhat unknown but potentially some or all of these):

  1. Run workspace with devcontainer and sub agents
  2. Recreate devcontainer but fail to delete sub agent (inject/stop race)
  3. Restart workspace
  4. Recreate devcontainer
  5. Potentially observe the above in coderd logs

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions