Skip to content

CI stability: green is a local property, not a global one #60

Backlog

Description

@jherr

Summary

A multi-PR stabilization effort (#58, #59) surfaced that "green CI" in this repo means "the projects a diff happened to touch are green," not "the repo is green." main reports green while carrying latent failures across lint, types, coverage, and tests that only execute when a PR drags a project into nx's "affected" set. Any substantial PR trips a cascade of these. This issue documents the structural causes and the remedies, so we fix the mechanism rather than patching symptoms forever.

Evidence (found while stabilizing)

Real bugs (now fixed in #58/#59):

  • Schema-publish migration persisted a stale doc into index columns (schema-registry: publishing a schema draft doesn't backfill new-field defaults into existing records #57) — reads returned the pre-migration doc.
  • Embedded-PGlite production builds shipped no runtime assets — app/base, app/prm, examples/picks ran vite build without copy-pglite-assets.mjs, so the Docker runtime 500'd on boot forever. This made the Base Docker E2E fail 100% of runs.
  • Onboarding type error — app/base/app/prm passed kind/persistence to defineOnboarding, fields the type dropped; green on main only because nothing there touches those apps.

Latent debt merely exposed by widening the affected set:

  • oxlint violations in store-postgres and cms-api that hadn't run in ages.
  • knip failures (an unused kody/ spike, an app-resolved dependency).
  • Integration tests across ~20 projects at vitest's 5s default, flaking under CI load.
  • Coverage-threshold debt in 7 packages (cms-compat-wp at 45% vs its own 80% threshold, connect-atproto, cms-cli, prm, cms-api, cms-core) — each hard-codes coverage.thresholds and fails when CI forces --coverage.include='src/**' on an affected PR.
  • A real SSE event-delivery issue in the Docker smoke under the cron snapshot worker's load (did not respond to a 10s→30s tolerance bump).

Structural causes

  1. PR CI is nx affected, and nothing runs the full matrix. main's CI doesn't run everything either. Proof: the onboarding test:types error exists on a clean main yet main is green — base:test:types simply never runs there. Green is therefore local to recent diffs.
  2. Cross-cutting concerns checked per-project. Types, coverage, and the PGlite-asset build step are each handled per package. A change to a dependency doesn't reliably re-check dependents (graph edges / cache-input gaps), so cross-package breaks land silently.
  3. Nothing forces main green. main isn't branch-protected; admin-merging past red is routine. Every merge-past-red can bank a new dormant failure.
  4. Config drift, no shared baseline. No shared vitest/build config → per-project testTimeout and coverage.thresholds set ad hoc (18% here, 85% there, 80% elsewhere), tuned to pass under whatever affected condition last ran.
  5. Tests encode wall-clock as correctness. 5s vitest / 5s acquire / 10s SSE tolerances were calibrated for a fast, uncontended machine; the single-client embedded PGlite engine violates them under load.
  6. Critical build steps are opt-in per app. Shipping PGlite's WASM assets is a line each app must remember; nothing enforces it; only a (perpetually-red) smoke would catch the omission.
  7. A perpetually-red check gates nothing and hides the next layer. The Docker E2E was red 100% of the time; fixing the boot only then revealed the SSE issue behind it.

Amplifier: fast, largely agent-driven development (assembly-* workflows, admin-merges) optimizes for forward motion, so the cost — broken dormant projects — stays invisible until someone touches the right file.

Remedies

  • Scheduled full-matrix run on main (nx run-many --all --targets=test:types,test:oxlint,test:lib,test:build,test:knip nightly) so nothing stays dormant; triage its output to a known-debt baseline.
  • Branch protection on main: require PRs + review + conversation resolution immediately; add required status checks once the debt behind them is cleared.
  • Shared vitest/build config so testTimeout, coverage.thresholds, and the PGlite-asset copy can't drift or be forgotten (a vite plugin for the asset copy would make it automatic).
  • Decouple correctness from wall-clock where a test asserts behavior, not latency; raise/standardize timeouts for the single-client embedded engine.
  • Reconcile the coverage gate: the per-project thresholds + forced --coverage.include='src/**' fail broadly; either rely solely on the merge-base regression check (coverage-check.mjs) or set realistic per-project numbers and stop forcing a global include.
  • Investigate the Docker SSE delivery under the cron worker (single-client contention vs a real dispatcher/transport bug).

Already landed

Activity

  1. jherr commented on Dec 1, 2026

    @jherr
    ContributorAuthor

    Coverage gate — fix in #62

    The per-project absolute coverage.thresholds conflict with CI's forced --coverage.include=src/** (needed for the apples-to-apples merge-base comparison). #62 zeros the absolute thresholds in the CI runs, leaving the regression check (coverage-check.mjs) as the sole gate — the design intent. Once a broad PR confirms Coverage green, add Coverage to main's required checks.

    E2E Docker SSE — deep-dive conclusion

    Investigated thoroughly; this is not a code bug with a clean fix, it's an interaction between the embedded engine and the CPU-starved CI runner:

    • Not a deadlock. Snapshot generation (user cms_query in the cron worker) completes; the schedule is also paused before the SSE test runs.
    • Not reproducible off-CI. A faithful local repro (production build, cron interface active, then 12 concurrent workers issuing 1000+ ops to saturate the single PGlite connection) still delivers the SSE event in 0.0s. On real hardware the FIFO queue drains too fast to starve.
    • Mechanism. The SSE endpoint re-resolves the session fresh on every event (packages/api/src/http.ts ~L634) to honor revocation — resolveSession({fresh}) → auth.getUser → a read on the embedded engine's single connection. On the shared CI runner (CPU-starved, WASM PGlite), that per-event check serializes behind the write's own commit + dispatcher work and cumulatively exceeds the 30s SSE window.
    • Why the obvious fix doesn't work. Caching the session to make delivery connection-free breaks a tested security invariant — events.test.ts > "rechecks session revocation before emitting another event" requires the fresh check before each emit. The frame must not go out to a revoked session, so the DB revocation check can't be deferred or cached.

    Remediations (pick per appetite)

    • Accept + keep E2E non-required (current). It's a stress test of the embedded engine under CPU-starved CI; real deployments use pooled Postgres (multiple connections) and don't hit this.
    • Give the SSE revocation check a dedicated connection so it can't starve behind content writes (a second PGlite handle, or run the Docker smoke's SSE portion against pooled Postgres). The "correct" fix; a meatier change.
    • CI-side: run the E2E Docker smoke on a larger runner, or treat the SSE latency assertion as advisory.
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions