gabriel / muse public
fix task/225-fix-old-key-deregistration-lookup #1 / 1
AI Agent gabriel · 1 day ago · Sep 18, 2026 · Diff

fix: look up old key_id via hub instead of recomputing it (musehub#221 follow-up)

Found running the migration for real against localhost, staging, and production: old-key deregistration 404'd on all three ("could not deregister old key ... HTTP Error 404: Not Found"). The code computed old_key_id = sha256(identity_id, public_key_b64) locally and assumed it would match what the hub stored -- but the hub computed that same hash from whatever public_key_b64 *encoding* the account's original registration request used, which can predate conventions the current client uses (e.g. an unprefixed vs. canonically-prefixed base64url string). Recomputing it client-side is fragile by construction: it's only correct if the encoding history is reproduced exactly.

Added `_hub_get()` (auth.py, mirrors `_hub_delete()`) and use it to fetch the account's key list via the already-existing `GET /api/auth/keys/{handle}` endpoint, matching the old key by its *fingerprint* (which we already know authoritatively -- it's what's in identity.toml) rather than recomputing its key_id. This sidesteps the encoding-history problem entirely: the hub tells us the real key_id, we don't have to reconstruct it.

Both the lookup and the delete remain non-fatal on failure, matching `muse auth rotate`'s behavior -- the new key is already registered regardless of whether old-key cleanup succeeds.

Rewrote test_deregisters_old_key_after_successful_add to assert the delete targets the key_id returned by the (mocked) hub lookup -- using a key_id that deliberately does NOT match what the old recompute-based logic would have derived, so the test only passes under the new lookup-based implementation. Added tests for: old fingerprint missing from the hub's key list (skip delete, still non-fatal), and the lookup call itself failing (non-fatal). Updated the two existing tests that reach the deregistration path to mock the new _hub_get call.

Tests: 53/53 in test_migrate_hub_scoping.py, 149/149 across the full migrate/rotate/register targeted set.

sha256:bfd014ea21257cca982f8e389be81f60616acc78fb3d84f767601fea6d35a7f5 sha
+3 ~8 symbols
3 changed · 1195 in snapshot files
sha256:20b38e0857231dfd8c460238e3c97ce2b6b1e56424038fe0c8e9b5ecd0697b7c snapshot
+3
symbols added
~8
symbols modified
3
files changed
1195
files in snapshot
0
dead code introduced
Semantic Changes 11 symbols
~ muse/cli/commands/auth.py .py 1 symbol added
+ _hub_get function function _hub_get L533–552
Files Changed
~3
1195 in snapshot
← Older Oldest on task/225-fix-old-key-deregistration-lookup
All commits
Newer → Latest on task/225-fix-old-key-deregistration-lookup

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:bfd014ea21257cca982f8e389be81f60616acc78fb3d84f767601fea6d35a7f5 --body "your comment"