Phase 1 identity substrate: users table, owner user, terminal user binding#147
Open
ClaydeCode wants to merge 4 commits into
Open
Phase 1 identity substrate: users table, owner user, terminal user binding#147ClaydeCode wants to merge 4 commits into
ClaydeCode wants to merge 4 commits into
Conversation
This was referenced Jul 10, 2026
max-tet
requested changes
Jul 11, 2026
…minal user binding Adds the users table (id doubles as the future OIDC sub) and binds every terminal session to a user. The owner user is derived from the default identity: same id (single source of truth for identity), email taken from the identity or synthesized as owner@<domain> since OIDC clients require an email-shaped identifier to auto-provision accounts. ensure_owner_user() runs on every startup after init_default_identity(): creates the owner row if missing and backfills user_id on any terminal that predates this migration. New pairings bind to the owner directly. No behavior or API change otherwise; existing sessions stay valid. Phase 1 of the multi-user identity rollout (embedded OIDC provider). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…nding, User model - users.id is now BIGSERIAL: the owner user is its own entity, decoupled from the shard's identity hash id (which identifies the shard, not the person). The OIDC sub becomes the stringified numeric id in phase 2a. - role is a proper Postgres enum (user_role), mirrored by Role in the new data_model/user.py; ensure_owner_user returns a User model. - terminals.user_id is NOT NULL: the 0002 migration itself creates the owner user and binds existing terminals (existing shards have their identity at migration time; fresh shards have empty tables and get the owner at startup before any pairing). The Python-side backfill helper is gone; ensure_owner_user only creates the owner on fresh shards and backfills the synthesized email for migration-created owners. - pair.py drops the owner-missing fallback — the owner always exists once the app serves requests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The legacy-JSON migration inserted terminals without user_id, violating the new NOT NULL constraint (caught by CI). The owner user is created from the just-migrated default identity, mirroring the 0002 backfill. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
max-tet
force-pushed
the
feature/oidc-phase1-users
branch
from
July 26, 2026 20:36
703fa17 to
7d761f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 1 of the multi-user identity rollout (design docs in the KB, PoC verdict 2026-06-12): the invisible identity substrate that the embedded OIDC provider (phase 2, follow-up PR) builds on.
What this does
userstable (numeric BIGSERIAL ids,user_roleenum,Usermodel indata_model/user.py) — every shard now has an owner user derived from the default identity. The stringified numeric id becomes the OIDCsubin phase 2a; the shard's identity hash id stays what it is — the shard's identity, not the person's.terminals.user_id(NOT NULL) — every terminal session is bound to a user. The migration itself creates the owner and binds existing terminals; new pairings bind at creation.ensure_owner_user()runs at every startup (afterinit_default_identity(), before serving): creates the owner on fresh shards (where the migration ran against empty tables) and backfills the synthesized email for migration-created owners. Idempotent.owner@<shard-domain>— OIDC clients (e.g. Immich) require an email-shaped identifier to auto-provision accounts (PoC finding).No UX or API behavior change. Existing sessions stay valid (cookie/JWT mechanism untouched).
Not in this PR
Recommended reading order
migrations/shard-core-0002-users.sql— schemashard_core/database/users.py— new DB module (conn-first pattern)shard_core/database/terminals.py— insert gainsuser_id, backfill helpershard_core/data_model/terminal.py—Terminal.user_id(optional, backward compatible)shard_core/service/user.py—ensure_owner_user()shard_core/web/public/pair.py— new terminals bind to ownershard_core/app_factory.py— lifespan wiringtests/conftest.py,tests/test_users.py— fixture wiring + coverage🤖 Generated with Claude Code
Test status
Full suite on the stacked branch (this + phase 2a): 190 passed, 1 failed —
test_app_lifecycle.py::test_app_starts_and_stops, which fails identically on cleanmainon this machine (pre-existing, container-start timing), not a regression from this branch.Review round 1 addressed: numeric ids, role enum, NOT NULL binding,
Userdata model, strict owner lookup in pairing.