Repository navigation
fix(setup): the provisioned admin has no sign-in email on PostgreSQL (#3554) - #3802
Conversation
…3554) The PostgreSQL admin seed inserted email=username, so a hosted install's admin read as email 'admin' and the first-run 'Sign-in email' step (pending while the admin has no email) never appeared. The create branch now leaves email NULL, matching the SQLite seed, and a data migration on both tracks (SQLite entry + Alembic 0100) clears email where it equals the username and holds no '@'. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
obasilakis
left a comment
There was a problem hiding this comment.
Review + validate-pr: request changes. The fix is correct. CI is red on a test regression it causes.
Blocking
tests/unit/test_ent720_email_binding.py:99-104(TestUniqueAndOneWriter::test_the_password_upsert_cannot_insert_a_duplicate) fails inregression diff; reproduced locally (1 failed / 38 passed). The test expects the create branch ofupdate_user_password(email, …)to insertemail=usernameand hitEmailInUseError. The create branch now writes no email, so the collision can no longer occur. Delete the test, or rewrite it to assert the created row has a NULL email and does not collide with a held address._insert_user's held-address check stays covered bytest_update_user_refuses_a_held_addressand the writer-census test.
Should fix
2. src/backend/db/migrations.py:5294 and migrations/versions/0100_admin_email_not_username.py:24: WHERE email = username is case-sensitive. The old seed passed the username through normalize_email, which lowercases. With ADMIN_USERNAME=Root, the stored row is email='root', username='Root', and the migration skips it. Use lower(email) = lower(username) on both tracks.
3. Alembic: #3723 adds 0100_merge_agent_config_peer_grants on the same parent, 0099_agent_peer_skill_grants. Whichever PR merges second needs re-parenting onto the other, or dev gets two heads. The two touch different tables, so re-parenting is mechanical.
Info
4. The migration is not limited to role='admin'. It clears any user whose email equals the username and has no @. Such an email can't be used to sign in, so this is harmless.
Verified
test_a_created_admin_has_no_emailgoes red with theusers.pyfix reverted.- Both migration tracks are present.
check_alembic_headsagainst currentdevfinds one head. - Every caller of
update_user_passwordpassesadmin_username():database.py:887,database.py:903,routers/setup.py:310. - No secrets or PII in the diff.
obasilakis
left a comment
There was a problem hiding this comment.
Requesting changes for the failing test in regression diff (item 1 in the review comment above).
…licate (#3554) The create branch no longer copies the username into email, so the ent#720 refusal it pinned cannot happen; the test now asserts the new account has no email and the address keeps its one owner. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
UserOperations.update_user_password, create branch) insertedemail=username. A hosted install's admin therefore read asemail = "admin", which is truthy, so the first-run "Sign-in email" step (pending while the admin has no email) never appeared. The SQLite seed already leftemailNULL.emailNULL, matching SQLite.MIGRATIONSentry and Alembic0100_admin_email_not_username(parent0099_agent_peer_skill_grants). It nullsusers.emailonly where it equalsusers.usernameand has no@, so a real address is never touched. It is idempotent and guarded on theusername/emailcolumns existing. The Alembic downgrade is a deliberate no-op.Fixes #3554
Tests
tests/unit/test_3554_admin_seeded_without_email.py(red ondev, green here):@-bearing value equal to its username are kept);Locally: that file and
test_1160_migration_atomicity.pypass; the wider migration/schema/users/admin/setup unit selection passed (1032) apart fromtest_1160, which this change first broke on a pre-usernameuserstable and which the column guard fixed.check_alembic_heads: 1 head. Not run: the PostgreSQLpg-migrationsjob and the hosted-install walk from the issue (B24).🤖 Generated with Claude Code