mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-04 14:47:16 +01:00
* fix(cat): @cat has resolved to nobody for two days The email-derived-handle retirement renamed the Cat. Its predicate — `username = split_part(email, '@', 1)` — is exactly right for a person, whose public crawlable handle then republishes their email local part. It is exactly wrong for the Cat, because deriving the handle from the address is HOW the Cat is created: cat-account.ts registers `cat@orangecat.invalid` precisely so handle_new_user mints `cat`. So the script matched, and at 2026-08-26 21:58:59Z the handle became `user_0234d5e38e66`. `@cat` is the platform's advertised interface and it resolves by username, so every `@cat` in a message or under a post has since resolved to nobody. No reply anywhere. Found by typing `@` in the composer in production and seeing no Cat in the menu. Nothing went red. The account still existed, /profiles/cat still 301'd through profile_username_history, CI was green, health was 200. The only symptom was silence from the feature whose job is to answer. Three defects, three fixes: POLICY — the retirement could not tell a leaked address from a system identity. Now excluded by property, not by name: RFC 2606 reserves `.invalid` for undeliverable addresses, so there is no mailbox, no owner, and nothing personal in the local part. Hardcoding 'cat' in SQL would have put a second definition of the handle where it could drift from config/cat-identity.ts. Applied to the rename script and to count_email_derived_usernames(), which would otherwise have gone from 0 to 1 and turned the nightly gate red for a profile that is fine. CODE — ensureCatAccount looked the Cat up BY USERNAME, so its self-healing walked straight past a rename: lookup missed, createUser said "already registered", second lookup missed, returned null on every tick. It now keys on the login address, which no policy has reason to rewrite, and treats the handle as a field to assert rather than a key to search by. A rename now repairs itself on the next tick. GATE — nothing checked the product's own claim. checkCatHandle asserts that the name we tell people to type reaches the Cat; a lookup by id would have stayed green throughout. The literal it carries is pinned to CAT_USERNAME by a test, so the duplicate cannot drift. Proven by mutation: restoring the username lookup, removing the re-assert, and drifting the gate's literal each turn the suite red. The migration was rehearsed against production inside a transaction and rolled back — UPDATE 1, DELETE 1, 28 real retired handles untouched, gate still reads 0. Also restores the github.com/catomean links lost when this worktree was reset; the owner rename left them pointing at a redirect. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012dpTLxh5GJWeWTF1UEvcD5 * fix(docs): point at bitbaum, the canonical owner catomean is itself a redirect now — the repos live in the bitbaum org. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012dpTLxh5GJWeWTF1UEvcD5 * fix(mentions): the @ menu was offering rows nobody can read Production has 84 profiles and 74 of them have no display name — the correct consequence of no longer minting names out of email local parts, where NULL is honest. The menu did not account for that, so what it actually showed on a bare `@` was two rows of `user_d58c7dccec41`, printed twice each: once as the name, because the name falls back to the handle, and once as the subtitle. Three changes, all following from the data rather than from taste. A nameless row now shows its handle ONCE, in the position the eye reads first, instead of the same hex string on two lines. A nameless profile is not offered at all on a bare `@`. You cannot be searching for a name that does not exist, so those rows were pure noise in the one position that matters most — the first thing anyone sees when they discover the feature. Type any part of the handle and they come straight back through the existing prefix rules. At equal match quality, a named profile outranks a nameless one. `@u` matches `ursula` and `user_d58c7dccec41` equally well by anything the score can see, and only one of them is a row a human can act on. The tiebreak sits after match quality, never before it, so an exact handle match still wins — a demotion that overrode "this is plainly the row being asked for" would be a worse bug than the one it fixed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012dpTLxh5GJWeWTF1UEvcD5 * chore: leave the CLAUDE.md owner line to #803 Both branches edit the same line; one owner avoids a conflict that would stop CI running on whichever loses. 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>
82 lines
3.6 KiB
PL/PgSQL
82 lines
3.6 KiB
PL/PgSQL
-- Retire the handles that publish someone's email address.
|
|
--
|
|
-- WHAT: every profile whose public username is exactly its owner's email local
|
|
-- part gets a neutral `user_<12 hex>` handle, and any display name that is also
|
|
-- the email local part is cleared. The old handle is recorded in
|
|
-- profile_username_history first, so:
|
|
--
|
|
-- * /profiles/<old> keeps working — it 301s to the new handle
|
|
-- * <old>@orangecat.ch keeps working — LNURL resolves through history
|
|
--
|
|
-- That is the whole reason this is safe to run. A username here is a payment
|
|
-- identifier, not just a label; without the history row this script would
|
|
-- silently break saved Lightning addresses and every inbound link, and nobody
|
|
-- would find out until a payment failed to arrive.
|
|
--
|
|
-- NOT a migration on purpose. It rewrites rows for real accounts, so it is a
|
|
-- deliberate operation someone runs and checks, not something that rides along
|
|
-- with a deploy. (apply-schema.sh would refuse it anyway — see the destructive
|
|
-- guard.)
|
|
--
|
|
-- DRY RUN first — this prints what would change and touches nothing:
|
|
--
|
|
-- sudo docker exec supabase-db psql -U postgres -c "
|
|
-- SELECT p.username AS old_handle,
|
|
-- 'user_' || left(replace(p.id::text,'-',''),12) AS new_handle,
|
|
-- (p.name = split_part(u.email,'@',1)) AS name_also_leaks
|
|
-- FROM public.profiles p JOIN auth.users u ON u.id = p.id
|
|
-- WHERE p.username = split_part(u.email,'@',1)
|
|
-- AND u.email NOT LIKE '%.invalid' ORDER BY 1;"
|
|
--
|
|
-- THEN: sudo docker exec -i supabase-db psql -U postgres -v ON_ERROR_STOP=1 \
|
|
-- -f - < scripts/rename-email-derived-usernames.sql
|
|
--
|
|
-- REVERSIBLE: profile_username_history holds the old handle for every row this
|
|
-- touches, so `UPDATE profiles SET username = h.old_username FROM
|
|
-- profile_username_history h WHERE h.profile_id = profiles.id` puts them back.
|
|
--
|
|
-- SYSTEM ACCOUNTS ARE EXCLUDED (`.invalid`, RFC 2606). Learned the hard way:
|
|
-- the first run retired the Cat. Deriving the handle from the address is HOW
|
|
-- the Cat is created — cat-account.ts registers `cat@orangecat.invalid` so that
|
|
-- handle_new_user mints `cat` — so it matched the predicate perfectly while
|
|
-- leaking nothing, and `@cat` resolved to nobody for two days. An undeliverable
|
|
-- address has no mailbox, so no owner, so no personal information in its local
|
|
-- part. See 20260828070000_system_accounts_keep_their_handles.sql.
|
|
|
|
BEGIN;
|
|
|
|
-- Record first. If this half fails the rename never happens, which is the
|
|
-- correct order: a renamed profile with no history row is a dangling payment
|
|
-- address.
|
|
INSERT INTO public.profile_username_history (old_username, profile_id)
|
|
SELECT lower(p.username), p.id
|
|
FROM public.profiles p
|
|
JOIN auth.users u ON u.id = p.id
|
|
WHERE p.username = split_part(u.email, '@', 1)
|
|
AND u.email NOT LIKE '%.invalid'
|
|
ON CONFLICT (old_username) DO NOTHING;
|
|
|
|
-- Same shape as handle_new_user() and neutralUsernameFor(); see
|
|
-- 20260826130000. A uuid-derived handle cannot collide, so the unique index
|
|
-- cannot abort this.
|
|
UPDATE public.profiles p
|
|
SET username = 'user_' || left(replace(p.id::text, '-', ''), 12),
|
|
updated_at = now()
|
|
FROM auth.users u
|
|
WHERE u.id = p.id
|
|
AND p.username = split_part(u.email, '@', 1)
|
|
AND u.email NOT LIKE '%.invalid';
|
|
|
|
-- A display name set to the email local part is the same leak wearing another
|
|
-- label. NULL rather than a placeholder: the UI already falls back to the
|
|
-- handle, and inventing a name for someone is worse than showing none.
|
|
UPDATE public.profiles p
|
|
SET name = NULL,
|
|
updated_at = now()
|
|
FROM auth.users u
|
|
WHERE u.id = p.id
|
|
AND p.name = split_part(u.email, '@', 1)
|
|
AND u.email NOT LIKE '%.invalid';
|
|
|
|
COMMIT;
|