From 42555e2f1d883f78e3a72ca1062e12a22335ecde Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Thu, 3 Dec 2026 23:07:11 -0600 Subject: [PATCH 1/2] feat(generate): --allow-not-ready submits past a ready:false estimate Every gpt-image-2.5 edit estimate (--ecosystem OpenAI with --image) reports ready: false, so the CLI refused the whole job class, while civitai.com's own generator runs the same job. The site does not gate on the flag: ResourceAlerts.tsx shows a "Potentially slow generation" notice for ready:false with no download preparation and leaves Generate enabled. The refusal is this CLI's own (item 28(a)); nothing on the server's submit path reads `ready`. Measured 2026-12-04 against civitai.com, dry runs only: versions 3311436, 3311434 and 2880272, quality high and medium, aspect 4:5 and 1:1, all ready:false with preparation null; the same graph without images is ready:true. Sending the site's own shape (workflow img2img:edit, acceptBoostRequired) from a throwaway build also returned ready:false, so the request shape is not the difference. --allow-not-ready is opt-in; the refusal stays the default. With the flag the submit path and the --dry-run quote print one warning that promises no output. Help text, its golden, and the README say so. Tests: generate_allow_not_ready_test.go. Mutants killed: gate reverted to `!quote.Ready` (AllowNotReadySubmits), dry-run branch disabled (AllowNotReadyStatesItWouldSubmit), submit-path warning dropped (AllowNotReadySubmits). go test ./internal/cmd ok; golangci-lint 2.12.2 on ./internal/cmd 0 issues. Co-Authored-By: Claude Opus 5.5 (1M context) --- README.md | 9 ++ internal/cmd/generate.go | 50 +++++++++-- internal/cmd/generate_allow_not_ready_test.go | 90 +++++++++++++++++++ .../testdata/golden/generate_help_long.txt | 2 +- 4 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 internal/cmd/generate_allow_not_ready_test.go diff --git a/README.md b/README.md index bf9e42eb..a34fbd9c 100644 --- a/README.md +++ b/README.md @@ -1799,6 +1799,15 @@ generator. > what actually ran. Warned by default; `--fail-on-substitution` refuses on the > estimate, before any spend. +**When the estimate says `Resources ready: false`.** The CLI refuses to submit +by default. `--allow-not-ready` submits anyway, which is what the site's own +generator does (it shows a *Potentially slow generation* notice and lets you +generate). Image edits on the OpenAI ecosystem (`--ecosystem OpenAI --image …`) +were measured reporting `ready: false` on every estimate while the same job ran +from the site, so they need the flag. A `ready: false` job may start late or +never produce an output, and like any submit it is charged when the server +accepts it. + **Which Buzz pays.** `--buzz-type blue|yellow|green` picks the account, the same choice as the **Pay with** menu in the site's generator. Without it the server decides: blue first, then the site's own Buzz. On civitai.red the site diff --git a/internal/cmd/generate.go b/internal/cmd/generate.go index e36da88b..8ebec95b 100644 --- a/internal/cmd/generate.go +++ b/internal/cmd/generate.go @@ -251,6 +251,9 @@ type generateOpts struct { // server preserves a substitution deliberately so that a script pinned to a // retired version keeps working. See the flag registration for the argument. failOnSubstitution bool + // allowNotReady submits even when the estimate reports ready:false. Opt-in: + // the DEFAULT stays the refusal. See the flag registration for the argument. + allowNotReady bool // noWait prints the workflow id and exits instead of waiting. noWait bool @@ -396,7 +399,11 @@ server's ` + "`ready`" + ` flag, which reports only that the resources this job currently available — nothing about moderation, and nothing about whether the job will actually produce an image. A run that reports resources ready can still be charged and return nothing. Treat ` + "`ready: false`" + ` as "do not submit"; do not -read ` + "`ready: true`" + ` as a green light. +read ` + "`ready: true`" + ` as a green light. This CLI refuses a ` + "`ready: false`" + ` job unless +you pass --allow-not-ready. The site's own generator does not refuse it: it +shows a "Potentially slow generation" notice and lets you generate. Image edits +on the OpenAI ecosystem (--image) were measured reporting ` + "`ready: false`" + ` on +every estimate while the same job ran from the site. WAITING AND DOWNLOADING: by default the command waits for the job to finish and writes every deliverable output into --out-dir as -.. @@ -698,6 +705,23 @@ path that resolves model ids before anything is submitted.`, // command in this bool flag's usage rendered it in --help as a flag that // takes a value called "civitai workflows get " (measured, then fixed). // Use single quotes. Pinned by TestGenerateFlagUsageHasNoBackquotes. + // 🔴 OPT-IN, AND THE REFUSAL STAYS THE DEFAULT. `ready: false` is the + // server's capacity signal (some step's queuePosition.support is not + // 'available'), and the refusal it triggers is THIS CLI's own: nothing on + // the server's submit path reads it (AGENTS.md item 28(a)). The site's own + // generator does not gate on it either — civitai/civitai + // src/components/generation_v2/ResourceAlerts.tsx renders a "Potentially + // slow generation" notice for ready:false with no download preparation and + // leaves Generate enabled. Measured 2026-12-04: every gpt-image-2.5 edit + // (OpenAI + --image) estimate reports ready:false while the same job from the + // site's generator runs, so without this flag that whole job class is + // unreachable from the CLI. The usage string must not promise output — a + // ready:false job may also be one the server cannot run, and it is charged + // either way. + cmd.Flags().BoolVar(&o.allowNotReady, "allow-not-ready", false, + "submit even when the estimate reports ready: false (the default refuses). The site's own generator does the same: "+ + "it shows a 'Potentially slow generation' notice and lets you generate. ready: false means the server cannot "+ + "start the job right away, and it can also mean the job will never run; like any submit, it is charged when the server accepts it") cmd.Flags().BoolVar(&o.noWait, "no-wait", false, "submit, print the workflow id and exit without waiting; collect the results later with 'civitai workflows get '") // 🔴 The wording here is load-bearing. --timeout bounds the CLI's WAIT. The @@ -1346,12 +1370,17 @@ func runGenerate(cmd *cobra.Command, deps generateDeps, o generateOpts) error { return err } - if !quote.Ready { + if !quote.Ready && !o.allowNotReady { // `ready:false` means some job in the workflow has no available support — // the resources are not currently available. Submitting anyway spends on - // a job the server has already said it cannot serve. + // a job the server has already said it cannot serve right now. return civitai.Tag(civitai.ErrBadRequest, fmt.Errorf( - "the server reports the resources for this job are not currently available (ready: false) — they may be unavailable or unsupported by this workflow; inspect the estimate with --dry-run --json")) + "the server reports the resources for this job are not currently available (ready: false) — they may be unavailable or unsupported by this workflow; inspect the estimate with --dry-run --json, or pass --allow-not-ready to submit anyway")) + } + if !quote.Ready { + // --allow-not-ready: proceed, but say so BEFORE the confirmation, where a + // human can still decline. + fmt.Fprintln(errw, ui.For(errw).Warn(allowNotReadyWarning)) } cost := quote.Cost.Total @@ -2021,6 +2050,11 @@ func confirmGenerate(cmd *cobra.Command, o generateOpts, built *resolvedGraph, c // reports what the estimate did rather than what the user typed. const promptNotChecked = "" +// allowNotReadyWarning is the ONE line both the --dry-run quote and the submit +// path print for a ready:false estimate under --allow-not-ready. It states what +// the server said and what this CLI will do, and promises no output (item 28). +const allowNotReadyWarning = "The server reports the resources for this job are NOT currently available (ready: false). --allow-not-ready is set, so this CLI submits it anyway: it may start late or never produce an output, and like any submit it is charged when the server accepts it." + // printGenerateQuote renders the --dry-run breakdown. Factor and fixed keys are // printed VERBATIM — they are server-owned, and inventing friendlier labels is // how a vendored mapping starts. @@ -2162,8 +2196,12 @@ func printGenerateQuote(out, errw io.Writer, built *resolvedGraph, o generateOpt // #279's failing checkpoints came back as HTTP 400s rather than as // ready:false. Caveating `true` as unobservable while promoting `false` // on the same unread evidence is the same mistake twice. - fmt.Fprintln(errw, ui.For(errw).Warn( - "The server reports the resources for this job are NOT currently available (ready: false) — this CLI refuses to submit in that state.")) + if o.allowNotReady { + fmt.Fprintln(errw, ui.For(errw).Warn(allowNotReadyWarning)) + } else { + fmt.Fprintln(errw, ui.For(errw).Warn( + "The server reports the resources for this job are NOT currently available (ready: false) — this CLI refuses to submit in that state.")) + } } // The caveat belongs on stderr next to the number, every time. A user who // reads only the total will otherwise treat it as a quote. diff --git a/internal/cmd/generate_allow_not_ready_test.go b/internal/cmd/generate_allow_not_ready_test.go new file mode 100644 index 00000000..870cb83f --- /dev/null +++ b/internal/cmd/generate_allow_not_ready_test.go @@ -0,0 +1,90 @@ +package cmd + +import ( + "strings" + "testing" +) + +// --allow-not-ready: a ready:false estimate is SUBMITTED (once) instead of +// refused, and the user is told so on stderr before the submit. The default +// refusal is TestGenerate_NotReadyRefuses; this is the opt-in direction. +// +// Why the flag exists: every gpt-image-2.5 edit estimate (OpenAI + --image) +// was measured reporting ready:false while the same job runs from the site's +// generator, which never gates on the flag (ResourceAlerts.tsx shows a +// "Potentially slow generation" notice and leaves Generate enabled). +func TestGenerate_AllowNotReadySubmits(t *testing.T) { + var s genSeams + s.whatIf = notReadyQuoteSeam() + o := baseOpts() + o.assumeYes = true + o.allowNotReady = true + c, _, errb := genCmd("") + if err := runGenerate(c, s.deps(t), o); err != nil { + t.Fatalf("ready:false with --allow-not-ready: want a submit, got %v", err) + } + if s.submitCalls != 1 { + t.Errorf("ready:false with --allow-not-ready: submit called %d times, want 1", s.submitCalls) + } + if !strings.Contains(errb.String(), allowNotReadyWarning) { + t.Errorf("the submit must say it is proceeding past ready:false:\n%s", errb.String()) + } +} + +// The flag changes nothing for a ready:true estimate: no warning, one submit. +// Guards the warning against firing on every run once the flag is in a script. +func TestGenerate_AllowNotReadySilentWhenReady(t *testing.T) { + var s genSeams + o := baseOpts() + o.assumeYes = true + o.allowNotReady = true + c, _, errb := genCmd("") + if err := runGenerate(c, s.deps(t), o); err != nil { + t.Fatalf("ready:true with --allow-not-ready: %v", err) + } + if s.submitCalls != 1 { + t.Errorf("submit called %d times, want 1", s.submitCalls) + } + if strings.Contains(errb.String(), "ready: false") { + t.Errorf("a ready:true estimate must not print the not-ready warning:\n%s", errb.String()) + } +} + +// --dry-run must not say "this CLI refuses to submit" when the flag means a +// real run would submit. It still reports the server's false and spends nothing. +func TestDryRun_AllowNotReadyStatesItWouldSubmit(t *testing.T) { + withStdinTTY(t, false) + var s genSeams + s.whatIf = notReadyQuoteSeam() + o := baseOpts() + o.dryRun = true + o.allowNotReady = true + c, out, errb := genCmd("") + if err := runGenerate(c, s.deps(t), o); err != nil { + t.Fatalf("--dry-run --allow-not-ready: %v", err) + } + if s.submitCalls != 0 { + t.Errorf("--dry-run submitted %d times, want 0", s.submitCalls) + } + if !strings.Contains(collapseWS(out.String()), "Resources ready: false") { + t.Errorf("the readiness line must still report the server's false:\n%s", out.String()) + } + if !strings.Contains(errb.String(), allowNotReadyWarning) { + t.Errorf("--dry-run with the flag must print the proceed warning:\n%s", errb.String()) + } + if strings.Contains(errb.String(), "refuses to submit in that state") { + t.Errorf("--dry-run with the flag must not claim a refusal a real run would not make:\n%s", errb.String()) + } +} + +// The flag is registered on the real command, off by default, so the refusal +// stays the default for every existing caller. +func TestGenerate_AllowNotReadyFlagRegisteredOffByDefault(t *testing.T) { + f := newGenerateCmd().Flags().Lookup("allow-not-ready") + if f == nil { + t.Fatal("generate has no --allow-not-ready flag") + } + if f.DefValue != "false" { + t.Errorf("--allow-not-ready default = %q, want false (the refusal is the default)", f.DefValue) + } +} diff --git a/internal/cmd/testdata/golden/generate_help_long.txt b/internal/cmd/testdata/golden/generate_help_long.txt index 5e759b18..dbb19ada 100644 --- a/internal/cmd/testdata/golden/generate_help_long.txt +++ b/internal/cmd/testdata/golden/generate_help_long.txt @@ -1 +1 @@ -Generate images from a text prompt on Civitai's generator. 🔴 THIS SPENDS REAL BUZZ AND CANNOT BE UNDONE. A submitted generation is charged the moment the orchestrator accepts it, and nothing local calls that back — neither --timeout nor Ctrl-C stops the job, and `civitai workflows cancel` stops the remaining work rather than reversing the charge. Preview the price with --dry-run first; it calls the server's cost estimator and spends nothing. What the LEDGER then does with that charge — if the run fails, expires, or you cancel it — is decided server-side, and this CLI cannot see your Buzz ledger — `civitai buzz` reports a balance, not a history, so settle it against your Buzz transaction history (/user/transactions). CREDENTIAL: generation needs the AI Services scopes. Two credentials carry them: `civitai login --scopes generate` (a browser login that opts into generation), or a full-scope personal API key (`civitai login --token `, created at https://civitai.com/user/account). A DEFAULT OAuth browser login (`civitai login` with no --scopes) does NOT carry them and is refused — and re-running plain `civitai login` will not fix that. Check yours with `civitai whoami`. The ONE exception is --print-input: it assembles the graph and exits before the estimator, the submit and the balance read, so it needs no credential. Two caveats, and they are NOT the same caveat. With --image it does need one, because it uploads each local file first and that upload is authenticated. With --checkpoint or --lora it still needs none — the model-version lookup is a public read — but it is not OFFLINE: that lookup is a real request and fails without a network. Only a bare --print-input needs neither a credential nor a network. --max-cost IS AN ESTIMATE CHECK, NOT A SPENDING CAP. The cost this command shows is an estimate, not a quote: the server's estimator returns no quote id, no signed price and no expiry — there is nothing to hand back at submit time, and no server-side ceiling is reachable from an API key at all. The realized charge can exceed the estimate, and --max-cost cannot claw the difference back — it never reaches the server. --max-cost compares the ESTIMATE against your number and refuses locally before submitting; it catches a --quantity typo, and that is all it can do. Do not run an unattended loop believing it caps spend. CONFIRMATION: an interactive run prints the estimate and your balance and asks before spending. A non-interactive shell (pipe/CI) without --yes is REFUSED rather than charged silently. WHICH BUZZ PAYS: --buzz-type blue|yellow|green picks the account, the same choice as the "Pay with" menu in the site's generator, and is sent with the submit. Without it the server decides: blue first, then the site's own Buzz. The account matters beyond the balance — on civitai.red the site states that Blue Buzz is limited to safe-for-work results, so a mature result paid in blue can come back locked, and unlocking it on the site is a second charge. To pay for a mature result up front, point the CLI at that site (CIVITAI_BASE_URL=https://civitai.red) and choose yellow. On the default civitai.com the server offers blue and green only. With the flag, the balance check and the confirmation use that account's balance alone. Two limits: the estimate does not take the choice (--dry-run shows it, but prices the job without it), and a type the site does not offer is NOT refused by the server — it silently pays from its default account instead. That includes yellow on civitai.com, even though the site's menu there lists a yellow balance (as a pointer to civitai.red). WHAT THE SERVER DOES NOT TELL YOU: the generator is permissive, not a validator. An out-of-range --quantity is clamped with no error, and a checkpoint id that does not exist is accepted with the ecosystem default silently substituted and billed. This command therefore resolves every --checkpoint / --lora id against the public model-version API BEFORE submitting, so a bad id is a hard local error instead of a wrong charge, and it echoes the resolved model NAME in the confirmation so you approve a name rather than an integer. 🔴 NAMING A CHECKPOINT DOES NOT MOVE THE ECOSYSTEM WITH IT. --checkpoint selects a model version and nothing else. The settings the server generates with — engine, steps, cfg scale, sampler — follow the ECOSYSTEM (--ecosystem, or the server's default when you pass none), not the checkpoint you named, and there is no --steps or --cfg-scale here to correct them (see RAW GRAPHS below). A checkpoint paired with an ecosystem it does not belong to is refused by nothing — not by this CLI, not by the estimator, not by the generator. The job is accepted and charged, and it can finish having produced no usable output. The model-version lookup above proves the id EXISTS, not that it fits, and "Resources ready" does not answer it either. Which ecosystem a given checkpoint belongs to is server knowledge this CLI does not hold and will not guess: if you name a checkpoint, name the --ecosystem it belongs to as well. 🔴 --dry-run's "Resources ready" line is NOT A PROMISE OF OUTPUT. It echoes the server's `ready` flag, which reports only that the resources this job needs are currently available — nothing about moderation, and nothing about whether the job will actually produce an image. A run that reports resources ready can still be charged and return nothing. Treat `ready: false` as "do not submit"; do not read `ready: true` as a green light. WAITING AND DOWNLOADING: by default the command waits for the job to finish and writes every deliverable output into --out-dir as -.. --out-name