Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,15 @@ listing and everything on it, and a rejection can too.** `civitai app withdraw`
on a **first-version** submission is therefore destructive, which is why it
asks first and needs `--yes` in a script.

🔁 **To update a version that is still waiting for review, submit again — do not
withdraw it.** A new `civitai app submit` replaces your own version in review:
the old one is marked replaced, its store listing and media are kept, and
moderators see only the new one. The submit says which version it replaces (and,
on a terminal without `--yes`, asks first). A submit whose manifest declares the
**same** version as the one in review is refused with the exact bump to make
(`set "version" to 0.1.1 in block.manifest.json`). A version someone else
submitted is never replaced.

📖 **The two kinds of credential, what `civitai whoami` reports (including the
tri-state capability rows) and `whoami --json`:
[CLI credentials and scopes](https://developer.civitai.com/site/guide/cli-auth).**
Expand Down Expand Up @@ -2041,6 +2050,7 @@ esac
- **When validation produces a result**, `civitai app validate --json` prints it in full and its `ok` field is the structured form of the same answer; a failure that produces no result at all — a project directory the CLI cannot **stat**, say, because it is unreadable or because a path component below it is not a directory — still exits `1` with **nothing on stdout**, so branch on the exit code before parsing. The full exit→stdout table is in [The `--json` result shape](https://developer.civitai.com/apps/guide/validate#the-json-result-shape).
- A resource that **exists but is not ready** lands here too, and deliberately not on `4`: `civitai app metrics <slug>` for an app whose submitted version is still in review exits `1`, because the slug is right and the app does exist — only its analytics do not exist yet, and the error names `civitai app status <slug>` as the next command. `4` stays reserved for a slug with no submissions at all, so the two remain separately actionable: fix the slug, versus wait for approval.
- A **version regression** lands here for the same reason: `civitai app submit` refuses when the manifest version is not strictly **above the highest approved version** of that app, because approving an older (or identical) version replaces the newer live deployment. Nothing about the invocation is wrong, so it is a verdict about the project, not a `2`. `--allow-downgrade` is the deliberate-rollback escape hatch, and the guard is skipped entirely by `--package-only` or a run with no token — neither reaches the server.
- A **resubmit of the version already in review** lands here too: when your own version of the app is waiting for review, `civitai app submit` refuses a manifest declaring that same version and names the next patch to set, because the new submit replaces the one in review and two submissions of one version cannot be told apart. Like the version guard it reads `GET /api/v1/blocks/submissions` and is skipped by `--package-only` or a run with no token; a read that fails warns and the submit goes ahead.
- A **dirty git work tree** lands here too: `civitai app submit` refuses while files that go into the bundle are uncommitted, because the bundle is packaged from what is on disk and approving one deploys code that exists in no commit. `--allow-dirty` submits the tree as it is. It **degrades rather than enforcing** — a directory that is not in a git repo, or a machine with no `git` on `PATH`, submits exactly as before (scaffolded apps have no repo, and that path must keep working), and a clean tree whose `HEAD` is on no remote **warns** instead of refusing. Like the version guard it is skipped by `--package-only` and by a run with no token.
- **A bundle the server cannot receive** lands here for the same reason, since [#585](https://github.com/civitai/cli/issues/585): `civitai app submit` refuses BEFORE uploading when the base64 JSON body would exceed what the platform accepts, so the transfer costs nothing. Nothing about the invocation is wrong — the project is too big — which is why it is `1` and not `2`, matching the version and dirty-tree refusals above. It previously reached `2` by way of the server answering `400: Invalid JSON`. `--allow-oversize` is the escape hatch, because the ceiling is a vendored number the CLI cannot re-measure; see AGENTS.md item 31.
- **An incomplete store listing** lands here too, since [#762](https://github.com/civitai/cli/pull/762): `civitai app submit` refuses while the app's listing is missing something you can fix **now** — a missing icon or cover, and, on an **off-site** listing whose copy you own, an empty tagline or description — and names the command that fixes each. Nothing about the invocation is wrong, which is why it is `1` and not `2`, matching the version, dirty-tree and oversize refusals above. `--allow-incomplete-listing` is the escape hatch; **`--yes` is not**, and the refusal says so, because `--yes` is the flag a script already passes. It is deliberately narrower than `civitai app doctor`: no screenshots, an empty category, a still-scanning asset and even a **blocked** asset are reported and not refused, because each of those remedies can end at a moderator's queue rather than at a command you can run. An **on-site** app's tagline and description come from `block.manifest.json` and are re-read only when a version is approved, so a tagline already in your manifest is reported as fixed rather than refused — refusing it would refuse the one submit that fixes it. Your **first** submit is what creates the listing, so nothing is refused there; the gate applies from the second on. Like the other four guards (version, dirty tree, oversize, outdated SDK) it is skipped by `--package-only` and by a run with no token. When the listing cannot be read the gate warns and the submit goes ahead (exit `0`). A scope refusal is the common case in CI: the read needs the Apps submit scope, which a `civitai login` token carries and a personal API key passes only with Full Access, so a scoped personal key skips the check on every run — the warning says so and, when unattended (a GitHub Actions OIDC submit, a CI environment, or no TTY), names `civitai app doctor <slug>` from a `civitai login` session as the check to run instead.
Expand Down
10 changes: 10 additions & 0 deletions internal/appapi/appblocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,16 @@ type SubmitResult struct {
// server that predates it), null, or malformed decodes to nil rather than
// failing the submit — see SubmitAdvisories.UnmarshalJSON.
Advisories SubmitAdvisories `json:"advisories,omitempty"`
// Replaced is the caller's own version that was waiting for review and this
// submit replaced (civitai/civitai#11502). nil when nothing was replaced or
// the server predates the field.
Replaced *SubmitReplaced `json:"replaced,omitempty"`
}

// SubmitReplaced is SubmitResult.Replaced.
type SubmitReplaced struct {
PublishRequestID string `json:"publishRequestId"`
Version string `json:"version"`
}

// SubmitAdvisory is one entry of SubmitResult.Advisories.
Expand Down
30 changes: 29 additions & 1 deletion internal/cmd/app_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ Version guard:
deployment on approval, which is what a repo that is behind what was last
released produces naturally. Pass --allow-downgrade for a deliberate rollback.

Version-in-review guard:
When your own version of the app is still waiting for review, a submit that
would really upload REPLACES it (the store listing and media are kept). The
submit names the version it replaces and, on a terminal without --yes, asks
first; a manifest declaring the SAME version as the one in review is refused
with the exact version to set.

Dirty-tree guard:
When the packaged directory is inside a git work tree, a submit that would
really upload REFUSES while files that go into the bundle are uncommitted —
Expand Down Expand Up @@ -683,7 +690,20 @@ Defaults to the current directory.`,
if ctx == nil {
ctx = context.Background()
}
if err := checkVersionNotRegression(ctx, client.ListSubmissions, cmd.ErrOrStderr(), m.BlockID, m.Version, allowDowngrade); err != nil {
// One read of the caller's submissions serves both guards below.
listSubmissions := onceLister(client.ListSubmissions)
if err := checkVersionNotRegression(ctx, listSubmissions, cmd.ErrOrStderr(), m.BlockID, m.Version, allowDowngrade); err != nil {
return err
}

// 2b'. VERSION-IN-REVIEW GUARD, after the version guard and on the
// same network read's terms (after confirmSubmit). The server
// replaces the author's own version in review with this submit;
// a same version is refused here with the bump to make, and a
// different one is announced (and confirmed on a TTY without
// --yes). See app_submit_pending_guard.go.
if err := checkPendingReplace(ctx, listSubmissions, cmd.InOrStdin(), cmd.OutOrStdout(), cmd.ErrOrStderr(),
m.BlockID, m.Version, assumeYes); err != nil {
return err
}

Expand Down Expand Up @@ -947,6 +967,11 @@ func afterPlatformUpdateMerge(ctx context.Context, cmd *cobra.Command, client *a
if err := checkVersionNotRegression(ctx, client.ListSubmissions, errw, m2.BlockID, m2.Version, allowDowngrade); err != nil {
return nil, prov, err
}
// The new version was announced or confirmed above; only a merge that
// moved it onto the version in review is refused here.
if err := checkPendingReplace(ctx, client.ListSubmissions, nil, io.Discard, errw, m2.BlockID, m2.Version, true); err != nil {
return nil, prov, err
}
}
outdated, err := checkSDKFloor(ctx, client.GetSDKFloor, errw, dir, m2.BuildCommand, allowOutdatedSDK)
if err != nil {
Expand Down Expand Up @@ -1121,6 +1146,9 @@ func doUploadWith(cmd *cobra.Command, client appapi.Submitter, zipBytes []byte,
}
base := strings.TrimRight(baseURL, "/")
fmt.Fprintln(out, ui.Success(fmt.Sprintf("Submitted — %s is pending moderator review.", r.PublishRequestID)))
if r.Replaced != nil {
fmt.Fprintf(out, "It replaces %s (%s), which was waiting for review; its store listing and media are kept.\n", r.Replaced.PublishRequestID, r.Replaced.Version)
}
printActionsRunSourceRecorded(out, r.ActionsRunSourceRecorded)
printSubmitListingReadiness(out, r.Listing)
printStorageMigrationWarnings(out, r.StorageMigrationWarnings)
Expand Down
146 changes: 146 additions & 0 deletions internal/cmd/app_submit_pending_guard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package cmd

import (
"context"
"errors"
"fmt"
"io"
"regexp"
"strconv"
"strings"

"github.com/civitai/cli/internal/appapi"
)

// THE VERSION-IN-REVIEW GUARD.
//
// The server replaces the author's OWN version still waiting for review with a
// new submit (civitai/civitai#11502): the old one is marked replaced, its draft
// store listing and media are kept, and moderators see only the new one. Before
// that, a second submit was refused ("withdraw it first"), and withdrawing a
// first version deleted its draft listing.
//
// This guard is what the CLI adds on top, and it is client-side only:
//
// - a new submit carrying the SAME version as the one in review is refused,
// naming the exact bump to make. Two submissions of one version cannot be
// told apart in history or in the approval tag.
// - otherwise the author is told the submit replaces the version in review
// (by its publish-request id) and, on a TTY without --yes, asked to confirm.
//
// The read is GET /api/v1/blocks/submissions, which is scoped to the caller's
// own submissions, so a pending row there is the caller's own: exactly the one
// the server replaces. Another user's pending version never appears, and the
// server still refuses a submit over it.
//
// Like the version guard, a failed read WARNS and proceeds: this is an accident
// preventer, the server enforces the replace rule itself.

// ErrSameVersionInReview classifies the refusal of a submit whose version equals
// the version already waiting for review (errors.Is). Like ErrVersionRegression
// it is not tagged ErrBadRequest, so it exits 1: the project, not the
// invocation, is what is wrong.
var ErrSameVersionInReview = errors.New("submitted version is the version already waiting for review")

var semverCore = regexp.MustCompile(`^(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$`)

// nextPatchVersion returns MAJOR.MINOR.(PATCH+1), dropping any pre-release or
// build suffix; "" when version is not semver. The same rule App Assistant
// applies when it bumps a manifest (civitai packages/civitai-app-assistant).
func nextPatchVersion(version string) string {
m := semverCore.FindStringSubmatch(strings.TrimSpace(version))
if m == nil {
return ""
}
patch, err := strconv.Atoi(m[3])
if err != nil {
return ""
}
return fmt.Sprintf("%s.%s.%d", m[1], m[2], patch+1)
}

// pendingInReview returns the caller's own submission of slug that waits for
// review, or nil. The server allows one pending submission per app.
func pendingInReview(subs []appapi.Submission, slug string) *appapi.Submission {
for i := range subs {
if appapi.SameSlug(subs[i].BlockID, slug) && strings.EqualFold(strings.TrimSpace(subs[i].Status), "pending") {
return &subs[i]
}
}
return nil
}

// sameVersionInReviewError is the refusal for a submit carrying the version in
// review, naming the exact bump.
func sameVersionInReviewError(slug string, pending *appapi.Submission) error {
next := nextPatchVersion(pending.Version)
bump := "set a higher \"version\" in block.manifest.json"
if next != "" {
bump = fmt.Sprintf("set \"version\" to %s in block.manifest.json", next)
}
return fmt.Errorf("%w: %s@%s is already waiting for review (%s); %s, then submit again — the new submit replaces the version in review",
ErrSameVersionInReview, slug, pending.Version, pending.ID, bump)
}

// replacesLine is what the author is told before a submit that replaces their
// version in review.
func replacesLine(slug, version string, pending *appapi.Submission) string {
return fmt.Sprintf("This submit replaces %s@%s, the version waiting for review (%s), with %s. Its store listing and media are kept.",
slug, pending.Version, pending.ID, version)
}

// checkPendingReplace runs the guard described above. in is read only when
// asking (a TTY without --yes); out takes the prompt, warn the notes.
func checkPendingReplace(ctx context.Context, lister submissionLister, in io.Reader, out, warn io.Writer,
slug, version string, assumeYes bool) error {
if strings.TrimSpace(slug) == "" {
return nil
}
subs, err := lister(ctx, slug)
if err != nil {
warnf(warn, "could not check whether a version of %s is waiting for review (%v) — submitting anyway; a new submit replaces your version in review.", slug, err)
return nil
}
pending := pendingInReview(subs, slug)
if pending == nil {
return nil
}
if strings.TrimSpace(version) == strings.TrimSpace(pending.Version) {
return sameVersionInReviewError(slug, pending)
}
if assumeYes || !stdinIsTTY() {
// --yes (or an unattended run that already passed the submit
// confirmation): say it, do not ask.
warnf(warn, "%s", replacesLine(slug, version, pending))
return nil
}
fmt.Fprintln(out, replacesLine(slug, version, pending))
fmt.Fprint(out, "Replace the version in review? [y/N]: ")
// readPromptLine, not a bufio.Reader: confirmSubmit may have read from the same stdin, and
// a buffered read here could swallow input meant for a later prompt.
switch strings.ToLower(strings.TrimSpace(readPromptLine(in))) {
case "y", "yes":
return nil
default:
return fmt.Errorf("submission cancelled; %s@%s is still waiting for review", slug, pending.Version)
}
}

// onceLister wraps lister so every call after the first returns the first
// call's answer for the same blockID: the version guard and this guard read
// the same rows, and one submit makes one read.
func onceLister(lister submissionLister) submissionLister {
type answer struct {
subs []appapi.Submission
err error
}
seen := map[string]answer{}
return func(ctx context.Context, blockID string) ([]appapi.Submission, error) {
if a, ok := seen[blockID]; ok {
return a.subs, a.err
}
subs, err := lister(ctx, blockID)
seen[blockID] = answer{subs, err}
return subs, err
}
}
Loading
Loading