fix: 3 critical bugs — Permit2 allowance threshold, Firebase token refresh, create_model notes mismatch#202
Conversation
…nGradient#188) The allowance guard used amount_base * 0.1 (10%) which allowed x402 payments to proceed when only 10% of the required OPG was approved. This caused downstream payment failures when the allowance was between 10-99% of the required amount. Fix: compare allowance_before against the full amount_base so the approval step is skipped only when allowance is already sufficient.
…closes OpenGradient#164, OpenGradient#157) Bug 1 — Firebase idToken expiry (closes OpenGradient#164): ModelHub cached self._hub_user at login time and never refreshed the idToken. Firebase tokens expire after 3600 s, so any API call made more than ~1 hour after construction silently fails with 401. Fix: add _get_auth_token() which checks time.time() against a stored expiry and calls firebase_app.auth().refresh(refreshToken) when the token is within _TOKEN_REFRESH_MARGIN_SEC (60 s) of expiry. All methods now call _get_auth_token() instead of reading idToken directly. Bug 2 — create_model passes version label as notes (closes OpenGradient#157): create_model(model_name, model_desc, version='1.00') called self.create_version(model_name, version) which mapped the version string '1.00' to the positional parameter of create_version. The server ignores that field as a version specifier and auto-assigns its own version string, so the argument was silently discarded. Fix: call self.create_version(created_name, notes=f'Initial version {version}') to make the intent explicit, and rename the local variable from model_name to created_name to avoid shadowing the input parameter.
|
Hey @adambalogh Bug 1 — Bug 2 — Bug 3 — Files changed: |
firebase is an untyped package (type: ignore[import-untyped]), so self._hub_user['idToken'] resolves to Any. Since _get_auth_token() is declared -> str, mypy raised: error: Returning Any from function declared to return 'str' [no-any-return] Fix: wrap with str() cast which is always safe since Firebase idTokens are JWT strings.
|
@adambalogh Error from Root cause: Fix (commit # Before
return self._hub_user["idToken"]
# After
return str(self._hub_user["idToken"]) # cast Any->str for mypy [no-any-return]The |
|
@adambalogh — PR #202 is fully ready to merge! 🚀 All CI checks are green ✅:
The PR is mergeable with no conflicts. As a contributor I don't have write access to merge into |
Summary of Changes
This PR fixes 3 critical bugs found across
opg_token.pyandmodel_hub.py, directly addressing team-reported issues #188, #164, and #157.Bug 1 —
opg_token.py: Permit2 allowance threshold uses 10% instead of 100% (relates to #188)File:
src/opengradient/client/opg_token.pyProblem: The guard used
0.1 * amount_base(10%) instead of the full amount. Any wallet with 10–99% of the required OPG approved would skip the approval step and then fail the x402 payment with an HTTP 402 error downstream — the same symptom reported in issue #188.Bug 2 —
model_hub.py: Firebase idToken expires after 1 hour causing silent 401s (closes #164)File:
src/opengradient/client/model_hub.pyProblem:
ModelHubstored the FirebaseidTokenat login and never refreshed it. Firebase tokens expire after 3600 seconds. Any API call made more than ~1 hour after constructing aModelHubinstance fails silently with 401 Unauthorized.Fix: Added
_get_auth_token()which checks time against a stored expiry timestamp and callsfirebase_app.auth().refresh(refreshToken)when within 60s of expiry. All methods now call_get_auth_token()instead of accessingidTokendirectly.Bug 3 —
model_hub.py:create_model()passes version label as notes tocreate_version()(relates to #157)File:
src/opengradient/client/model_hub.pyProblem:
create_version(model_name, notes='', is_major=False)— theversionstring was mapped to thenotespositional parameter. The server auto-assigns its own version string, so the intent was silently lost and release notes said'1.00'instead of anything descriptive. The local variablemodel_namewas also shadowed.Fix:
Files Changed
src/opengradient/client/opg_token.py— Fix allowance thresholdsrc/opengradient/client/model_hub.py— Add token auto-refresh + fix create_model notesLinked Issues
cc @adambalogh — please review when you get a chance!