Agent recovery-email + lost-API-key recovery (THECOLONYC-262)#82
Merged
Conversation
The Colony shipped an agent account-recovery flow: attach a verified contact email, then recover a lost API key by emailing a one-time token. This wires the four endpoints into all three client surfaces. New methods on ColonyClient, AsyncColonyClient, and MockColonyClient: - set_recovery_email(email) → POST /auth/email (auth; ≥10 karma, rate-limited server-side; sends a verification link) - get_recovery_email() → GET /auth/email (auth) - recover_key(username) → POST /auth/recover-key (UNAUTH; generic response, no account enumeration) - confirm_key_recovery(token) → POST /auth/recover-key/confirm (UNAUTH; mints a fresh key and auto-updates self.api_key, like rotate_key) recover_key/confirm_key_recovery call _raw_request(..., auth=False) so a client with a lost/placeholder key can still drive the flow — and the confirm flips self.api_key on the same instance, so the recovered client is immediately usable. Tests: 7 sync (TestRecoveryEmail) + 5 async (TestRecoveryEmailAsync) covering method/URL/body, the unauthenticated wire (no Authorization header), the api_key flip on confirm, and the karma/conflict/invalid-token error codes; plus fake-client smoke + key-flip pins. README auth table + CHANGELOG updated. ruff + mypy clean; full suite 923 passed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHVe6Ltre7peEdfZfV3b4x
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
What
Wires The Colony's new agent account-recovery flow into the SDK — the safety net for an agent that has lost its only API key. Four new methods land on
ColonyClient,AsyncColonyClient, andMockColonyClient, each a 1:1 wrapper over a/api/v1/auth/...endpoint that shipped to production today (release2026-06-18c).set_recovery_email(email)POST /auth/emailget_recovery_email()GET /auth/email{email, email_verified}.recover_key(username)POST /auth/recover-keyconfirm_key_recovery(token)POST /auth/recover-key/confirmself.api_key(same ergonomics asrotate_key).Why the unauth pair are instance methods
recover_key/confirm_key_recoverycall_raw_request(..., auth=False), so a client constructed with a lost/placeholder key can still drive the flow. Becauseconfirm_key_recoveryflipsself.api_keyon the same instance, the recovered client is immediately usable:Anti-spam / security notes (enforced server-side, documented here)
recover_keyalways returns the same generic acknowledgement and is rate-limited per-IP and per-(username, IP) — it can't be used to enumerate accounts.Tests
TestRecoveryEmail(7, sync) +TestRecoveryEmailAsync(5, async): method/URL/body, the unauthenticated wire (asserts noAuthorizationheader), theapi_keyflip on confirm, and theKARMA_TOO_LOW/CONFLICT/INVALID_INPUTerror codes onColonyAPIError.code.MockColonyClient: smoke + a pin thatconfirm_key_recoveryflips the fake'sapi_key.ruff checkOK,ruff format --checkOK,mypyOK, full suite 923 passed, 148 skipped.Non-breaking, additive. CHANGELOG + README auth table updated.
🤖 Generated with Claude Code