feat(profiles): ask the swept accounts for a display name (#912)

* fix(profiles): give the swept accounts their display name back

Reported as "user accounts like my mother's lost their names". They did, on
2026-08-26 21:58:59Z — the timestamp is on her row's updated_at to the second.

scripts/rename-email-derived-usernames.sql did two correct things in an order
that made them wrong together:

  1. UPDATE profiles SET username = 'user_' || left(hex(id), 12)
  2. UPDATE profiles SET name = NULL   -- where name was the email local part

Both are right on their own. A handle republishing someone's email local part
is a leak on a crawlable page, and a display name quietly set to the same
string is that leak wearing another label. Step 2 even justifies clearing the
name rather than inventing a placeholder:

    "NULL rather than a placeholder: the UI already falls back to the
     handle, and inventing a name for someone is worse than showing none."

True when written, false by the time it ran: step 1 had just replaced that
handle with twelve hex characters. The two halves of one script invalidated
each other's assumption, and a person was left with no name AND no readable
handle. 72 of 99 profiles matched the predicate, so this is most of the user
base rendering as hex to each other in every thread, mention and profile card.

Nothing went red. The sweep is correct-by-design, the rows still exist, health
stayed 200 — the same silence that hid the Cat's two-day outage from the
identical sweep (20260828070000). The Cat got a repair migration. The humans
did not. This is theirs.

RESTORES name from the display name the user gave their OAuth provider. Not a
new source of truth: it is exactly what handle_new_user() has used for every
signup since 20260826130000. Accounts predating that trigger never had it
applied, which is why they fell back to the email at all. Parity, not policy.

Deliberately does NOT: restore usernames (they ARE the leak, and
profile_username_history exists so nobody has to guess); write a name equal to
the email local part under any path, case-insensitively — some providers put
the address in that field, so repairing one leak is a plausible route back into
the other; overwrite anyone who has since chosen a name; or invent anything.
Profiles with no usable metadata keep NULL, and the migration reports how many
and says they must be ASKED.

Adds count_email_derived_names() + a nightly invariant at baseline 0. The
handle had a watcher; the name column — the one the sweep actually cleared —
had none. That gap only became dangerous because this migration adds the first
write path setting `name` from provider metadata: a door with no lock would
repeat the original mistake one column over.

check:rpc-exists 37/37, check:migration-versions 65 unique.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2LBioUzJP4oBL9LeH9qAe

* feat(profiles): ask the swept accounts for a display name

The half of the 2026-08-26 repair that SQL cannot do.

20260907090000 restored `name` for everyone whose OAuth provider had given us
one. It could not invent a name for the rest, and inventing one is precisely
the mistake being repaired — so those people have to be asked. This asks them.

Conditioned on the MINTED handle, not merely on a missing display name:

    !display_name?.trim() && /^user_[0-9a-f]{8,}$/.test(username)

That second clause is the whole design. Someone who chose a readable username
and simply never filled in a display name is not broken and does not need a
high-priority nag. Dropping it turns a repair for ~72 swept accounts into a
prompt shown to most of the platform — a fix becoming spam.

Proved by mutation rather than by passing: widening the condition to the naive
`!display_name` fails three tests, including the negative that matters
(`does NOT show for a user who picked a readable handle and skipped the name`).
Restored, 9 pass. Both mint widths are covered — 20260818140000 minted 8 hex,
20260826130000 mints 12 — and `user_smith` is somebody's chosen name, not a
mint, so it does not match.

Priority is `high`, not `critical`: being nameless degrades every interaction,
it does not block one. `critical` is reserved for things that stop the product
working.

NOT VERIFIED BY OBSERVATION, deliberately stated: the card only renders for an
account with a minted handle and no name, and the account available to me has
both a handle and a name. The condition is proven by test; the rendering is
not. Clearing a display name and loading the dashboard would close that.

Full verify green on a corrected dependency tree: 288 files, 2713 tests.
(The worktree had zod 3.25.76 installed against a package.json asking for
^4.5.4 — a stale node_modules from before main's zod 3→4 bump — which produced
eight type errors in files this branch never touched. `pnpm install
--frozen-lockfile` cleared all of them. Worth knowing: the install layer failed
as eight plausible-looking type errors, and the signal was a version number
rather than anything in the compiler output.)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2LBioUzJP4oBL9LeH9qAe

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
CatoandClaude Opus 5 authored and GitHub committed 2026-09-07 03:11:10 -07:00
1 parent 06621602ca
commit 4fda83518e
2 files changed
+97

No files matched your search

@@ -0,0 +1,72 @@
/**
* The prompt that asks the accounts swept on 2026-08-26 for a display name.
*
* The positive case is the easy half. The one that matters is the NEGATIVE:
* a user who chose a readable handle and simply has not filled in a display
* name is not broken, and must not be given a high-priority nag. Conditioning
* on "no display name" alone would have caught every such person — which is how
* a repair turns into spam.
*/
import { describe, expect, it } from 'vitest';
import { TASK_DEFINITIONS } from '@/services/recommendations/tasks';
import type { UserContext } from '@/services/recommendations/types';
const task = TASK_DEFINITIONS.find(t => t.id === 'set-display-name');
function ctx(profile: Partial<UserContext['profile']>): UserContext {
return {
profile: { id: 'u1', ...profile },
entityCounts: {},
hasWallet: false,
profileCompletion: 0,
} as UserContext;
}
const shows = (profile: Partial<UserContext['profile']>) => task!.condition(ctx(profile));
describe('set-display-name task', () => {
it('exists and is not critical — being nameless degrades every interaction, it does not block one', () => {
expect(task).toBeDefined();
expect(task!.priority).toBe('high');
});
it('shows for an account the sweep left nameless behind a minted handle', () => {
expect(shows({ username: 'user_a3eaa53c23cd', display_name: null })).toBe(true);
});
it('does NOT show for a user who picked a readable handle and skipped the name', () => {
// The whole reason the condition tests the handle and not just the name.
expect(shows({ username: 'adelina', display_name: null })).toBe(false);
});
it('stops showing once the name is restored or entered', () => {
expect(shows({ username: 'user_a3eaa53c23cd', display_name: 'Metal Music' })).toBe(false);
});
it('treats a whitespace-only name as no name', () => {
expect(shows({ username: 'user_a3eaa53c23cd', display_name: ' ' })).toBe(true);
});
it('treats an empty-string name as no name', () => {
// The messages API coerces a NULL name to '' on the way out, so both shapes
// reach the client and both mean "unnamed".
expect(shows({ username: 'user_b4c9f3272af7', display_name: '' })).toBe(true);
});
it('matches both the 8-hex and 12-hex mints', () => {
// 20260818140000 minted 8 chars, 20260826130000 mints 12. Both are ours.
expect(shows({ username: 'user_a3eaa53c', display_name: null })).toBe(true);
expect(shows({ username: 'user_a3eaa53c23cd', display_name: null })).toBe(true);
});
it('does not match a handle that merely starts with user_', () => {
// `user_smith` is somebody's chosen name, not a mint.
expect(shows({ username: 'user_smith', display_name: null })).toBe(false);
});
it('survives a missing username without throwing', () => {
expect(shows({ username: null, display_name: null })).toBe(false);
expect(shows({ display_name: null })).toBe(false);
});
});
+25
View File
@@ -86,6 +86,31 @@ export const TASK_DEFINITIONS: TaskDefinition[] = [
icon: Star,
condition: ctx => !ctx.profile.username,
},
{
id: 'set-display-name',
title: 'Add Your Display Name',
description: 'Other people currently see a string of hex where your name should be',
priority: 'high',
category: 'setup',
action: { label: 'Add Name', href: ROUTES.DASHBOARD.INFO_EDIT },
icon: Edit3,
// Narrow on purpose: only the accounts left nameless AND handle-less by the
// 2026-08-26 email-leak sweep, which retired the handle and cleared a display
// name that was the email local part. Both halves were right; together they
// left ~72 profiles rendering as `user_a3eaa53c23cd` in every thread,
// mention and profile card. See migration 20260907090000.
//
// That migration restored everyone whose OAuth provider had given us a real
// name. It could not invent one for the rest — and inventing one is exactly
// the mistake being repaired — so the remainder have to be ASKED. This is
// the asking.
//
// Conditioned on the MINTED handle, not merely on a missing name: someone who
// chose a readable username and simply has not filled in a display name is
// not broken and does not need a high-priority nag.
condition: ctx =>
!ctx.profile.display_name?.trim() && /^user_[0-9a-f]{8,}$/.test(ctx.profile.username ?? ''),
},
{
id: 'add-wallet',
title: 'Add Bitcoin Wallet',