Skip to content

flaky: pageImports nested CSS recovery test reads a stale watch result #487

Closed

Description

@allisonmahmood

packages/patchy/src/pageImports.test.ts › "rechecks nested CSS edits, refuses the actual importer, and recovers through cycles" failed on the test (22) job with no code cause. The PR only touched portal, serving and core rendering. test (24) passed on the same commit, and the test passed in two local pnpm verify runs.

Failing run: https://github.com/allisonmahmood/patchy-cloud/actions/runs/37049348374/job/110978542626 (PR #485)

After the test rewrites nested.css from the refused @import "lodash/style.css" to a valid import, it expects the next completed Vite watch build to contain color: blue. Instead it got another import_refused error for lodash/style.css.

The likely cause is that one writeFileSync can fire more than one watch event, so the refused write queues two ERROR results in completed. next() then shifts the stale second error instead of the build for the fix. Draining or ignoring results queued before each write, or waiting for the result matching the latest write, would remove the race.

Activity

  1. added
    flaky
    on Oct 2, 2026
  2. allisonmahmood commented on Oct 2, 2026

    @allisonmahmood
    OwnerAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: bug
    Summary: The pageImports nested CSS watch test must tolerate a save that causes more than one rebuild.

    Current behavior:
    The test "rechecks nested CSS edits, refuses the actual importer, and recovers through cycles" queues every ERROR and BUNDLE_END from Vite's build watcher and takes the oldest result after each file write, as if each write produced exactly one result. A plain write truncates the file and then writes it, and that can fire two watch events. The refused write can then leave a second, identical import_refused result in the queue (or one still building when the fix is written). The test reads that stale refusal instead of the build for the fix, and fails on CI (seen on test (22), PR #485).

    Triage found no production defect. The plugin clears its refusal at every buildStart and re-reads nested CSS on every build. patchy dev keeps only the latest build result, so a duplicate rebuild can at worst log an outdated refusal before the good build replaces it. Neither Codex nor I could reproduce the failure locally (40/40 single builds per write; 25/25 passes on Node 22 under full CPU load), so the race is timing-dependent.

    Desired behavior:
    The test checks each distinct result the watcher produces, not one queue entry per write, using the two mitigations the dev server's watch test already uses (its save helper and its inspectedChanges reader):

    1. Write each save atomically: write a temporary file and rename it into place, rather than truncating and writing.
    2. The test's next() helper skips a result identical to the one it last returned. Keep the assertions outside the wait so a new, different error or unexpected CSS still fails the test.

    Clearing the queue before each write is not enough: a rebuild already running can still finish after the fix is written.

    Key interfaces:

    • The test's local Result type ({ css: string } | { error: Error }) and its next() helper.
    • Refusals are LocalError instances, so two refusals of the same import are separate objects. Either confirm that isDeepStrictEqual treats them as equal, or compare them by code and message.

    Acceptance criteria:

    • Before the fix: pushing a fake duplicate refusal into the queue, both before and after the fix is written, makes the test fail. After the fix: the same setup reaches the color: blue build. This is a temporary check and does not ship as a test.
    • The test still fails if the fix write yields a refusal that differs from the previous result, or never produces a blue build.
    • The test passes when looped (for example, 50 runs) on Node 22 and on Node 24.
    • pnpm verify passes.

    Out of scope:

  3. added
    bug
    ready-for-agent
    area:cli
    on Oct 2, 2026
  4. added a commit that references this issue on Oct 3, 2026
    88101a5
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

    area:clibugflakyready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions