Skip to content

fix(auth): an auth error's hint and recovery follow the failure, the site and the profile - #92

Merged
AltaMills merged 13 commits into
refactorfrom
ark/auth-error-recovery
Dec 4, 2026
Merged

AltaMills merged 13 commits into
refactorfrom
ark/auth-error-recovery

Conversation

@AltaMills

@AltaMills AltaMills commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The shared auth errors every API command prints (and meshy doctor shows as they are) all said Run: meshy auth login with recovery: {action: "login"}. For several failures that is the wrong step: a bare meshy auth login writes the default profile and makes it active, and without MESHY_BASE_URL_V2 it signs in to production. Each error now says what fits the failure, the site and the profile:

Failure Hint recovery
The stored login was replaced by another terminal while the command ran, by a login of the same account (OAuth, same user id), and another run takes the same profile and API base Run the command again retry (was login)
…by another account, an API key, the profile was removed, another profile was made active, or the same account signed in on the other site Check which account another run would use (meshy auth status, with the run's --profile), then run again only if it is the one to use none (was login): another run could pay with another account
…after create --wait / make already created the task Same account, profile and site: Run: 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) same: wait + that command; otherwise none, and no result.next (its commands would read the task as another account and get a 404)
Login expired with no refresh token; key does not open; token endpoint refuses the refresh; a stored profile holds a placeholder key Sign in again as that login: --profile, --region; on another site, keep MESHY_BASE_URL_V2 pointing at it login + the exact command when one runs as is
No credential, or --profile names none, on a site other than production Keep MESHY_BASE_URL_V2 set, then sign in (with --profile when not default) unchanged
A refresh whose result cannot be written back Fix what kept the credentials file from being written (the directory, the key store), then sign in again as that login none (was login)
 internal/auth
-  loginGone            Hint: LoginHint, Recovery: login
+  loginGone            same account, profile and API base: run again, retry; otherwise check first, no recovery
-  expiredLogin(name)   LoginHint
+  r.expiredLogin(...)  relogin(site, profile, login)
+  r.OpenSecrets(...)   Store.Secrets, a key that does not open → relogin
+  r.asRelogin(...)     token endpoint refusal during a refresh → relogin
+  r.authRequired(...)  AuthRequired with the site in its hint; a placeholder key → relogin
   refresh: write-back failures lose their login recovery
 internal/cmd
   createAndWait        a retry recovery after the create → wait <task>; otherwise no runnable command, no result.next
-  doctor reloginDetail (the key check now gets the right hint from OpenSecrets)
   doctor --help        drops the paragraph that listed these cases
 docs/scripting.md, docs/decisions.md (D-034), docs/usage.md, skills/meshy-cli/SKILL.md
                        result.next is left out after a login replaced by one that may be another account

error.code and exit codes are unchanged. meshy doctor's fix still comes from recovery.command only.

Evidence

Built at the base (e22e67d) and at 7c93e8d (later commits change only tests and docs), run with a throwaway config dir:

  • Expired login of profile work on the China site, meshy balance get --profile work --format json
    Before: 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"}
  • No login, MESHY_BASE_URL_V2 set to another site
    Before: 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)
  • A key that does not open, on another site
    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: TestAuthErrorsSayHowToRecover checks the stderr hint and the envelope's recovery for each failure. TestALoginReplacedBeforeACreateIsSent checks, for the same and for another account, that nothing is sent or journaled. TestCreateWaitAfterALoginWasReplaced checks that nothing says to run the create again, and that only a confirmed outcome (a user id on both logins, the profile --profile names) carries a runnable command. TestALoginReplacedOnTheProductionFile covers a profile replaced by another account, another active profile, or the same account on the other site, and MESHY_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 recovery of every API command
Scripts that branch on recovery.action == "login" see retry (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.next is now absent in one case: the login was replaced and another run may not be the same account, profile and API base.

…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.
@AltaMills
AltaMills marked this pull request as ready for review December 4, 2026 17:16
@AltaMills
AltaMills merged commit c8c448b into refactor Dec 4, 2026
8 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Devin Review

Comment thread internal/auth/resolve.go
Comment on lines +538 to +539
func sameAccount(kind Kind, subject string, p *Profile) bool {
return p != nil && kind == KindOAuth && p.Kind == KindOAuth && subject != "" && p.UserID == subject

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread internal/auth/resolve.go
Comment on lines +612 to +615
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant