omi icon indicating copy to clipboard operation
omi copied to clipboard

Python CLI browser re-login revokes the previous key before replacement mint succeeds

Open aa903061825 opened this issue 2 months ago • 3 comments

At main 294e3772732f780bf610a35d35baf8e51534c6d8, browser re-login can revoke an existing working CLI key even when no replacement key is obtained. In _exchange_firebase_token_for_dev_key, the matching old keys are deleted before the POST that mints the replacement. I reproduced the ordering with the production function and intercepted HTTP on Windows / Python 3.11.9: a 503 response, a 201 response without key, and a connection failure all leave the simulated old key revoked, although re-login raises an error. A successful-mint control passes and unrelated keys remain untouched. Expected: failure to obtain a replacement should not revoke the prior working key. This is distinct from #12982's explicit --api-key local-config replacement path; this report concerns the browser flow's remote DELETE-before-POST ordering.

Minimal offline reproduction (no live service or real credentials)

With the Python CLI and its development dependencies installed, save this as a test and run python -m pytest test_browser_relogin.py -q:

import httpx
import pytest
import respx
from omi_cli.auth import oauth
from omi_cli.errors import AuthError

def test_failed_mint_keeps_previous_key():
    base = "https://api.example.test"
    url = base + "/v1/dev/keys"
    live = {"old-cli-key"}
    events = []

    def revoke(request):
        events.append("delete-old")
        live.remove("old-cli-key")
        return httpx.Response(204)

    def mint(request):
        events.append("mint")
        return httpx.Response(503, json={"detail": "synthetic failure"})

    with respx.mock(assert_all_called=False, assert_all_mocked=True) as router:
        router.get(url).respond(200, json=[
            {"id": "old-cli-key", "name": oauth._cli_key_name()}
        ])
        router.delete(url + "/old-cli-key").mock(side_effect=revoke)
        router.post(url).mock(side_effect=mint)
        with pytest.raises(AuthError):
            oauth._exchange_firebase_token_for_dev_key(
                base, "synthetic-firebase-token"
            )

    assert "old-cli-key" in live, events

Observed assertion failure: ['delete-old', 'mint']. The broader local reproduction has three failing preservation cases (503, missing key, connection failure) and one passing successful-mint control. This tests the real helper with mocked HTTP; it is not a claim of testing Google sign-in or a live Omi account. The current upstream file still has blob b05ff01f4451c6877116e6ad534e9c26e9f1a55e when rechecked before filing.

Following the contribution guide's invitation to suggest paid fixes: @josancamon19, would you consider US$25 via the documented private PayPal process after acceptance and merge for a focused correction and regression coverage? Please confirm the scope and bounty before I submit a PR; no assignment or reward is assumed.

AI disclosure: this investigation and local reproduction were prepared with OpenAI Codex, authorized by @aa903061825. No production requests or private payment details are included.

aa903061825 avatar Sep 08 '26 03:09 aa903061825

I would like to take this issue. I will submit a focused fix that preserves the existing key until replacement mint succeeds, with offline regression coverage. Please confirm the scope and bounty eligibility before merge.

omeriadon avatar Sep 08 '26 06:09 omeriadon

Thanks for the interest, @omeriadon. To avoid duplicate work: I already have a local candidate for this report that snapshots the old matching key IDs, mints and validates the replacement first, and only then attempts cleanup. It also covers failed minting and best-effort cleanup with offline regression tests. It is not submitted or assigned, and no bounty has been approved. I am waiting for maintainer direction on scope and eligibility before opening a PR, as stated in the report. Happy to coordinate once the maintainers choose how they want to proceed.

AI disclosure: this update and the local candidate were prepared with Codex on behalf of @aa903061825.

aa903061825 avatar Sep 08 '26 09:09 aa903061825

Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏

aryanorastar avatar Nov 05 '26 16:11 aryanorastar