Skip to content

fix(auth,files): a login asks for asset:file:download, and a download without file links fails - #93

Open
AltaMills wants to merge 9 commits into
refactorfrom
fix/oauth-download-scope
Open

AltaMills wants to merge 9 commits into
refactorfrom
fix/oauth-download-scope

Conversation

@AltaMills

@AltaMills AltaMills commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A device-code login asked for the identity scopes and the scopes the spec's operations declare. No operation declares asset:file:download: it only changes what a response holds. So a login never got it, the API left the links to a task's files out of every task it returned to that login, and -o, download and make saved the preview alone and exited 0.

Where the login scope comes from. It now has a source that can be checked:

 spec/openapi.v2.json   components.securitySchemes.ApiKeyAuth
+                         x-meshy-scopes: [account:balance:read, account:usage:read, asset:file:download,
+                                          task:task:create, task:task:delete, task:task:read]
 overlay/cli.yaml
+  response_scopes:            # asked for at login although no operation declares them
+    - name: asset:file:download
+      why: a task's file links come back only to a credential that holds it
 catalog-gen                   fails unless each response scope is on the spec's list and is not an
                               operation's, and every operation scope is on the list
 internal/catalog/catalog.json
+  "response_scopes": ["asset:file:download"]
 meshy auth login  scope = openid profile email + catalog.scopes + catalog.response_scopes

The spec's list comes from the same contract as the operations' x-meshy-scopes. The committed spec changes only by that list; its version and sources are the same. A login asks for no scope just because the spec lists it.

A download whose file links were left out fails. The check runs before anything is fetched, on every path that saves a task's files: download, -o on tasks get / wait / stream and on create --wait, and make.

plan(task):
  output has file fields (model_urls, *_url, *_urls besides previews) but links nothing besides previews
      -> refuse, unless --asset or a file path picked a file that came (the preview):
         exit 1, code server, "nothing was downloaded";
         hint: the causes; once the credential this command used can download them, the
         command that saves this task's files again, with the same --profile or
         --api-key-file (meshy tasks get <id> -o …, or the same download; never the create)
         the credential that answered the task read (Executor.AnsweredBy) is an OAuth login
         held to permissions without asset:file:download (msy_restricted + scope claims)
             -> code auth (exit 3), recovery login; hint: sign in again with
                meshy auth login --profile <that login's profile> --region <the region of
                the site that answered, on a production site>, keeping the permission
                (and MESHY_BASE_URL_V2 as it is, when the variable chose the site), then
                the same save command; recovery.command only when it runs as it is
  • Previews alone mean the links were left out: every v2 task type with file fields has a field besides its previews.
  • A task without file fields, such as a check's verdict, saves its sidecar as before.
  • input.target_formats is not checked: a task keeps the formats of its request even when it does not produce them (a relief asked for its depth map alone).
  • On such a task, --asset or a file path that names a file which came (--asset thumbnail_url, -o preview.png) still saves it. A directory (with or without --all), or a selection that finds nothing (--asset model_urls.glb, -o car.glb), gets the error above. A path the download refuses (outside the workspace, a symbolic link in the way) stays a path error (exit 11). On other tasks, -o <file> and --asset refuse a file the task does not have as before (exit 2).
  • Creative Lab tasks keep their fields outside output, so they are not checked.

Other callers of the code this changes:

  • internal/exec records the credential of each 2xx response, in Do and Open; nothing else changes there.
  • internal/auth gains LacksScope, which reads two more claims of the access token. Its other readers (refresh timing, issuer) are unchanged.

download, make and the -o flag help describe the new failure.

Evidence

  • Before (e22e67d) / After (cd49724). Both binaries were built and run with --format json against a local mock. Its task is shaped like the staging response to a login without asset:file:download: model_urls: {}, a preview link and null texture links. The run used a fake API key and a temporary config directory.

                                    before                                   after
    auth login asks for             openid profile email account:balance:    ... task:task:read asset:file:download
                                    read account:usage:read task:task:create
                                    task:task:delete task:task:read
    download <id> -o out/           exit 0, saved meta.json thumbnail.png    exit 1, code server, saved nothing:
                                                                             "the API sent no link to the files of
                                                                             task <id>, only to its previews
                                                                             (nothing was downloaded)"
    tasks get <id> -o out/          exit 0, saved meta.json thumbnail.png    exit 1, code server, saved nothing
    
  • New tests:

    • The login scope: the device-code request carries asset:file:download.
    • The generator: catalog-gen refuses a response scope missing from the spec's list, one an operation declares, one without a why, one listed twice, a spec without the list, an operation scope missing from the list, a malformed list, and a security requirement without a scheme.
    • Task shapes: linksWithheld over a model, rig, animation, image and motion task without links, previews alone, a verdict, whole tasks, and a depth-map relief that echoes target_formats.
    • Credentials: download (directory, --all, --asset, file path) and tasks get -o with an API key, a login held without the scope (exit 3, login recovery), a login held with it, and a login with full access.
    • A login replaced on disk while the task is read still gets exit 3: the error goes by the login that read the task.
    • make -o with a login without the scope sends one create and points at meshy tasks get <id> -o …, never at make.
    • The sign-in command names the login's profile, quoted when it must be, and takes its region from the site that answered, not from the profile on disk; also when it cannot be run as it is (a quoted name, a credentials file of one's own, MESHY_BASE_URL_V2 set).
    • Executor.AnsweredBy holds the token of a first attempt, the token a 401 swapped in, and a stream's token, and nothing after a 401 or a 404.
  • Mutation probes, 35 guards: each broken on purpose turned at least one test red.

  • Locally, darwin/arm64, go test -race ./... at ef2a9c9: 1018 passed, 0 failed, 18 skipped (the 0.8.8 interoperability and OS key store tests, which need MESHY_TEST_TS_CLI and MESHY_TEST_OS_KEYRING). go vet ./... (also with GOOS=windows) passes. CI passes on cd49724.

  • Staging, build cd49724, two device-code logins approved in the browser, each with its own config directory and a test key store, logged out afterwards:

    login                                   command                                         exit  saved
    base build, no asset:file:download      image-to-3d create --wait -o out/               3     nothing (code auth; hint: sign in again, then
                                                                                                  meshy tasks get <id> -o out/ …)
                                            tasks get <id> -o preview.png                   0     preview.png, 151983 bytes
                                            download <id> -o dir/                           3     nothing (code auth)
    this build, with asset:file:download    download <id> -o old-task/   (the same task)    0     model.glb, 32543244 bytes, starts with glTF
                                            image-to-3d create --wait -o out/               0     model.glb, 31876760 bytes, starts with glTF
    

    The creates pass --should-texture=false (an untextured model, the quickest GLB).

Merge Danger

Door: two-way
Revert restores the old scope and the old saving. A login made with this build keeps asset:file:download after a revert, which only adds the file links the API gives an API key.

Blast Radius: every download of a task's files, and every new OAuth login
A task the check misreads would fail where it saved before. The check fires only when no file other than a preview has a link, and a verdict or Creative Lab task is not checked.

… without file links fails

A device-code login asked for the identity scopes and the scopes the spec's
operations declare. No operation declares asset:file:download, which only
changes what a response holds, so a login could not get it. The API then
leaves the links to a task's files out of every task it returns to that
login, and -o, download and make saved the previews alone and exited 0.

The login scope:

- The spec's security scheme now lists every permission a credential can be
  limited to (x-meshy-scopes). It comes from the same contract as the
  operations' scopes; no other part of the spec changes.
- overlay/cli.yaml gains response_scopes: scopes a login asks for although
  no operation declares them, each with the reason. catalog-gen fails unless
  each one is on the spec's list and not already an operation's, and unless
  every operation scope is on the list. The catalog carries them as
  response_scopes.
- meshy auth login asks for openid profile email, the operations' scopes and
  the response scopes. It does not ask for every scope the spec lists.

The download:

- A SUCCEEDED task whose output has file fields (model_urls, a *_url) but
  links only previews is refused before anything is fetched, whatever is
  asked for (-o, download with or without --all or --asset, make): exit 1,
  code server, "nothing was downloaded", and a hint naming the causes the CLI
  cannot tell apart.
- When the run's credential is a stored OAuth login whose access token is
  held to permissions without asset:file:download (its msy_restricted and
  scope claims, read without a refresh), the error is code auth (exit 3)
  with a login recovery and the command that signs that profile in again.
- Without --all or --asset, a download also fails when a format in the
  task's input.target_formats has no link in model_urls (the spec says every
  format a task produced has one) and the download would save it: any such
  format into a directory, the path's own for a file path (-o car.glb).
  --all and --asset still save what the task has.
- download, make and -o help say so.
… never point back at a paid create

- The credential that explains a task without file links is the one the
  API answered: the executor records the credential of the latest 2xx
  response (Executor.AnsweredBy), and the error goes by it, not by what
  the credentials file holds by then. A login replaced on disk during the
  run, or one whose token was refreshed, no longer changes the verdict.
- The hint never says to run the command again: after make or create
  --wait -o the task is paid for. It says to sign in again (or which
  causes apply) and then save the same task's files with the command that
  reads it again (meshy tasks get <id> -o …, or the same download).
- input.target_formats is not checked any more: a task keeps the formats of
  its request even when it does not produce them (a relief asked for its
  depth map alone), so it is no list of what a task holds. A download
  fails only when every file came without a link; -o <file> and --asset
  still refuse a file the task does not have, as before.
- When no preview came either, the message no longer says "only previews".
… command they give

- The sign-in after a download refused for a login without the download
  permission is for the profile that answered, on the site that answered:
  its region comes from that site, not from the credentials file, which
  another login may hold by then. The hint always names the profile
  (meshy auth login --profile <name>, quoted for the shell when needed);
  recovery.command carries it when it runs as it is, with --region on the
  production file.
- The hint without that knowledge no longer offers another credential (a
  bare meshy auth login, an API key in the environment) beside a save
  command that keeps this run's --profile or --api-key-file. It names the
  causes, then: once the credential this command used can download them,
  save the task's files with that command.
…on the site that answered

When a login without the permission to download files read the task and
its sign-in cannot be given as a command to run as it is (a profile name
the shell needs quoted, a credentials file of one's own, MESHY_BASE_URL_V2
set), the command to copy now still names the region of the site that
answered on a production site, and says to leave MESHY_BASE_URL_V2 as it
is when the variable chose the site. A login without --region goes to the
active profile's site, so the hint could sign a China login in again on
the global site, and the save it gave next failed again.
…t can be pasted as it is

With MESHY_BASE_URL_V2 set, the note to keep it was written inside the
command to copy, which a shell then refused. The command is the command
alone again, and the hint asks to keep MESHY_BASE_URL_V2 as it is next to
the permission to download files. A test now states the causes the hint
gives in full.
…he other links were left out

The check for links left out ran before the files were picked, so it
refused even a preview that --asset or a file path named, and turned an
unknown --asset or a path in a format the task lacks from a usage error
into a server error. The files are now picked first. Of a task whose
other links were left out, a file an explicit selection found is saved;
a directory, which would hold the previews alone, and a selection that
found nothing, which most likely asked for a file left out, still fail
with the error that explains it.
…k's links were left out

Every error from picking the files and their paths was turned into the
error for links left out, so an output path outside the workspace or a
symbolic link in the way was reported as a missing link (exit 1), or as a
login without the permission (exit 3), instead of the path error it was
(exit 11). Only a selection that found nothing, a usage error, is turned
into it now. The -o and make help say that a path naming the preview still
saves it.
@AltaMills
AltaMills marked this pull request as ready for review December 4, 2026 17:16

@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/cmd/files.go
Comment on lines +96 to +98
e.Recovery = &output.Recovery{Action: "login"}
signIn, keep := "Sign in again", "the permission to download files"
if c.Source == string(auth.SourceFile) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Download recovery keeps the restricted host token

For a restricted host login, withheldFrom tells users to sign in again and repeat the download. Credential resolution still picks the host token over the new profile, so signing in does not restore downloads.

Learn more

The host app passes an OAuth token to the CLI in DSH_MESHY_CREDENTIAL. Credential resolution uses that token before considering a stored profile. Device login writes a profile; it does not update the host's environment. A restricted host token that can read tasks but cannot download files therefore survives the recovery instructions unchanged.

Example: A host shell downloads a completed task with a token that lacks asset:file:download. The user runs meshy auth login and grants downloads, but the retry in the same shell still uses the old host token and returns exit 3.

Recommended fix: Distinguish auth.SourceHost from auth.SourceFile. Tell host users to reauthorize through the host and retry once it supplies an updated token. Do not present a local profile login as recovery unless the instructions also explain how to select that profile without the host override.

Devin Review


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

Comment on lines +241 to +245
if linksWithheld(r.Task, assets) {
var e *output.Error
missed := errors.As(err, &e) && e.Code == output.CodeUsage
if missed || err == nil && (len(r.Keys) == 0 && !p.single || len(p.jobs) == 0) {
return nil, nil, withheldError(taskID, len(assets) > 0, r.Rerun)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Missing links hide occupied download paths

For a preview-only task, plan reports missing links before checking whether another task owns the destination sidecar. The suggested retry still fails after the user restores download permission, because the destination remains occupied.

Learn more

Directory downloads write meta.json to record the files saved for a task. The sidecar ownership check refuses an existing sidecar for a different task and tells the user to choose another path. The new missing-link check returns before that check, even though the directory and sidecar path are already known. Its recovery instead points users back to the occupied destination.

Example: A user downloads task A into out/, then runs meshy download B -o out/ with a login that can read B but not download its model. The command tells the user to sign in again. When the user gains permission and retries, the command refuses to overwrite A's meta.json.

Recommended fix: When layout succeeds, run the existing destination and sidecar collision checks before returning the missing-link error. Keep both checks before file transfers and add a regression case with an existing sidecar for a different task.

Devin Review


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

This branch has not been deployed

No deployments
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