diff --git a/AGENTS.md b/AGENTS.md index 1abc775a5..e1bb4512f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -72,9 +72,11 @@ In v0.108.0: two accounts while headed passed (#1554). - **`video upscale` 720p / 270p GIF** drive the download menu headless (measured, 0 credits); 4K video follows that path headless by decision (Ultra only, unmeasured; #1554). +- **A credit-capped `video t2v` of an explicit measured key** reads Flow's quote in a headless + browser under `auto` (measured, #1554); other capped videos stay headed. - **The remaining UI surfaces stay headed** (`ui_automation`: `image batch`, `movie run`, r2v, edit, end-frame i2v, 1080p menu upscale, scene/character create, instructions, the agent composer, - other credit-capped video; on an account served flow.google.com, gflow cannot drive + credit-capped video other than a text-to-video of an explicit measured key; on an account served flow.google.com, gflow cannot drive instructions, scenes or characters yet in either mode, #639/#1587). Headless UI is tracked in #1554. - **`auth login`** is interactive and needs a display once; `auth renew` and the credits read were already browserless or headless. diff --git a/CHANGELOG.md b/CHANGELOG.md index df7975971..5ae2e0f1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **A credit-capped text-to-video of an explicit measured key runs headless by default** + ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). When `--max-credits` (or `GFLOW_CLI_MAX_CREDITS`, MCP `max_credits`) is the + only reason a text-to-video takes Flow's UI, because the uncapped request is an explicit measured + direct key (a bare text-to-video, whose key is the account's selection, stays headed), Flow's quote is read and enforced in a headless browser under `auto`, on the CLI and on + `gflow_generate_video` (queued). It reached the submit 2/2 headless matching a headed control + with the submit aborted, and a billed headless run completed at the quoted 4 credits on one + account (3/3); another account refused the same run as unusual activity both headless and + headed, unbilled, so that refusal reflects the account's state. A capped video of any other shape stays + headed. `video i2v --end-frame` stays headed (a billed headless run was refused while the + headed control completed), and `video edit` stays headed (exit 23 in both modes, #1605). - **The AI-attribution commit check covers more forms (#1526).** `scripts/ci/check_commit_trailers.py` now also refuses an `Assisted-by:` trailer, a `Co-Authored-By:` trailer with no e-mail address (GitHub credits nobody without one), and a commit whose committer is an AI identity. An indented diff --git a/README.md b/README.md index fcd978369..ff3f4c292 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Which commands open a browser, with the default `GFLOW_CLI_BROWSER_VISIBILITY=au | `image i2i --ref` | headless with one local file | One local reference file in an existing project, on a request that would go direct once the file is uploaded: a new file is uploaded and generated directly, a file already in the project is attached through Flow's UI, both from a headless browser ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). More files, another reference, a character or an unmeasured model keep it headed | | `video upscale --scale 720p` | headless on `flow.google.com` | Drives the download menu; 720p and the 270p GIF measured headless, 0 credits ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | | `video upscale --scale 4k` | headless on `flow.google.com` (not measured) | Ultra only; spends credits on the click; follows the measured menu path by decision ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | +| `video t2v --max-credits` | headless when only the cap needs the UI | A capped explicit measured key (for example `--model omni-1.2-flash --duration 4 --resolution 360p`) reads Flow's quote headless ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | **Headed** (Flow's UI) @@ -65,8 +66,8 @@ Which commands open a browser, with the default `GFLOW_CLI_BROWSER_VISIBILITY=au | `image upscale --scale 2k` | headed | Headless was refused as unusual activity on one of two accounts while headed passed ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)); 4K too | | `movie run` | headed | Scene requests carry no resolution, so no scene forms a measured key; characters and instruction cards are UI surfaces too | | `video r2v` | headed | Reference-to-video is not measured over direct HTTP | -| `video edit` | headed | Not measured over direct HTTP | -| `video i2v --end-frame` | headed | An end frame, or a start frame that is already in the project, is not a measured shape | +| `video edit` | headed | gflow cannot drive it yet in either mode on an account served flow.google.com ([#1605](https://github.com/ffroliva/gflow-cli/issues/1605)) | +| `video i2v --end-frame` | headed | Not a measured shape; a billed headless run was refused while headed completed ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | | `video upscale --scale 1080p` (menu) | headed | 1080p of a clip the local catalog does not hold as a measured direct source drives the download menu; not measured headless | | `scene create` | headed | Scenes are built in the UI | | `scene show` | headed | Reads the scene in the UI | @@ -75,7 +76,7 @@ Which commands open a browser, with the default `GFLOW_CLI_BROWSER_VISIBILITY=au | `instructions add` | headed | Agent-mode instruction cards are a UI surface (every `instructions` subcommand) | | `project create` | headed | Creates the project in the UI (also `project rename`) | | `data sync` | headed | Reads the project in the profile's browser | -| `video t2v --max-credits` | headed | Any credit-capped video (`--max-credits`, `GFLOW_CLI_MAX_CREDITS`, MCP `max_credits`) reads Flow's quote in the UI; direct video has no wire quote | +| `video t2v --max-credits` (other shapes) | headed | A credit-capped video of an unmeasured shape reads Flow's quote in the UI; direct video has no wire quote | **No browser** @@ -401,7 +402,7 @@ These keep the labs driver until they are ported: other UUID media references, a **Remaining limits.** - The one-time `auth login` is interactive and needs a display. -- Reference-to-video, `video edit`, image-to-video with an end frame, 1080p upscales of clips outside the measured direct shape, `scene create`, `character create`, `instructions`, the agent-only composer, and any other video run with a credit cap (`--max-credits`, MCP `max_credits`) still drive Flow's interface in a headed browser; `video extend` on flow.google.com drives it headless, `media trash`/`restore` run with no browser or in a headless one, image-to-image from one local `--ref` file in an existing project runs headless when the request would otherwise go direct, and the 720p, GIF and (unmeasured) 4K video upscales run headless. Headless operation of these surfaces is tracked in [#1554](https://github.com/ffroliva/gflow-cli/issues/1554). +- Reference-to-video, `video edit`, image-to-video with an end frame, 1080p upscales of clips outside the measured direct shape, `scene create`, `character create`, `instructions`, the agent-only composer, and any other video run with a credit cap (`--max-credits`, MCP `max_credits`) other than a text-to-video of an explicit measured key still drive Flow's interface in a headed browser; `video extend` on flow.google.com drives it headless, `media trash`/`restore` run with no browser or in a headless one, image-to-image from one local `--ref` file in an existing project runs headless when the request would otherwise go direct, and the 720p, GIF and (unmeasured) 4K video upscales run headless. Headless operation of these surfaces is tracked in [#1554](https://github.com/ffroliva/gflow-cli/issues/1554). - Request shapes that have not been measured fall back to the interface path. - The headless mint was measured on Windows only, on accounts served flow.google.com. macOS, Linux and accounts Flow serves on labs.google are unmeasured. - The headless browser reports itself as `HeadlessChrome`. It is not a stealth technique, and Google may treat it differently in future. diff --git a/README.zh-CN.md b/README.zh-CN.md index 7613af38e..9aceb9716 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -46,6 +46,7 @@ | `image i2i --ref` | 单个本地文件为 headless | 在已有项目中仅使用一个本地参考文件、且文件上传后的请求可直接发送时:新文件直接上传并生成,项目中已有的文件通过 Flow 的 UI 附加,两者均在无头浏览器中运行([#1554](https://github.com/ffroliva/gflow-cli/issues/1554))。多个文件、其他参考、角色或未测量的模型则保持有头 | | `video upscale --scale 720p` | 在 `flow.google.com` 上为 headless | 驱动下载菜单;720p 和 270p GIF 已测量可无头运行,0 积分([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | | `video upscale --scale 4k` | 在 `flow.google.com` 上为 headless(未测量) | 仅 Ultra;按决定沿用已测量的菜单路径([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | +| `video t2v --max-credits` | 仅因积分上限需要 UI 时为 headless | 显式指定的已测量形态(例如 `--model omni-1.2-flash --duration 4 --resolution 360p`)加上积分上限时,以无头方式读取 Flow 报价([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | **有头**(Flow 的界面) @@ -57,8 +58,8 @@ | `image upscale --scale 2k` | headed | 在两个账户之一上,无头运行被判为异常活动而有头运行通过([#1554](https://github.com/ffroliva/gflow-cli/issues/1554));4K 同样 | | `movie run` | headed | 场景请求不携带分辨率,因此没有场景能构成已测量的键;角色和指令卡也是 UI 界面 | | `video r2v` | headed | 参考图生视频尚未通过直接 HTTP 测量 | -| `video edit` | headed | 尚未通过直接 HTTP 测量 | -| `video i2v --end-frame` | headed | 结束帧,或已在项目中的起始帧,不是已测量的形态 | +| `video edit` | headed | 在 flow.google.com 账户上 gflow 暂时无法在任一模式下驱动([#1605](https://github.com/ffroliva/gflow-cli/issues/1605)) | +| `video i2v --end-frame` | headed | 不是已测量的形态;一次计费的无头运行被拒绝,而有头运行完成([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | | `video upscale --scale 1080p` (menu) | headed | 本地媒体库中没有的片段的 1080p 驱动下载菜单;未测量无头运行 | | `scene create` | headed | 场景在 UI 中构建 | | `scene show` | headed | 在 UI 中读取场景 | @@ -67,7 +68,7 @@ | `instructions add` | headed | Agent 模式指令卡是 UI 界面(所有 `instructions` 子命令) | | `project create` | headed | 在 UI 中创建项目(`project rename` 同样) | | `data sync` | headed | 在该配置文件的浏览器中读取项目 | -| `video t2v --max-credits` | headed | 任何设置了积分上限的视频(`--max-credits`、`GFLOW_CLI_MAX_CREDITS`、MCP `max_credits`)都在 UI 中读取 Flow 的报价;直接视频路径没有线上报价 | +| `video t2v --max-credits` (other shapes) | headed | 未测量形态的积分上限视频在 UI 中读取 Flow 的报价;直连视频没有线上报价 | **不使用浏览器** diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index d4ca80425..3455d8876 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -483,7 +483,7 @@ used only where it is strictly necessary. - **The UI transport (`ui_automation`) for the other surfaces.** `image batch`, `movie run`, reference-to-video, edit, end-frame image-to-video, the 1080p menu upscale, scene and character create, - instructions, the agent-only composer and other credit-capped video still drive Flow's page in a headed browser. Headless operation of these + instructions, the agent-only composer and credit-capped video other than a text-to-video of an explicit measured key still drive Flow's page in a headed browser. Headless operation of these surfaces is tracked in [#1554](https://github.com/ffroliva/gflow-cli/issues/1554). - **`auth login`** is interactive and needs a display once. - **Selecting the mode.** `GFLOW_CLI_BROWSER_VISIBILITY=auto|headless|headed` (default `auto`); diff --git a/docs/BROWSER_MODES.md b/docs/BROWSER_MODES.md index 980b4be7b..1bc4405eb 100644 --- a/docs/BROWSER_MODES.md +++ b/docs/BROWSER_MODES.md @@ -41,6 +41,7 @@ browser has been measured, so `auto` runs them headless. | `image i2i --ref` | headless with one local file | When the only reference is a local file, `--project` names an existing project, and, with each file in the shape an upload produces (one in-project reference), the request would go direct (for example `nano2`), the browser starts headless: a new file is uploaded and generated directly, and a file the catalog already holds in the project is attached through Flow's UI in that headless browser. Two quota runs of the UI attach matched a headed control ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). Two or more files, a UUID reference or a character beside the file, a new project, an unmeasured model, or another reason for the UI keeps it headed. `GFLOW_CLI_TRANSPORT=ui_automation` keeps it headed | | `video upscale --scale 720p` | headless on `flow.google.com` | Drives the video's download menu; 720p and the 270p GIF (`--scale 270p`) each ran twice in a headless browser matching a headed control, 0 credits, including on an account that was refusing headless image upscales at the time ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). `GFLOW_CLI_TRANSPORT=ui_automation` or an explicit `GFLOW_CLI_FLOW_HOST=labs.google` keeps it headed | | `video upscale --scale 4k` | headless on `flow.google.com` (not measured) | Ultra only, so not measured: it follows the measured video download-menu path by an explicit decision ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). It spends credits on the click, and a failure after the click is never retried. `--browser-visibility headed` shows the window | +| `video t2v --max-credits` | headless when only the cap needs the UI | A capped text-to-video whose uncapped request is an explicit measured key (for example `--model omni-1.2-flash --duration 4 --resolution 360p`; with no `--model` the key is the account's selection and it stays headed) reads Flow's quote in a headless browser: it reached the submit 2/2 headless matching a headed control with the submit aborted, and billed headless runs of that key on one account completed at the quoted 4 credits (3/3), and the other measured keys follow it by decision; an account that refused it headless refused the headed control too ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). A capped video of any other shape, image-to-video and reference-to-video stay headed. `GFLOW_CLI_TRANSPORT=ui_automation` keeps it headed | ## Headed (Flow's UI) @@ -52,8 +53,8 @@ browser has been measured, so `auto` runs them headless. | `image upscale --scale 2k` | headed | Headless was refused on one of two accounts while headed passed: after a day of runs, `SPrCad` answered `PUBLIC_ERROR_UNUSUAL_ACTIVITY` to three headless 2K upscales and accepted the headed one (unbilled); the other account passed both ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). `--scale 4k` (Ultra) follows the same path and stays headed | | `movie run` | headed | Scene requests carry no resolution, so no scene forms a measured key; characters and instruction cards are UI surfaces too | | `video r2v` | headed | Reference-to-video is not measured over direct HTTP | -| `video edit` | headed | Not measured over direct HTTP | -| `video i2v --end-frame` | headed | An end frame, or a start frame that is already in the project, is not a measured shape | +| `video edit` | headed | On an account served flow.google.com, gflow cannot drive it yet in either mode (exit 23, [#1605](https://github.com/ffroliva/gflow-cli/issues/1605)), so headless is unmeasured | +| `video i2v --end-frame` | headed | An end frame, or a start frame that is already in the project, is not a measured shape. A billed headless run was refused as unusual activity (unbilled) while the headed control completed ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | | `video upscale --scale 1080p` (menu) | headed | 1080p of a clip the local catalog does not hold as a measured direct source is planned through the download menu and launches headed; not measured headless (the menu offered no 1080p on the clip tried). A planned direct 1080p that falls back to the menu at run time stays in the headless browser it launched | | `scene create` | headed | Reads the retired labs.google session token; refused identically headless and headed on an account served flow.google.com (HTTP 410), so headless is unmeasured ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554), [#639](https://github.com/ffroliva/gflow-cli/issues/639)) | | `scene show` | headed | As `scene create` | @@ -62,7 +63,7 @@ browser has been measured, so `auto` runs them headless. | `instructions add` | headed | Every `instructions` subcommand reads a labs.google route that an account served flow.google.com refuses, identically headless and headed, so headless is unmeasured ([#639](https://github.com/ffroliva/gflow-cli/issues/639)) | | `project create` | headed | Creates the project in the UI (also `project rename`) | | `data sync` | headed | Reads the project in the profile's browser | -| `video t2v --max-credits` | headed | Any credit-capped video (`--max-credits`, `GFLOW_CLI_MAX_CREDITS`, MCP `max_credits`) reads Flow's quote in the UI; direct video has no wire quote | +| `video t2v --max-credits` (other shapes) | headed | A credit-capped video (`--max-credits`, `GFLOW_CLI_MAX_CREDITS`, MCP `max_credits`) whose shape is not a measured direct key reads Flow's quote in the UI; direct video has no wire quote | These conditions also send a request that would otherwise go direct to the headed UI path: diff --git a/docs/MCP.md b/docs/MCP.md index cfc8f9634..eb09f6418 100644 --- a/docs/MCP.md +++ b/docs/MCP.md @@ -114,7 +114,7 @@ An omitted parameter cannot clear that environment default for one MCP call. 400 problem-details envelope), the twin of the CLI's `--browser-visibility`; omitted, the server's `GFLOW_CLI_BROWSER_VISIBILITY` applies. Under `auto`, a measured shape runs with a headless browser that only mints the reCAPTCHA token and is sent over direct HTTP; any other -shape, and any video with a `max_credits` cap, opens a headed browser. The exception is +shape, and every video with a `max_credits` cap, opens a headed browser, except a capped text-to-video of an explicit measured model, duration and resolution, which runs headless (#1554). The exception is `gflow_extend_video` on `flow.google.com`: it drives Flow's UI, which is measured headless, so `auto` runs it headless ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)), as do the page fallback of `gflow_media_trash` / `gflow_media_restore`, a `gflow_generate_image` call whose only reference diff --git a/docs/superpowers/memory/real-browser-auth-mandatory.md b/docs/superpowers/memory/real-browser-auth-mandatory.md index a8eb20307..237a0b1e9 100644 --- a/docs/superpowers/memory/real-browser-auth-mandatory.md +++ b/docs/superpowers/memory/real-browser-auth-mandatory.md @@ -46,6 +46,7 @@ visibility, decided acceptance. A not-charged refusal is retried once from a fre Flow page in the profile's Chrome, never synthesised, stored or replayed. A UI surface runs headless only once it is measured headless (`HEADLESS_UI_SURFACES`, docs/BROWSER_MODES.md); every other surface (r2v, edit, end-frame i2v, image upscale, scenes, characters, instructions, the agent -composer, credit-capped video) still drives the Flow UI, headed. The Chrome-channel rule above binds +composer, credit-capped video other than a text-to-video of an explicit measured key) still +drives the Flow UI, headed. The Chrome-channel rule above binds headless launches exactly as headed ones: a marker-less profile still downgrades to bundled Chromium, so generation paths still require a Chrome-strategy profile. diff --git a/docs/superpowers/spikes/2026-11-29-headless-billed-video-ui.md b/docs/superpowers/spikes/2026-11-29-headless-billed-video-ui.md new file mode 100644 index 000000000..d5430ad3b --- /dev/null +++ b/docs/superpowers/spikes/2026-11-29-headless-billed-video-ui.md @@ -0,0 +1,62 @@ +# Spike: the billed video UI surfaces in a headless browser (#1554) + +**Date:** 2026-11-29 · **Script:** +[`scripts/dev/spike_headless_billed_ui.py`](../../../scripts/dev/spike_headless_billed_ui.py) + +## Method + +Two stages per surface, on accounts served flow.google.com (Windows 11, Chrome stable): + +1. **$0, up to the submit.** The production migrated-host path (`run_video_edit` / + `run_video`) launched through `FlowApiClient(visibility=…)`, the page minting its own + reCAPTCHA token, and the billed request aborted before it left the browser by the billing + guard of `scripts/dev/spike_1228_route_abort_drift.py` (`jIps6` added to its billed set). Two + runs per mode, headless first, then the headed control; the balance read before and after. +2. **One billed headless run** through the real CLI under `--max-credits 10`, with a headed + control when the headless run was refused. + +## Observations + +### Stage 1 ($0; balance unchanged) + +| Surface | Headless | Headed | Billed RPC reached | +|---|---|---|---| +| `video edit` (existing clip) | 0/2, exit 23 | 0/2, exit 23 | none: "a video edit control did not respond" | +| `video r2v` (one local image) | 2/2 | 2/2 | `MZZa6b` | +| `video i2v --end-frame` (local frames) | 2/2 | 2/2 | `nprQif` | +| capped `video t2v` (the account's selected model, no duration or resolution) | 2/2 | 2/2 | `YhhmEf` | + +The real CLI reproduced the edit failure in both modes under a 1-credit cap (exit 23, nothing +charged): [#1605](https://github.com/ffroliva/gflow-cli/issues/1605). + +### Stage 2 (billed, `--max-credits 10`) + +| Surface | Account | Headless | Headed control | +|---|---|---|---| +| capped `video t2v` (Omni 1.2 Flash, 4 s, 360p) | A (free plan, after a day of runs) | refused, `PUBLIC_ERROR_UNUSUAL_ACTIVITY`, unbilled | **refused the same way** (later the same evening) | +| capped `video t2v` (same shape) | B | completed, quoted 4 credits (3/3 headless with the CLI and MCP e2e below) | — | +| `video i2v --end-frame` | B | refused, unbilled | completed, quoted 10 credits | +| `video r2v` (Omni 1.2 Flash, 4 s, 360p) | B | completed, quoted 4 credits | — | + +Under `auto`, the capped text-to-video first ran headed in the live e2e: the direct transport +attempts first, the cap ends that attempt not-sent, and the retry loop's UI fallback relaunched +headed. With the fallback keeping the headless launch for this surface, the CLI and MCP e2e +completed headless (2/2). + +## Verdict + +- **Capped `video t2v` of an explicit measured key: headless.** Account A refused it headed as + well, so its refusal reflects the account's state, not the headless launch. Same up to the submit (stage 1 + used the account's selected model), a billed headless run of Omni 1.2 Flash, 4 s, 360p + completed, and the e2e passes headless. A bare text-to-video (no model: its key is the + account's selection, unread before the quote) and capped videos of other shapes stay headed. +- **`video r2v`: headless candidate** (same up to the submit, a billed headless run completed); + decided in its own change. +- **`video i2v --end-frame`: stays headed.** The billed headless run was refused while the headed + control completed. +- **`video edit`: stays headed**, unmeasured until #1605 is resolved. + +## Not measured + +macOS, Linux, a third account, accounts Flow serves on labs.google; r2v with several +references or a character; other capped shapes. diff --git a/scripts/dev/spike_headless_billed_ui.py b/scripts/dev/spike_headless_billed_ui.py new file mode 100644 index 000000000..d2df3bd38 --- /dev/null +++ b/scripts/dev/spike_headless_billed_ui.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python3 +"""#1554 spike ($0): do the billed video UI surfaces reach their submit the same way in a headless +Chrome as in a headed one? + +Surfaces: ``edit`` (video-to-video edit of an existing clip, ``jIps6``), ``r2v`` (reference-to-video +from a local image), ``i2v-end`` (image-to-video with local start and end frames) and +``t2v-capped`` (text-to-video under a credit cap, which reads Flow's quote in the UI). + +Method: each run opens the profile through the production launcher, +``FlowApiClient(visibility=)``, drives ONE production migrated-host path straight on the page +(``run_video_edit`` / ``run_video``), lets the page mint its own reCAPTCHA token, and aborts the +billed request before it leaves the browser with the billing guard of +``scripts/dev/spike_1228_route_abort_drift.py`` (its billed set extended with ``jIps6``). It +records which billed RPC the run reached. Headless runs first, then the headed control. + +Cost: navigation, uploads and reCAPTCHA mints are free; nothing billed is sent. The caller reads +``gflow credits user`` before and after; the script reads it after every trial and stops on any +drop. Side effect: r2v and i2v-end runs leave uploaded images in the project. + +Pre-registered readings (written before the first run) +------------------------------------------------------ +| Headless | Headed | Reading | +|---|---|---| +| N/N reach the expected billed RPC | N/N | same up to the submit: one billed headless run decides | +| fewer than N/N | N/N | headless differs before the submit: stays headed | +| any | fewer than N/N | the control failed: unmeasured | +| any LEAK or credit drop | | STOP, report, run nothing else | + +Usage:: + + uv run python scripts/dev/spike_headless_billed_ui.py --profile \ + --config scripts/dev/_spike_out/spike_1228/ids.json --path edit --runs 2 + +``ids.json`` holds ``project`` and ``video_media`` (a finished clip in ``project``). +""" + +from __future__ import annotations + +import argparse +import asyncio +import contextlib +import json +import subprocess +import sys +import time +from pathlib import Path +from typing import Any + +sys.path.insert(0, str(Path(__file__).parent)) +import spike_1228_route_abort_drift as drift # noqa: E402 + +drift.BILLED = drift.BILLED | {"jIps6"} # the guard reads the module global at call time +EXPECTED = { + "edit": {"jIps6"}, + "r2v": set(drift.BILLED), + "i2v-end": {"eb1hJf", "nprQif"}, + "t2v-capped": {"YhhmEf", "MZZa6b", "nprQif"}, +} +PROMPT = "a slow dolly across a quiet harbour at dawn" + + +async def drive(path: str, page: Any, ids: dict[str, str], tmp: Path) -> None: + from gflow_cli.api.transports import migrated_composer as mc + from gflow_cli.api.transports.migrated_video_edit import run_video_edit + from gflow_cli.api.video import Aspect, EditVideoRequest, GenerateVideoRequest, Mode, VideoModel + + async def save(_name: str, _data: bytes) -> Path: + raise AssertionError("nothing should be downloaded") + + common: dict[str, Any] = {"save": save, "poll_timeout_s": 30.0, "download": False} + if path == "edit": + req = EditVideoRequest(prompt=PROMPT, source_media_id=ids["video_media"]) + await run_video_edit(page, req, project_id=ids["project"], on_started=None, **common) + return + start = drift.frame_png(tmp / "start.png") + fields: dict[str, Any] = {"prompt": PROMPT, "aspect": Aspect.PORTRAIT} + if path == "r2v": + fields |= {"mode": Mode.R2V, "reference_images": (start,)} + elif path == "i2v-end": + end = drift.frame_png(tmp / "end.png") + fields |= {"mode": Mode.I2V, "start_image": start, "end_image": end} + fields["model"] = VideoModel.VEO_3_1_LITE + elif path == "t2v-capped": + fields |= {"mode": Mode.T2V, "max_credits": 20} + else: + raise SystemExit(f"unknown path {path}") + await mc.run_video( + page, GenerateVideoRequest(**fields), project_id=ids["project"], on_started=None, **common + ) + + +async def one_run(path: str, mode: str, profile_dir: Path, ids: dict[str, str]) -> dict[str, Any]: + from gflow_cli.api.client import FlowApiClient + from gflow_cli.api.submit_policy import BrowserVisibility + + guard = drift.Guard() + started = time.monotonic() + outcome = "captured" + async with FlowApiClient(profile_dir=profile_dir, visibility=BrowserVisibility(mode)) as client: + page = client._page # noqa: SLF001 - the spike drives the live page + assert page is not None + await page.context.route("**/batchexecute**", guard.on_route) + page.context.on("response", guard.on_response) + tmp = drift.OUT / "tmp" + tmp.mkdir(parents=True, exist_ok=True) + task = asyncio.create_task(drive(path, page, ids, tmp)) + waiter = asyncio.create_task(guard.got.wait()) + done, _ = await asyncio.wait({task, waiter}, timeout=180, return_when="FIRST_COMPLETED") + if waiter in done: + await asyncio.sleep(3) # let a second billed request (if any) show itself + if task.done() and task.exception() is not None: + exc = task.exception() + outcome = f"driver ended: {type(exc).__name__}: {str(exc).splitlines()[0][:200]}" + for t in (task, waiter): + t.cancel() + with contextlib.suppress(BaseException): + await t + rpcs = sorted({rpc for c in guard.captured for rpc in c.get("billed_ids", ["?"])}) + if not guard.captured: + outcome = f"UNMEASURED ({outcome})" + return { + "path": path, + "mode": mode, + "seconds": round(time.monotonic() - started, 1), + "outcome": outcome, + "rpcs": rpcs, + "expected": bool(set(rpcs) & EXPECTED[path]), + "unresolved": len(guard.unresolved), + "leaks": len(guard.leaks), + } + + +def balance(profile: str) -> object: + proc = subprocess.run( # noqa: S603 - fixed argv + [sys.executable, "-m", "gflow_cli", "credits", "user", "--profile", profile, "--json"], + capture_output=True, + text=True, + encoding="utf-8", + check=False, + timeout=180, + ) + try: + return json.loads(proc.stdout).get("credits") + except ValueError: + return None + + +async def main() -> int: + from gflow_cli.config import get_settings + + ap = argparse.ArgumentParser(description=(__doc__ or "").split("\n")[0]) + ap.add_argument("--profile", required=True) + ap.add_argument("--config", type=Path, required=True) + ap.add_argument("--path", choices=sorted(EXPECTED), required=True) + ap.add_argument("--runs", type=int, default=2) + args = ap.parse_args() + ids = json.loads(args.config.read_text(encoding="utf-8")) + profile_dir = get_settings().profile_subdir(args.profile) + before = balance(args.profile) + print(json.dumps({"credits_before": before}), flush=True) + drift.wrap_continue() + for mode in ("headless", "headed"): + for _ in range(args.runs): + rec = await one_run(args.path, mode, profile_dir, ids) + print(json.dumps(rec), flush=True) + if rec["leaks"] or rec["unresolved"]: + print(json.dumps({"STOP": "leak" if rec["leaks"] else "unclassified request"})) + return 3 + after = balance(args.profile) # per trial: a drop stops the next one + print(json.dumps({"credits_after": after}), flush=True) + if before is None or after is None: + print(json.dumps({"STOP": "balance unreadable: credit drop unmeasured"})) + return 4 + if after != before: + print(json.dumps({"STOP": "credit drop"})) + return 3 + return 0 + + +if __name__ == "__main__": + raise SystemExit(asyncio.run(main())) diff --git a/src/gflow_cli/_cli_helpers.py b/src/gflow_cli/_cli_helpers.py index 3e0998da0..8d87f1a34 100644 --- a/src/gflow_cli/_cli_helpers.py +++ b/src/gflow_cli/_cli_helpers.py @@ -779,6 +779,7 @@ def client_visibility( # every other UI surface stays headed until it is measured. HEADLESS_UI_SURFACES: Final = frozenset( { + "video t2v capped", "video extend", "media trash", "image i2i --ref", @@ -806,20 +807,36 @@ def ui_surface_visibility( async def video_client_visibility( - settings: Settings, profile_dir: Path, routes: Sequence[Route] + settings: Settings, + profile_dir: Path, + routes: Sequence[Route] | None = None, + *, + request: GenerateVideoRequest | None = None, + transport: str | None = None, ) -> BrowserVisibility: """:func:`client_visibility` for video, after the browser-free zero-balance check. A planned direct clip meeting a balance of 0 ends with exit 37 before any browser launches; an unreadable balance skips the check. This is the only balance check: once - the profile's Chrome runs, it holds the on-disk cookie jar the read needs. + the profile's Chrome runs, it holds the on-disk cookie jar the read needs. With + ``request``, a capped text-to-video whose cap is its only reason for the UI launches + headless (#1554); without ``routes``, the request's own route is planned. """ + if routes is None: # one clip, planned on its own request + assert request is not None + routes = (video_route(request, transport=transport),) if Route.DIRECT in routes: from gflow_cli.api.transports.direct_http._transport import ( # noqa: PLC0415 refuse_empty_balance, ) await refuse_empty_balance(profile_dir) + if ( + request is not None + and _direct_transport(transport) + and direct_route.cap_is_the_only_ui_reason(request) + ): + return ui_surface_visibility(settings, "video t2v capped", transport=transport) return client_visibility(settings, routes) diff --git a/src/gflow_cli/api/_flow_generation.py b/src/gflow_cli/api/_flow_generation.py index 31803a1b7..eda10a0a9 100644 --- a/src/gflow_cli/api/_flow_generation.py +++ b/src/gflow_cli/api/_flow_generation.py @@ -242,27 +242,43 @@ def _validate_fife_final_url(url: str) -> None: raise ValueError(msg) from None +def _keep_headless_fallback( + setting: VisibilitySetting | str, launched: BrowserVisibility, measured: bool +) -> VisibilitySetting: + """The setting the retry loop applies to a UI fallback. + + A run launched headless under ``auto`` for a measured headless UI surface (#1554) keeps + that headless browser when its direct attempt falls back to the UI; anything else keeps + the setting, so ``auto`` still falls back headed. + """ + resolved = VisibilitySetting(setting) + if resolved is VisibilitySetting.AUTO and launched is BrowserVisibility.HEADLESS and measured: + return VisibilitySetting.HEADLESS + return resolved + + def image_fallback_setting( setting: VisibilitySetting | str, launched: BrowserVisibility, request: GenerateImageRequest, ) -> VisibilitySetting: - """The setting the image retry loop applies to a UI fallback. + """:func:`_keep_headless_fallback` for the local-reference image surface.""" + from gflow_cli.api.transports.direct_http import _route as direct_route # noqa: PLC0415 - A run launched headless under ``auto`` for the measured local-reference surface (#1554) - keeps that headless browser when its direct attempt falls back to the UI; anything else - keeps the setting, so ``auto`` still falls back headed. - """ + return _keep_headless_fallback(setting, launched, direct_route.local_file_refs_only(request)) + + +def video_fallback_setting( + setting: VisibilitySetting | str, + launched: BrowserVisibility, + request: GenerateVideoRequest, +) -> VisibilitySetting: + """:func:`_keep_headless_fallback` for the capped measured-shape text-to-video surface.""" from gflow_cli.api.transports.direct_http import _route as direct_route # noqa: PLC0415 - resolved = VisibilitySetting(setting) - if ( - resolved is VisibilitySetting.AUTO - and launched is BrowserVisibility.HEADLESS - and direct_route.local_file_refs_only(request) - ): - return VisibilitySetting.HEADLESS - return resolved + return _keep_headless_fallback( + setting, launched, direct_route.cap_is_the_only_ui_reason(request) + ) class GenerationSurface(WorkspaceSurface): @@ -1000,7 +1016,9 @@ def transport() -> DirectHttpTransport: on_started=on_started, **resolver_kw, ), - setting=VisibilitySetting(self.settings.browser_visibility), + setting=video_fallback_setting( + self.settings.browser_visibility, cast("RetryHost", self).visibility, request + ), on_checkpoint=on_checkpoint, observe=self._observed, ) diff --git a/src/gflow_cli/api/transports/direct_http/_route.py b/src/gflow_cli/api/transports/direct_http/_route.py index 51dc8febd..a7fe3ee87 100644 --- a/src/gflow_cli/api/transports/direct_http/_route.py +++ b/src/gflow_cli/api/transports/direct_http/_route.py @@ -16,8 +16,10 @@ choose_upscale_route, choose_video_route, direct_can_serve, + video_target, ) from gflow_cli.api.image import ImageRef +from gflow_cli.api.video import Mode from gflow_cli.config import UiMode, get_settings, resolve_ui_mode if TYPE_CHECKING: @@ -91,6 +93,19 @@ def video_route(request: GenerateVideoRequest) -> Route: ) +def cap_is_the_only_ui_reason(request: GenerateVideoRequest) -> bool: + """True for a credit-capped text-to-video whose uncapped request routes direct. + + A cap sends a video to the UI, where Flow's quote is read; when nothing else would, the + run is the measured headless capped-text-to-video surface (#1554). + """ + if request.mode is not Mode.T2V or request.max_credits is None: + return False + uncapped = replace(request, max_credits=None) + # An explicit measured key: a bare t2v's key is the account's selection, read on the page. + return video_target(uncapped) is not None and video_route(uncapped) is Route.DIRECT + + def upscale_route(scale: str, catalog_row: object | None) -> Route: """The route a video upscale takes, from the local catalog row alone.""" return choose_upscale_route( diff --git a/src/gflow_cli/cli_video.py b/src/gflow_cli/cli_video.py index d6c0bcbe8..0a0123932 100644 --- a/src/gflow_cli/cli_video.py +++ b/src/gflow_cli/cli_video.py @@ -323,7 +323,7 @@ async def _generate_and_report( recorder = OperationRecorder.open(settings) started_media_ids: list[str] = [] try: - visibility = await video_client_visibility(settings, profile_dir, (video_route(request),)) + visibility = await video_client_visibility(settings, profile_dir, request=request) async with FlowApiClient( profile_dir=profile_dir, out_dir=out_dir, visibility=visibility ) as client: diff --git a/src/gflow_cli/mcp/generation_params.py b/src/gflow_cli/mcp/generation_params.py index af84d404e..3ce0e27d1 100644 --- a/src/gflow_cli/mcp/generation_params.py +++ b/src/gflow_cli/mcp/generation_params.py @@ -44,9 +44,9 @@ def bad_param(title: str, detail: str) -> dict[str, Any]: "Browser window policy for this job; overrides GFLOW_CLI_BROWSER_VISIBILITY. " "'auto' (the default): shapes the direct path can send run with a headless " "browser that only mints the reCAPTCHA token, and a refusal Flow did not charge " - "is retried once from a new headless browser; shapes it cannot send, a capped " - "video (max_credits) among them, open a visible browser, except a video extend " - "on flow.google.com, which is measured headless and runs headless. 'headed' " + "is retried once from a new headless browser; shapes it cannot send open a " + "visible browser, except the Flow UI shapes measured headless (a video extend on " + "flow.google.com, a capped text-to-video of an explicit measured key). 'headed' " "always shows the window. 'headless' also runs other Flow UI shapes headless, " "which is unsupported. " "Case-insensitive; any other value is a 400." diff --git a/src/gflow_cli/mcp/tools.py b/src/gflow_cli/mcp/tools.py index 7e84c92b4..8269248c1 100644 --- a/src/gflow_cli/mcp/tools.py +++ b/src/gflow_cli/mcp/tools.py @@ -1264,9 +1264,10 @@ async def gflow_generate_image( "Text-to-video and start-frame image-to-video at measured model keys go over direct " "HTTP with a headless browser that only mints the reCAPTCHA token; a refusal Flow " "did not charge is retried once from a new headless browser, and a second one is " - "final (retryable false, next_action wait). Other shapes, and any capped video, open " - "a visible browser; browser_visibility overrides. The result names route, visibility " - "and retried. " + "final (retryable false, next_action wait). A capped text-to-video of an explicit " + "measured key reads the quote in a headless browser; other shapes and other capped " + "videos open a visible one; browser_visibility overrides. The result names route, " + "visibility and retried. " "On flow.google.com, an i2v initial_frame or end_frame may be a Flow image UUID the " "catalog records in project with a caption; it is bound on the UI path with no upload, " "while a cross-project UUID (or un-captioned UUID with a local fallback) returns the " diff --git a/src/gflow_cli/worker/daemon.py b/src/gflow_cli/worker/daemon.py index 735aacd29..1283efdc9 100644 --- a/src/gflow_cli/worker/daemon.py +++ b/src/gflow_cli/worker/daemon.py @@ -17,7 +17,6 @@ slugify_project_name, ui_surface_visibility, video_client_visibility, - video_route, ) from gflow_cli.api.client import FlowApiClient from gflow_cli.api.credit_cap import resolve_max_credits @@ -509,8 +508,8 @@ async def _generate(request: GenerateImageRequest) -> list[GeneratedImage]: ) elif task.task_type in ("t2v", "i2v", "r2v"): - # The configured cap is resolved once, before the route: a capped job - # never launches headless (SCENARIO.md rows 11, 33). + # The configured cap is resolved once, before the route: a capped job takes + # the UI route, headless only for an explicit measured key (#1554). req = _apply_configured_video_cap( cast("GenerateVideoRequest", task.decoded.request) if task.decoded is not None @@ -526,7 +525,10 @@ async def _generate(request: GenerateImageRequest) -> list[GeneratedImage]: # declared Optional at method scope for the #341 failure funnel). video_recorder = recorder visibility = await video_client_visibility( - settings, profile_dir, (video_route(req, transport=transport),) + settings, + profile_dir, + request=req, + transport=transport, ) try: async with FlowApiClient( diff --git a/tests/api/test_generation_route.py b/tests/api/test_generation_route.py index c4ea2fc92..13f95d257 100644 --- a/tests/api/test_generation_route.py +++ b/tests/api/test_generation_route.py @@ -1242,3 +1242,41 @@ def test_image_fallback_setting( reset_settings() request = GenerateImageRequest(prompt="a cube", ref_paths=(Path("a.jpg"),) if local else ()) assert image_fallback_setting(setting, launched, request) is expected + + +@pytest.mark.parametrize( + ("setting", "launched", "cap", "resolution", "expected"), + [ + # A capped measured-shape t2v launched headless keeps headless on the UI fallback. + ("auto", BrowserVisibility.HEADLESS, 10, "360p", VisibilitySetting.HEADLESS), + # Launched headed, uncapped, or an unmeasured shape: the setting is unchanged. + ("auto", BrowserVisibility.HEADED, 10, "360p", VisibilitySetting.AUTO), + ("auto", BrowserVisibility.HEADLESS, None, "360p", VisibilitySetting.AUTO), + ("auto", BrowserVisibility.HEADLESS, 10, "720p", VisibilitySetting.AUTO), + ("headed", BrowserVisibility.HEADLESS, 10, "360p", VisibilitySetting.HEADED), + ], +) +def test_video_fallback_setting( + monkeypatch: pytest.MonkeyPatch, + setting: str, + launched: BrowserVisibility, + cap: int | None, + resolution: str, + expected: VisibilitySetting, +) -> None: + from gflow_cli.api._flow_generation import video_fallback_setting + + for key in ("GFLOW_CLI_FLOW_HOST", "GFLOW_CLI_UI_MODE", "GFLOW_CLI_TRANSPORT"): + monkeypatch.delenv(key, raising=False) + monkeypatch.setattr("gflow_cli.api.flow_wire.proxy_configured", lambda: False) + reset_settings() + request = GenerateVideoRequest( + prompt="a harbour", + mode=Mode.T2V, + model=VideoModel.OMNI_1_2_FLASH, + duration=4, + resolution=resolution, + aspect=VideoAspect.PORTRAIT, + max_credits=cap, + ) + assert video_fallback_setting(setting, launched, request) is expected diff --git a/tests/e2e/test_credit_cap_refusal_bdd.py b/tests/e2e/test_credit_cap_refusal_bdd.py index 379a58c4c..38f669584 100644 --- a/tests/e2e/test_credit_cap_refusal_bdd.py +++ b/tests/e2e/test_credit_cap_refusal_bdd.py @@ -21,6 +21,7 @@ from gflow_cli.api.transports.ui_automation import UiAutomationTransport from gflow_cli.cli import main from gflow_cli.mcp import tools as mcp_tools +from tests.e2e._visibility import expected_visibility scenarios("../features/credit_cap_refusal.feature") @@ -212,3 +213,54 @@ def _paid_success(world: dict[str, Any]) -> None: data = json.loads(result.stdout) output = Path(data["local_path"]) assert output.is_file() and output.stat().st_size > 0 + + +# --- #1554: a cap is the only reason for the UI -> headless under auto ---------------------- + + +_FLASH = ("--model", "omni-1.2-flash", "--duration", "4", "--resolution", "360p") + + +@when("the operator requests an omni-1.2-flash 4-second x1 360p 9:16 video with max_credits 10") +def _cli_flash_capped(world: dict[str, Any]) -> None: + config.reset_settings() + args = ["video", "t2v", _PROMPT, "--project", world["project"], *_FLASH] + args += ["--aspect", "9:16", "--max-credits", "10", "--json"] + world["cli"] = CliRunner().invoke(main, args, env=world["env"]) + + +@when("MCP requests an omni-1.2-flash 4-second x1 360p 9:16 video with max_credits 10") +def _mcp_flash_capped(monkeypatch: pytest.MonkeyPatch, world: dict[str, Any]) -> None: + for key, value in world["env"].items(): + monkeypatch.setenv(key, value) + config.reset_settings() + world["mcp"] = asyncio.run( + mcp_tools.gflow_generate_video( + prompt=_PROMPT, + mode="t2v", + aspect="9:16", + model="omni-1.2-flash", + duration=4, + resolution="360p", + count=1, + max_credits=10, + profile=world["profile"], + project=world["project"], + wait=True, + ) + ) + + +@then("the CLI completes on the UI route at the expected visibility") +def _cli_capped_headless(world: dict[str, Any]) -> None: + result = world["cli"] + assert result.exit_code == 0, result.output + data = json.loads(result.stdout) + assert (data.get("route"), data.get("visibility")) == ("ui", expected_visibility()), data + + +@then("the MCP tool completes on the UI route at the expected visibility") +def _mcp_capped_headless(world: dict[str, Any]) -> None: + result = world["mcp"] + assert result.get("status") == "completed", result + assert (result.get("route"), result.get("visibility")) == ("ui", expected_visibility()), result diff --git a/tests/features/credit_cap_refusal.feature b/tests/features/credit_cap_refusal.feature index b5151313f..bf6009b5c 100644 --- a/tests/features/credit_cap_refusal.feature +++ b/tests/features/credit_cap_refusal.feature @@ -27,3 +27,15 @@ Feature: Pre-submit credit cap enforcement against Flow's live quote Given a live classic Flow project served by flow.google.com with paid video E2E enabled When the operator requests an omni-1.2 4-second x1 360p video with max_credits 4 Then the CLI completes and downloads a non-empty MP4 + + @e2e_video + Scenario: A capped measured-shape text-to-video runs headless on the CLI (#1554) + Given a live classic Flow project served by flow.google.com with paid video E2E enabled + When the operator requests an omni-1.2-flash 4-second x1 360p 9:16 video with max_credits 10 + Then the CLI completes on the UI route at the expected visibility + + @e2e_video + Scenario: A capped measured-shape text-to-video runs headless over MCP (#1554) + Given a live classic Flow project served by flow.google.com with paid video E2E enabled + When MCP requests an omni-1.2-flash 4-second x1 360p 9:16 video with max_credits 10 + Then the MCP tool completes on the UI route at the expected visibility diff --git a/tests/mcp/test_browser_visibility_mcp.py b/tests/mcp/test_browser_visibility_mcp.py index b95b0f8da..772600454 100644 --- a/tests/mcp/test_browser_visibility_mcp.py +++ b/tests/mcp/test_browser_visibility_mcp.py @@ -169,7 +169,8 @@ def _video_result() -> VideoResult: async def test_mcp_max_credits_video_routes_ui(wired: MagicMock) -> None: """A measured shape goes direct and headless; the same shape with a cap goes to the UI, - headed, because only the UI reads Flow's quote (SCENARIO row 11).""" + because only the UI reads Flow's quote (SCENARIO row 11), still headless: the cap is its + only reason for the UI (#1554).""" from gflow_cli.mcp.tools import gflow_generate_video wired.return_value.generate_video = AsyncMock(return_value=_video_result()) @@ -180,7 +181,7 @@ async def test_mcp_max_credits_video_routes_ui(wired: MagicMock) -> None: capped = await gflow_generate_video(prompt="a river", max_credits=5, **_MEASURED_T2V) assert capped["status"] == "completed" - assert _client_kwargs(wired)["visibility"] is BrowserVisibility.HEADED + assert _client_kwargs(wired)["visibility"] is BrowserVisibility.HEADLESS sent = wired.return_value.generate_video.await_args.kwargs["req"] assert sent.max_credits == 5 diff --git a/tests/test_cli_browser_visibility.py b/tests/test_cli_browser_visibility.py index 239bbb30e..4f90bbf38 100644 --- a/tests/test_cli_browser_visibility.py +++ b/tests/test_cli_browser_visibility.py @@ -335,3 +335,61 @@ def _no_read(*_: object) -> None: settings, tmp_path, "m-1", "1080p", kind="video", route=Route.DIRECT ) assert launch is BrowserVisibility.HEADLESS + + +# --- #1554: credit-capped text-to-video (the cap is the only reason for the UI) ------------- + + +def _video(**kw: object) -> object: + from gflow_cli.api.video import Aspect, GenerateVideoRequest, Mode, VideoModel + + fields: dict[str, object] = { + "prompt": "a harbour", + "mode": Mode.T2V, + "model": VideoModel.OMNI_1_2_FLASH, + "duration": 4, + "resolution": "360p", + "aspect": Aspect.PORTRAIT, + } + fields.update(kw) + if isinstance(fields.get("mode"), str): + fields["mode"] = Mode(fields["mode"]) + return GenerateVideoRequest(**fields) # type: ignore[arg-type] + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("kw", "env", "launch"), + [ + # A measured direct t2v made UI only by its cap: measured headless (#1554). + ({"max_credits": 10}, {}, BrowserVisibility.HEADLESS), + # Capped, but the shape is not a measured direct key: the UI for another reason. + ({"max_credits": 10, "resolution": "720p"}, {}, BrowserVisibility.HEADED), + # A bare t2v: its key is the account's selection, never read before the quote. + ({"max_credits": 10, "model": None}, {}, BrowserVisibility.HEADED), + # Only a text-to-video was measured; agentic mode is the UI for another reason. + ( + {"max_credits": 10, "mode": "i2v", "start_image": Path("f.png")}, + {}, + BrowserVisibility.HEADED, + ), + ({"max_credits": 10}, {"GFLOW_CLI_UI_MODE": "agentic"}, BrowserVisibility.HEADED), + ({"max_credits": 10}, {"GFLOW_CLI_TRANSPORT": "ui_automation"}, BrowserVisibility.HEADED), + ({"max_credits": 10}, {"GFLOW_CLI_BROWSER_VISIBILITY": "headed"}, BrowserVisibility.HEADED), + ], +) +async def test_capped_t2v_visibility( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + kw: dict[str, object], + env: dict[str, str], + launch: BrowserVisibility, +) -> None: + from gflow_cli._cli_helpers import video_client_visibility, video_route + + settings = _image_settings(monkeypatch, **env) + monkeypatch.setattr("gflow_cli.api.flow_wire.proxy_configured", lambda: False) + request = _video(**kw) + routes = (video_route(request),) # type: ignore[arg-type] + got = await video_client_visibility(settings, tmp_path, routes, request=request) # type: ignore[arg-type] + assert got is launch diff --git a/tests/test_cli_routing.py b/tests/test_cli_routing.py index fae178ae6..ad0ed7d70 100644 --- a/tests/test_cli_routing.py +++ b/tests/test_cli_routing.py @@ -248,7 +248,8 @@ def test_capped_t2v_constructs_headed_client(tmp_path: Path) -> None: *("--model", "omni-1.2-flash", "--duration", "4", "--resolution", "360p"), *("--aspect", "16:9", "--max-credits", "50"), ) - assert _launched(factory, tmp_path) is BrowserVisibility.HEADED + # The UI route reads Flow's quote; a capped measured key launches it headless (#1554). + assert _launched(factory, tmp_path) is BrowserVisibility.HEADLESS def test_ui_only_commands_launch_headed_under_auto(tmp_path: Path) -> None: @@ -431,20 +432,21 @@ async def test_worker_routes_after_effective_cap( tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: """SCENARIO.md row 11: the configured cap is resolved before the route, so a job with no - cap of its own never launches headless while ``GFLOW_CLI_MAX_CREDITS`` is set.""" + cap of its own takes the UI route while ``GFLOW_CLI_MAX_CREDITS`` is set (headless for a + measured key, #1554).""" visibility = await _worker_video_visibility(tmp_path / "open", _MEASURED_T2V_PAYLOAD) assert visibility is BrowserVisibility.HEADLESS monkeypatch.setenv("GFLOW_CLI_MAX_CREDITS", "50") config.reset_settings() visibility = await _worker_video_visibility(tmp_path / "capped", _MEASURED_T2V_PAYLOAD) - assert visibility is BrowserVisibility.HEADED + assert visibility is BrowserVisibility.HEADLESS -async def test_mcp_capped_video_constructs_headed_client(tmp_path: Path) -> None: - """SCENARIO.md row 33: MCP ``max_credits`` travels in the queued payload; the worker - builds the client headed for it.""" +async def test_mcp_capped_measured_video_launches_headless(tmp_path: Path) -> None: + """SCENARIO.md row 33: MCP ``max_credits`` travels in the queued payload; the worker reads + the quote on the UI route, headless for a measured key (#1554).""" payload = {**_MEASURED_T2V_PAYLOAD, "max_credits": 50} - assert await _worker_video_visibility(tmp_path, payload) is BrowserVisibility.HEADED + assert await _worker_video_visibility(tmp_path, payload) is BrowserVisibility.HEADLESS # --- council FIX items --------------------------------------------------------------------- @@ -573,7 +575,7 @@ def test_no_max_credits_route_ignores_configured_cap( config.reset_settings() measured = ("--model", "omni-1.2-flash", "--duration", "4", "--resolution", "360p") capped = _invoke_t2v(tmp_path, *measured, "--aspect", "16:9") - assert _launched(capped, tmp_path) is BrowserVisibility.HEADED + assert _launched(capped, tmp_path) is BrowserVisibility.HEADLESS # UI route, headless (#1554) uncapped = _invoke_t2v(tmp_path, *measured, "--aspect", "16:9", "--no-max-credits") assert _launched(uncapped, tmp_path) is BrowserVisibility.HEADLESS assert video_route(measured_t2v()) is Route.DIRECT diff --git a/website/docs/ARCHITECTURE.md b/website/docs/ARCHITECTURE.md index 22ef446fd..7da14962b 100644 --- a/website/docs/ARCHITECTURE.md +++ b/website/docs/ARCHITECTURE.md @@ -483,7 +483,7 @@ used only where it is strictly necessary. - **The UI transport (`ui_automation`) for the other surfaces.** `image batch`, `movie run`, reference-to-video, edit, end-frame image-to-video, the 1080p menu upscale, scene and character create, - instructions, the agent-only composer and other credit-capped video still drive Flow's page in a headed browser. Headless operation of these + instructions, the agent-only composer and credit-capped video other than a text-to-video of an explicit measured key still drive Flow's page in a headed browser. Headless operation of these surfaces is tracked in [#1554](https://github.com/ffroliva/gflow-cli/issues/1554). - **`auth login`** is interactive and needs a display once. - **Selecting the mode.** `GFLOW_CLI_BROWSER_VISIBILITY=auto|headless|headed` (default `auto`); diff --git a/website/docs/BROWSER_MODES.md b/website/docs/BROWSER_MODES.md index 980b4be7b..1bc4405eb 100644 --- a/website/docs/BROWSER_MODES.md +++ b/website/docs/BROWSER_MODES.md @@ -41,6 +41,7 @@ browser has been measured, so `auto` runs them headless. | `image i2i --ref` | headless with one local file | When the only reference is a local file, `--project` names an existing project, and, with each file in the shape an upload produces (one in-project reference), the request would go direct (for example `nano2`), the browser starts headless: a new file is uploaded and generated directly, and a file the catalog already holds in the project is attached through Flow's UI in that headless browser. Two quota runs of the UI attach matched a headed control ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). Two or more files, a UUID reference or a character beside the file, a new project, an unmeasured model, or another reason for the UI keeps it headed. `GFLOW_CLI_TRANSPORT=ui_automation` keeps it headed | | `video upscale --scale 720p` | headless on `flow.google.com` | Drives the video's download menu; 720p and the 270p GIF (`--scale 270p`) each ran twice in a headless browser matching a headed control, 0 credits, including on an account that was refusing headless image upscales at the time ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). `GFLOW_CLI_TRANSPORT=ui_automation` or an explicit `GFLOW_CLI_FLOW_HOST=labs.google` keeps it headed | | `video upscale --scale 4k` | headless on `flow.google.com` (not measured) | Ultra only, so not measured: it follows the measured video download-menu path by an explicit decision ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). It spends credits on the click, and a failure after the click is never retried. `--browser-visibility headed` shows the window | +| `video t2v --max-credits` | headless when only the cap needs the UI | A capped text-to-video whose uncapped request is an explicit measured key (for example `--model omni-1.2-flash --duration 4 --resolution 360p`; with no `--model` the key is the account's selection and it stays headed) reads Flow's quote in a headless browser: it reached the submit 2/2 headless matching a headed control with the submit aborted, and billed headless runs of that key on one account completed at the quoted 4 credits (3/3), and the other measured keys follow it by decision; an account that refused it headless refused the headed control too ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). A capped video of any other shape, image-to-video and reference-to-video stay headed. `GFLOW_CLI_TRANSPORT=ui_automation` keeps it headed | ## Headed (Flow's UI) @@ -52,8 +53,8 @@ browser has been measured, so `auto` runs them headless. | `image upscale --scale 2k` | headed | Headless was refused on one of two accounts while headed passed: after a day of runs, `SPrCad` answered `PUBLIC_ERROR_UNUSUAL_ACTIVITY` to three headless 2K upscales and accepted the headed one (unbilled); the other account passed both ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)). `--scale 4k` (Ultra) follows the same path and stays headed | | `movie run` | headed | Scene requests carry no resolution, so no scene forms a measured key; characters and instruction cards are UI surfaces too | | `video r2v` | headed | Reference-to-video is not measured over direct HTTP | -| `video edit` | headed | Not measured over direct HTTP | -| `video i2v --end-frame` | headed | An end frame, or a start frame that is already in the project, is not a measured shape | +| `video edit` | headed | On an account served flow.google.com, gflow cannot drive it yet in either mode (exit 23, [#1605](https://github.com/ffroliva/gflow-cli/issues/1605)), so headless is unmeasured | +| `video i2v --end-frame` | headed | An end frame, or a start frame that is already in the project, is not a measured shape. A billed headless run was refused as unusual activity (unbilled) while the headed control completed ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)) | | `video upscale --scale 1080p` (menu) | headed | 1080p of a clip the local catalog does not hold as a measured direct source is planned through the download menu and launches headed; not measured headless (the menu offered no 1080p on the clip tried). A planned direct 1080p that falls back to the menu at run time stays in the headless browser it launched | | `scene create` | headed | Reads the retired labs.google session token; refused identically headless and headed on an account served flow.google.com (HTTP 410), so headless is unmeasured ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554), [#639](https://github.com/ffroliva/gflow-cli/issues/639)) | | `scene show` | headed | As `scene create` | @@ -62,7 +63,7 @@ browser has been measured, so `auto` runs them headless. | `instructions add` | headed | Every `instructions` subcommand reads a labs.google route that an account served flow.google.com refuses, identically headless and headed, so headless is unmeasured ([#639](https://github.com/ffroliva/gflow-cli/issues/639)) | | `project create` | headed | Creates the project in the UI (also `project rename`) | | `data sync` | headed | Reads the project in the profile's browser | -| `video t2v --max-credits` | headed | Any credit-capped video (`--max-credits`, `GFLOW_CLI_MAX_CREDITS`, MCP `max_credits`) reads Flow's quote in the UI; direct video has no wire quote | +| `video t2v --max-credits` (other shapes) | headed | A credit-capped video (`--max-credits`, `GFLOW_CLI_MAX_CREDITS`, MCP `max_credits`) whose shape is not a measured direct key reads Flow's quote in the UI; direct video has no wire quote | These conditions also send a request that would otherwise go direct to the headed UI path: diff --git a/website/docs/MCP.md b/website/docs/MCP.md index cfc8f9634..eb09f6418 100644 --- a/website/docs/MCP.md +++ b/website/docs/MCP.md @@ -114,7 +114,7 @@ An omitted parameter cannot clear that environment default for one MCP call. 400 problem-details envelope), the twin of the CLI's `--browser-visibility`; omitted, the server's `GFLOW_CLI_BROWSER_VISIBILITY` applies. Under `auto`, a measured shape runs with a headless browser that only mints the reCAPTCHA token and is sent over direct HTTP; any other -shape, and any video with a `max_credits` cap, opens a headed browser. The exception is +shape, and every video with a `max_credits` cap, opens a headed browser, except a capped text-to-video of an explicit measured model, duration and resolution, which runs headless (#1554). The exception is `gflow_extend_video` on `flow.google.com`: it drives Flow's UI, which is measured headless, so `auto` runs it headless ([#1554](https://github.com/ffroliva/gflow-cli/issues/1554)), as do the page fallback of `gflow_media_trash` / `gflow_media_restore`, a `gflow_generate_image` call whose only reference