Skip to content

fix(setup): the provisioned admin has no sign-in email on PostgreSQL (#3554) - #3802

Merged
dolho merged 2 commits into
devfrom
fix/3554-admin-no-email
Oct 19, 2026
Merged

dolho merged 2 commits into
devfrom
fix/3554-admin-no-email

Conversation

@dolho

@dolho dolho commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The PostgreSQL admin seed (UserOperations.update_user_password, create branch) inserted email=username. A hosted install's admin therefore read as email = "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 left email NULL.
  • The create branch now leaves email NULL, matching SQLite.
  • Installs that already carry the value are cleaned by a data migration on both tracks: a SQLite MIGRATIONS entry and Alembic 0100_admin_email_not_username (parent 0099_agent_peer_skill_grants). It nulls users.email only where it equals users.username and has no @, so a real address is never touched. It is idempotent and guarded on the username/email columns existing. The Alembic downgrade is a deliberate no-op.

Fixes #3554

Tests

tests/unit/test_3554_admin_seeded_without_email.py (red on dev, green here):

  • a created admin has a NULL email;
  • the migration clears only username-as-email rows and is idempotent (a real address and an @-bearing value equal to its username are kept);
  • the migration is registered on both tracks.

Locally: that file and test_1160_migration_atomicity.py pass; the wider migration/schema/users/admin/setup unit selection passed (1032) apart from test_1160, which this change first broke on a pre-username users table and which the column guard fixed. check_alembic_heads: 1 head. Not run: the PostgreSQL pg-migrations job and the hosted-install walk from the issue (B24).

🤖 Generated with Claude Code

…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 obasilakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review + validate-pr: request changes. The fix is correct. CI is red on a test regression it causes.

Blocking

  1. tests/unit/test_ent720_email_binding.py:99-104 (TestUniqueAndOneWriter::test_the_password_upsert_cannot_insert_a_duplicate) fails in regression diff; reproduced locally (1 failed / 38 passed). The test expects the create branch of update_user_password(email, …) to insert email=username and hit EmailInUseError. 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 by test_update_user_refuses_a_held_address and 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_email goes red with the users.py fix reverted.
  • Both migration tracks are present. check_alembic_heads against current dev finds one head.
  • Every caller of update_user_password passes admin_username(): database.py:887, database.py:903, routers/setup.py:310.
  • No secrets or PII in the diff.

@obasilakis obasilakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>

@obasilakis obasilakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking test fixed in f7fbce4; CI green. The case-sensitive email = username match in the cleanup migration is still open as a non-blocking follow-up, and #3723 will need re-parenting onto this PR's 0100 (or vice versa) depending on merge order.

@dolho
dolho merged commit 88f5e30 into dev Oct 19, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants