Skip to content

flake: TestTasksNotification/TemplateTaskWorkingFromIdle #1218

@flake-investigator

Description

@flake-investigator

CI Failure Details

CI Run Link: https://github.com/coder/coder/actions/runs/20498829535

Failed Job: test-go-pg (windows-2022)

Commit Info:

  • SHA: 05529139bc9b90f01fc0ef4f413adc2f3febdbb7
  • Author: Danielle Maywood
  • Date: 2025-12-24

Failure Signature

From the Windows job logs:

  • Test: TestTasksNotification/TemplateTaskWorkingFromIdle
  • Location: coderd/aitasks_test.go:1637
  • Assertion:
    • Error: "[]" should have 1 item(s), but has 0

The failure occurs when the test expects exactly one notification to have been enqueued:

Error Trace: C:/actions-runner/coder/coder/coderd/aitasks_test.go:1637
Error:      "[]" should have 1 item(s), but has 0
Test:       TestTasksNotification/TemplateTaskWorkingFromIdle

Root Cause Hypothesis (most likely)

This test seeds multiple workspace_app_statuses rows in a tight loop using dbgen.WorkspaceAppStatus, which defaults CreatedAt to dbtime.Now():

CreatedAt: takeFirst(orig.CreatedAt, dbtime.Now())

If multiple inserts happen within the same clock tick (more likely on Windows due to coarser timestamp resolution), two seeded statuses can end up with identical created_at values.

The production query that determines the “latest” status is:

SELECT *
FROM workspace_app_statuses
WHERE app_id = @app_id::uuid
ORDER BY created_at DESC, id DESC
LIMIT 1;

When created_at ties, the tie-breaker becomes random-ish for test data because UUIDs are random. That can cause the handler to think the latest status was already working, so it treats the new working update as a no-op transition and skips notification enqueueing.

This explains why the test sometimes observes notifyEnq.Sent(...) == [].

Suggested Fix

Make the test’s seeded history deterministic by explicitly setting CreatedAt when inserting tc.latestAppStatuses so that the “latest” row is always the intended one.

Example approach:

  • pick a base := dbtime.Now()
  • for older statuses use base.Add(-2*time.Second), base.Add(-1*time.Second), etc.
  • ensure the intended “latest” status has the greatest timestamp

Assignment Analysis

Most relevant recent change touching TestTasksNotification is:

  • f2a1a7e8c3beda4f40a545beb4d62efa23b401d1 ("gate AI task notifications on agent ready state")

That commit modified TestTasksNotification and the related notification gating logic in coderd/workspaceagents.go, so assigning to the author of that change for triage.

Related Issues

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions