11 Commits
Author SHA1 Message Date
CatoandClaude eb9b3149fc fix(ci): the E2E fixture no longer signs other runs out, and a dropped request is retried (#1454)
ensure-e2e-fixtures rewrote the shared user's password on every run. GoTrue
ends a user's other sessions on a password change, and every CI run (each PR,
each push) uses the same account, so one run's bootstrap signed another run's
browser out partway: check:broken-words opened /dashboard/cat, /receive and
/send@320 and then 'bounced to sign-in' for the rest (PR run 40504618122, 6.5
minutes instead of 1). The password is now written only when the user does not
already sign in with it.

refresh-e2e-reset-tokens failed main's CI (run 40450576245) on one dropped
request (AuthRetryableFetchError, status 0). A request with no answer is now
retried up to three times; a real refusal is not.


Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-27 22:18:14 +01:00
a99d541b45 fix(db): actors outlived their accounts — the last table in the family (#655)
profiles (#637) and cat_conversations (#651) both cascade from the account
now. Each sweep stopped one table short of done, and `actors.user_id` is
what was left: it references nothing at all. Deleting an account still
leaves the actor standing — the row that owns every product, service,
project, cause, event, loan and asset the person ever published.

15 orphaned actors were live in production. They were `e2e-reset-*`,
`cat-wallet-eval-*` and `cascade-proof-*` rows: the verification of the
earlier fixes leaked rows into the table the next fix would be about.
Purged, behind a guard that proved they owned 0 rows across all 25 child
foreign keys before deleting anything.

Unlike its siblings this one cannot be closed with a constraint, which is
why this adds a check rather than a migration:

  - ON DELETE CASCADE would delete the actor, which cascades on into
    contracts, investments and bookings — destroying the COUNTERPARTY's
    record of an agreement because the other side closed their account.
  - ON DELETE SET NULL is rejected outright by actor_type_check, which
    requires actor_type='user' to have a non-null user_id.

The honest fix is a tombstone — keep the actor, sever the identity — which
needs a deleted/anonymous actor_type. That is a schema decision, not a
drive-by, so it is stated here and left for one.

Until it lands:

  - `actors.orphaned` in the nightly invariant gate. This is the part that
    covers call sites nobody thought to patch, including future ones.
  - the two known leak sites delete the actor explicitly:
    refresh-e2e-reset-tokens.mjs (every CI run) and write-test-supabase.js,
    whose comment claimed "cascade removes profile" — true, and precisely
    the trap: it names the fixed thing while missing the one still broken.

Mutation-tested both directions with --gate: one injected orphan makes it
exit 1, removing it exits 0.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 19:39:49 +00:00
GandGeorgy Butaev f2bfa7cf30 fix(db): profiles outlived their users — make that structurally impossible (#637)
public.profiles had NO foreign key at all. `profiles.id` held an
auth.users id by convention only, so deleting a user removed the auth
row and left the profile standing forever: a public page, a username
still taken, and a row counted by every "how many users" query.

Measured in production today: 115 orphaned profiles. 113 came from the
per-run `e2e-reset-*` CI fixtures minted since 2026-06-12.
refresh-e2e-reset-tokens.mjs was doing its job the whole time — it calls
admin.deleteUser on throwaways older than a day — but with no cascade
the profile survived every single deletion.

The consequence was not cosmetic: 136 of 185 profile rows (73%) were
test accounts, so OrangeCat's own signup numbers were mostly synthetic.
The real figure — 39 profiles, 5 with a bio, 3 created in the last 30
days — was invisible behind them. A metric nobody can trust is worse
than no metric, because it still gets used to decide what to build.

No real end user has been orphaned yet; the other 2 are our own
memtest_* / selfhost-verify+* fixtures. But nothing prevented it, and
"delete my account" must not leave a public profile behind.

- FK profiles.id -> auth.users(id) ON DELETE CASCADE. A delete path you
  have to remember to call is one that eventually is not called; a
  foreign key cannot be forgotten. Added NOT VALID so it governs every
  future write without requiring the 115 existing rows to be deleted —
  purging live production data is a separate, explicit decision and this
  migration must not smuggle it in.
- count_orphaned_profiles(), service_role only, because auth.users is
  not reachable through PostgREST and the nightly gate needs to see it.
- New `profiles.orphaned` invariant in check-data-invariants.mjs — the
  backstop for the constraint being dropped, bypassed, or left NOT VALID
  while something writes around it.

Verified against the production schema in a rolled-back transaction:
migration applies clean, the gate reports 115, and end to end an auth
user insert creates a profile (1) while deleting that user now removes
it (0). Before this, that second number was 1.

The gate will report the 115 existing orphans until they are cleared;
that is the honest state, not a regression. After clearing:
ALTER TABLE public.profiles VALIDATE CONSTRAINT profiles_id_fkey;

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
2026-08-07 00:30:46 +00:00
f96c71611e fix(ci): the merge train deadlocked, and its retry path could never have worked (#642)
* fix(ci): a cancelled base run deadlocked the merge train

Five green PRs sat unmerged for seven hours tonight behind one line:

    [auto-merge] main CI is cancelled — refusing to merge onto a broken base

Refusing a red base is correct. A CANCELLED run is not a red base — it
carries no verdict about the code at all. And it is unrecoverable: the
only thing that produces a new CI run on main is a merge, and merges are
precisely what the guard is blocking. A GitHub Actions outage cancelled
main's run, and the queue could not clear itself. It took a human
`gh run rerun` to move.

This script had ALREADY learned this lesson for PR checks — the
`re-running cancelled run` branch below was added after #603 and #604
stranded the same way — and left the identical hole on the base branch.
Same shape as the top-up settlement bug earlier today: a class retired on
one path and left open on its sibling. Enumerate both sides, or the
backstop only covers the half you were looking at.

So: on `cancelled`, re-run the base run and let the next sweep judge the
real result. A genuine `failure` still blocks, because that IS a verdict.
The existing `status != completed` check keeps re-runs from stacking.

Tested against the real script with a fake `gh` on PATH rather than a
description of it — cancelled re-runs and merges nothing, failure neither
re-runs nor merges, in-progress defers, and a run belonging to an older
commit still waits. Verified non-vacuous: stubbing the new branch out
turns the first test red.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(ci): a re-run could never succeed, so no retry path was ever a recovery path

Re-running main's outage-cancelled CI turned a stalled merge queue into a
genuinely RED main:

    createUser for reset fixture failed AuthApiError:
    A user with this email address has already been registered  (422 email_exists)

`refresh-e2e-reset-tokens.mjs` mints `e2e-reset-${GITHUB_RUN_ID}@…`, and
GITHUB_RUN_ID is **stable across a re-run**. So the second attempt of any
run that reached fixture bootstrap tried to create a user the first
attempt had already created, and the job exited 1.

The consequence is bigger than one red run: **re-running CI could never
succeed**, which silently disabled every recovery mechanism built on
re-running — including this repo's own cancelled-run retry for PRs, added
after #603/#604 stranded, which therefore cannot have worked in any case
where the cancelled run got this far. The retry existed; the thing it
retried was guaranteed to fail. That is the third instance today of a
recovery path nobody had exercised.

It also makes the base-branch retry in the previous commit unsafe on its
own — it would have converted "deadlocked" into "permanently red". The
two belong together.

Fix: key the fixture on the ATTEMPT (`GITHUB_RUN_ID-GITHUB_RUN_ATTEMPT`),
and treat a leftover of the same tag as something to clear rather than
fail on — this fixture is disposable by definition. Anything that makes
CI unrunnable twice in a row disables the recovery paths we depend on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 23:15:38 +00:00
a162724a50 fix(ci): disposable per-run user for the reset E2E — replace fragile smoke queue (#553)
The #546 queue group can't work on GitHub's semantics: a concurrency group
holds at most ONE pending job, so under load a newer arrival (including PR
smoke jobs sharing the group) cancels main's queued job — today it starved
the deploy gate entirely. Reverted.

The correct isolation: only the password-reset test MUTATES shared auth
state (consumes the single-use recovery token, changes the password). It
now gets a disposable user minted per run (e2e-reset-<run-id>@) by
refresh-e2e-reset-tokens.mjs — no shared token to invalidate, no shared
password to flip, so concurrent runs simply can't interfere. Stale
throwaway users are cleaned up opportunistically after 24h. All other
matrix tests only read or are idempotent on the shared fixture user.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-02 14:10:04 +02:00
Georgy ButaevandCursor 0a5f30b770 fix(ci): mint fresh reset tokens per run for P0 matrix
Bootstrap generates single-use recovery sessions, fixes reset URL encoding,
and disables retries for the password-reset test.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-05 00:18:59 +02:00
Georgy ButaevandCursor 3f70ed517d fix(ci): self-heal E2E fixture user during bootstrap
Create or sync the fixture account when missing, pass password to bootstrap,
and wait for actor bootstrap before inserting the fixture project.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 23:53:53 +02:00
Georgy ButaevandCursor 292f4841c3 fix(ci): bootstrap E2E fixtures on Node 20 with ws transport
Use ESM imports plus ws for Supabase realtime init in GitHub Actions.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 23:45:09 +02:00
Georgy ButaevandCursor 9a257e36d6 fix(ci): use CJS for E2E fixture bootstrap script
Avoid Supabase realtime WebSocket init failure on Node 20 in GitHub Actions.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 23:37:05 +02:00
Georgy ButaevandCursor 7e2f34c508 fix(ci): bootstrap E2E fixtures and stabilize reset password test
Ensure self conversation + fixture project before P0 matrix. Keep reset
password fixed so CI login credentials stay valid across runs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-04 23:29:32 +02:00
Your Name 94bfe613b6 chore: deploy local snapshot
Commit current local state for production deploy.
2025-12-10 16:56:40 +01:00