Reviewed trail #1034 — Simplify CLI login management (dip/simplify-login-management, 1 commit, 44 files, −1754 net). I read the full diff and ran the touched packages' tests (internal/entireclient/contexts, cmd/entire/cli/auth — both pass).
What it does well
Single-login invariant is enforced in the writer, not just at call sites (writeCredential collapses multi-entry input); the refresh-before-access write order and the "delete credentials before metadata" logout contract both survive the rewrite; metadata is scoped by config-dir hash so test/CI isolation still holds; CLAUDE.md and docs/architecture/upstream-host-resolution.md are updated in the same PR.
Blocking
1. contexts.json is shared with entiredb's CLIs — this PR stops writing it and starts deleting it.
The removed comments state it outright ("shared with entiredb's CLIs", "Both CLIs share the same file so a login from either is visible to the other"). Corroborating evidence: on main nothing in this repo ever writes JurisdictionAudiences or a JurisdictionService token — only the other CLI does, through that file. Consequences:
- entiredb reads the user as logged out after migration removes the file.
internal/entireclient/contexts/contexts.go:269 — every Save/Modify from entire silently os.Removes a contexts.json the other CLI may have just written.
- Worse,
readNoLock migrates only when the keychain entry is absent, so a re-created contexts.json is never re-read. Jurisdiction audiences recorded there become permanently invisible to deleteContextKeychain, so entire logout leaves 8h-TTL data-plane bearers on the machine — precisely the contract TestRemoveContext_DeletesJurisdictionTokens pinned before it was deleted.
Either land a coordinated entiredb change, or keep contexts.json as the interop surface and put only the "one current login" pointer in the new entry.
2. Legacy file with contexts but no current_context is destroyed with no cleanup — contexts.go:211-213: os.Remove with the error discarded, no token deletion, whole context list gone. Reachable state: File.Delete deliberately clears current_context while keeping other entries, and the other CLI writes this file too. The keychain slots are then orphaned forever (nothing can ever find them). Untested branch.
3. The lock moved off the file it protects — contexts.go:86/100/149 now flock <configDir>/login, but the migration reads and deletes contexts.json while any other writer (older entire binary, entiredb) is still locking contexts.json itself. Torn read / lost write in exactly the window where it matters.
Should fix
4. RecordLogin can delete a jurisdiction token it just claimed — cmd/entire/cli/auth/contexts.go:100-108. Slots are keyed (audience, handle), not per-core: the sameLogin branch copies JurisdictionAudiences onto next, then a later previous with the same handle on a different core calls deleteContextKeychain, deleting that same slot. The migration path guards this explicitly via currentAudiences (contexts.go:227-231); RecordLogin doesn't. Low blast radius (forces a re-exchange) but leaves dangling metadata and contradicts its sibling.
5. Coverage deleted for behavior that was kept. deleteContextKeychain still skips blank audiences and still aborts logout on a failed jurisdiction delete, but both tests went away with the multi-account ones. Per the repo's own rule, the multi-login tests should go; these two shouldn't. Also uncovered: finding 2's branch, and the migration audience guard.
6. Doc over-deletion. upstream-host-resolution.md lost material that is still accurate and unrelated to single-login: the /.well-known/entire-api.json payload shape, the aud == host origin rationale, the "no fallback without discovery" rule, and all key-file pointers. Trim the context-selection prose, keep the rest.
Notes
- Switching accounts no longer revokes the old server-side session:
RecordLogin drops the previous credentials locally, and with --all-contexts gone there's no path to revoke them. Worth calling out deliberately.
contexts.Load failing on a locked/denied keyring now hard-errors read-only commands (entire status) that previously answered "logged out". Consider mapping that on read paths where logged-out is a valid answer.
CHANGELOG.md isn't updated, though entire auth contexts, entire auth use, and logout --all-contexts are all removed — breaking surface.
- Stray
<configDir>/login lock file is created and never cleaned up.
Want me to post these as trail findings on #1034 (or as review comments), and if so which ones?