Repository navigation
fix(auth): an auth error's hint and recovery follow the failure, the site and the profile - #92
Conversation
…site and the profile A login that another terminal removed or replaced while a command ran now says to run the command again (recovery retry), not to sign in: a bare meshy auth login writes the default profile and makes it active. After create --wait has created its task, that recovery waits for the task instead, so nothing says to run the create again. A stored login that expired without a refresh token, whose key does not open, or whose refresh the token endpoint refuses is signed in again as itself: the command names its profile and region, and on a site other than production the hint says to keep MESHY_BASE_URL_V2 pointing at the login's site. No credential at all, or a --profile that names none, keeps MESHY_BASE_URL_V2 in its hint on such a site. A refresh whose result cannot be written back has no login recovery: the hint says to make the credentials directory writable first. meshy doctor shows these hints as they are, so its help no longer repeats them.
…profile, and the real write failure meshy doctor's "no credential" detail now carries the shared error's hint, so on another site it still says to keep MESHY_BASE_URL_V2 set. A stored profile whose key is a placeholder is signed in again as itself, with its region: a new login of a profile that is not the active one takes the active profile's region. A refresh whose result cannot be written back says to fix what kept the credentials file from being written, which may be the key store rather than the directory.
…account When the stored login a command started with is replaced while it runs, another run is the recovery (retry) only when the profile now holds an OAuth login of the same account. A login of another account, an API key (which names no account) or a removed profile, after which a run without --profile takes another active profile, has no recovery: the hint says to check the account first, since that run could pay with another account. After create --wait has created its task, the same account waits for it; another account cannot (the task is the first account's), so the hint says to wait for it signed in as that account.
…kes the same profile Another run uses the profile --profile names, else the active one. A login of the same account under the run's profile is not enough when another profile was made active meanwhile: a run without --profile would take that one, and could pay with another account. Retry, and after create --wait the wait recovery, now need both; otherwise the hint says to check which account another run would use.
…another account's After create --wait or make has created its task, a login replaced by one that may be another account's leaves result.next out: run as they are, its commands would read the task as that account, and the answer (404) reads as "no such task" to a caller that might create it again. The task id, the submission and the hint, which says to wait signed in as the account that created the task, stay.
…and no output then says otherwise Another run is taken to be the same one only when it would use the same account, the same profile and the same API base: MESHY_BASE_URL_V2 or MESHY_REGION when set, else the region the profile is stored for. The same account signed in again on the other site has no recovery. After create --wait or make has created its task, one decision now drives every output: when another run is the same one, the message, hint, recovery and result.next all name the wait command; otherwise none of them carries a command to run as it is, and the hint says to wait for the task signed in as the account that created it, on the API base it was created on.
A replaced login confirms the same account only with a user id on both sides, and the next run's profile is the --profile the run named, not the active one. Two cases on the create --wait table hold each.
The scripting guide, the D-034 record and the agent skill promised result.next after every failure of an accepted create. When the stored login was replaced mid-run and another run may not use the same account, profile and API base, it is left out; task_id and submission stay, and the hint names the account and API base the task belongs to.
… login was removed The exception covers a stored login removed as well as replaced, with the three conditions (account by user id, profile, API base). The agent skill reads the task id and submission first and result.next only when it is there, and the make guide says when next is left out.
…ft out The make guide no longer restates when result.next is left out: run the next commands when they are there, otherwise wait as the error's hint says. The full rule stays in the scripting guide and D-034.
| func sameAccount(kind Kind, subject string, p *Profile) bool { | ||
| return p != nil && kind == KindOAuth && p.Kind == KindOAuth && subject != "" && p.UserID == subject |
There was a problem hiding this comment.
🟡 False same-account recovery across issuers
When a replacement OAuth login comes from another issuer, sameAccount accepts it if the user IDs match. A fixed API base passes the retry check, so accepted creates publish wait commands that use the other issuer’s token.
Learn more
CredentialsPath uses one development credentials file for all non-production bases. DeviceLogin obtains the user ID from the issuer's token response, and auth login saves that login under the requested profile. With an explicit base, nextSite returns that base even when another site wrote the replacement profile. createAndWait then turns the retry decision into executable task commands. Those commands resolve the replacement token; an API that accepts only its own issuer's tokens rejects the wait.
Example: Start a rigging create with --wait on staging A as profile work, user 123. After submission, sign into staging B under work, where a different account also has ID 123. The first run reports a runnable wait command, but that command sends B's token to A and fails authentication.
Recommended fix: For credentials files shared across sites, require a verified issuer match as well as the user ID before exposing retry or task commands. If the issuer cannot be established, use the existing account-check path. Add a regression test using two OAuth origins and one development credentials file.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if IsNonProdBaseURL(siteBase) { | ||
| return fmt.Sprintf("With %s still set to this API base, run: %s%s (or export MESHY_API_KEY)", BaseURLEnv, login, quote) | ||
| } | ||
| return fmt.Sprintf("Run: %s%s (or export MESHY_API_KEY)", login, quote) |
There was a problem hiding this comment.
🟡 API-key fallback rejected with profiles
When --profile names a missing login, signInHint suggests exporting MESHY_API_KEY. The same command then fails with a usage error because resolve rejects API keys alongside --profile.
Learn more
A missing explicit profile now uses stored to get a sign-in hint. That hint offers an environment API key as an alternative, but resolve checks the environment first and rejects the combination before sending a request.
Example: Run meshy balance get --profile work when work does not exist. Export a usable MESHY_API_KEY as suggested and repeat the command. It exits with a usage error instead of fetching the balance.
Recommended fix: When r.Profile is set, either omit the environment-key alternative or say to drop --profile when using it. Use the same wording for relogin, which offers the same fallback on other explicit-profile errors.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
The shared auth errors every API command prints (and
meshy doctorshows as they are) all saidRun: meshy auth loginwithrecovery: {action: "login"}. For several failures that is the wrong step: a baremeshy auth loginwrites thedefaultprofile and makes it active, and withoutMESHY_BASE_URL_V2it signs in to production. Each error now says what fits the failure, the site and the profile:recoveryretry(waslogin)meshy auth status, with the run's--profile), then run again only if it is the one to uselogin): another run could pay with another accountcreate --wait/makealready created the taskRun: meshy tasks wait <id>; otherwise wait signed in as the account that created it, on the API base it was created on (no output carries a command to run as it is)wait+ that command; otherwise none, and noresult.next(its commands would read the task as another account and get a 404)--profile,--region; on another site, keepMESHY_BASE_URL_V2pointing at itlogin+ the exact command when one runs as is--profilenames none, on a site other than productionMESHY_BASE_URL_V2set, then sign in (with--profilewhen not default)login)error.codeand exit codes are unchanged.meshy doctor'sfixstill comes fromrecovery.commandonly.Evidence
Built at the base (
e22e67d) and at7c93e8d(later commits change only tests and docs), run with a throwaway config dir:workon the China site,meshy balance get --profile work --format jsonBefore:
hint: Run: meshy auth login (or export MESHY_API_KEY),recovery {"action":"login"}After:
hint: Run: meshy auth login --profile work --region cn (or export MESHY_API_KEY),recovery {"action":"login","command":"meshy auth login --profile work --region cn"}MESHY_BASE_URL_V2set to another siteBefore:
hint: Run: meshy auth login (or export MESHY_API_KEY)After:
hint: With MESHY_BASE_URL_V2 still set to this API base, run: meshy auth login (or export MESHY_API_KEY)Before:
… or sign in again. Run: meshy auth login …After:
… or sign in again. With MESHY_BASE_URL_V2 pointing at the site this login came from, run: meshy auth login …Tests:
TestAuthErrorsSayHowToRecoverchecks the stderr hint and the envelope'srecoveryfor each failure.TestALoginReplacedBeforeACreateIsSentchecks, for the same and for another account, that nothing is sent or journaled.TestCreateWaitAfterALoginWasReplacedchecks that nothing says to run the create again, and that only a confirmed outcome (a user id on both logins, the profile--profilenames) carries a runnable command.TestALoginReplacedOnTheProductionFilecovers a profile replaced by another account, another active profile, or the same account on the other site, andMESHY_REGION.go test ./...passes; each guard was broken on purpose and its test went red.Merge Danger
Door: two-way
Revert restores the old hints and recovery.
Blast Radius: auth error hints and
recoveryof every API commandScripts that branch on
recovery.action == "login"seeretry(same account) or no recovery for a login replaced mid-run, and no recovery for a refresh that could not be written back. After an accepted create,result.nextis now absent in one case: the login was replaced and another run may not be the same account, profile and API base.