Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(garment-forge): tell a refused prompt apart from an empty draw
nirholas83ef3b2d4758
diff --git a/workers/garment-forge/README.md b/workers/garment-forge/README.mdindex fc7c9f858..54e249649 100644--- a/workers/garment-forge/README.md+++ b/workers/garment-forge/README.md@@ -49,14 +49,29 @@ pure glTF work in between:A-pose, front view, plain background. Reference quality drives meshquality; the resolution is held at 2K.- The model sometimes answers `200` carrying no image at all (a safety or- recitation filter, or an empty candidate under load). That is not a- transport failure, so the HTTP retry has nothing to retry, and a single such- response used to kill a job that was already queued. Generation is- stochastic, so the stage now re-rolls the same prompt up to- `VERTEX_IMAGE_ATTEMPTS` times (default 3) and only fails once the budget is- spent, reporting the last `finishReason`. Pinned by- `test_reference_image.py`, which runs as a Docker build gate.+ The model can answer `200` carrying no image at all. That is not a transport+ failure, so the HTTP retry has nothing to retry, and it used to kill a queued+ job outright. There are two distinct causes and the stage now tells them+ apart:++ - **Empty draw** (stochastic): candidates came back without image bytes.+ The same prompt usually succeeds on the next roll, so the stage re-rolls+ up to `VERTEX_IMAGE_ATTEMPTS` times (default 3) before failing with the+ last `finishReason`.+ - **Refused prompt** (deterministic): the safety classifier rejected the+ wording, so Vertex returns **no candidates at all** and puts the reason in+ `promptFeedback.blockReason` — nowhere near `candidates[].finishReason`.+ Re-rolling is pointless (measured: refused 3 of 3), so the job fails+ immediately with the block reason, the slot, and an instruction to+ rephrase. Reading only `finishReason` is what made these look like+ transient failures on 2026-07-29; the message was a bare "no image data"+ with no reason attached.++ Prompt wording matters more than it looks: "tan suede desert boots with+ crepe soles" is refused every time while "black leather ankle boots with a+ low block heel" renders fine. If a garment will not generate, rephrase+ before investigating anything else. Pinned by `test_reference_image.py`,+ which runs as a Docker build gate.2. **Mesh** (`pipeline.generate_mesh`): the image goes through the deployedimage→3D failover chain, first healthy rung wins:`model-hunyuan3d-21-rtx` (warm primary, full PBR: albedo +diff --git a/workers/garment-forge/pipeline.py b/workers/garment-forge/pipeline.pyindex 4b0b18bef..edaab166b 100644--- a/workers/garment-forge/pipeline.py+++ b/workers/garment-forge/pipeline.py@@ -123,9 +123,16 @@ def generate_reference_image(prompt: str, slot: str) -> tuple[bytes, str]:headers = {"authorization": f"Bearer {_access_token()}","content-type": "application/json"}- def _attempt() -> tuple[bytes | None, str | None]:- """One generation call. Returns (image_bytes, None) on success, or- (None, finish_reason) when the model answered 200 with no image."""+ def _attempt() -> tuple[bytes | None, str | None, bool]:+ """One generation call.++ Returns `(image_bytes, None, False)` on success, or+ `(None, reason, prompt_blocked)` when the model answered 200 with no+ image. `prompt_blocked` separates the two very different no-image+ cases: a REFUSED PROMPT (deterministic — the safety classifier rejects+ this wording every time) from an EMPTY DRAW (stochastic — the same+ prompt usually succeeds on the next roll).+ """with httpx.Client(timeout=120) as client:res = _post_with_retry(client, endpoint, json_body=body, headers=headers)if res.status_code == 400:@@ -134,27 +141,45 @@ def generate_reference_image(prompt: str, slot: str) -> tuple[bytes, str]:res = _post_with_retry(client, endpoint, json_body=body, headers=headers)res.raise_for_status()data = res.json()+ # A blocked PROMPT produces no candidates at all, so the reason lives in+ # promptFeedback, not in candidates[0].finishReason. Reading only the+ # latter reported every such block as a bare "no image data" with no+ # reason attached, which is what made the 2026-07-29 batch failures+ # look transient when they were not.+ feedback = data.get("promptFeedback") or {}+ block = feedback.get("blockReason")+ if block:+ detail = feedback.get("blockReasonMessage") or ""+ return None, f"prompt blocked: {block}{f' ({detail})' if detail else ''}", Truecandidate = (data.get("candidates") or [{}])[0]parts = candidate.get("content", {}).get("parts", [])img_part = next((p for p in parts if p.get("inlineData", {}).get("data")), None)if not img_part:- return None, candidate.get("finishReason") or "no finishReason"- return base64.b64decode(img_part["inlineData"]["data"]), None+ return None, candidate.get("finishReason") or "no finishReason", False+ return base64.b64decode(img_part["inlineData"]["data"]), None, False# A 200 carrying no image is a DIFFERENT failure from the transport errors# _post_with_retry covers: the request succeeded and the model simply- # declined to draw this time (a safety/recitation filter, or an empty- # candidate under load). Image generation is stochastic, so re-rolling the- # same prompt usually succeeds — and without a re-roll one such response+ # declined to draw. Image generation is stochastic, so re-rolling the same+ # prompt usually succeeds — and without a re-roll one such response# permanently loses a job that has already been queued, paid for in GPU# time downstream, and counted against the batch.last_reason = Nonefor attempt in range(_IMAGE_ATTEMPTS):- image, last_reason = _attempt()+ image, last_reason, prompt_blocked = _attempt()if image is not None:if attempt:log.info("reference image took %d attempt(s) (prior: %s)", attempt + 1, last_reason)return image, f"vertex-ai/{VERTEX_MODEL}"+ if prompt_blocked:+ # Deterministic: the classifier rejects this wording, so every+ # further roll costs a call and ~10s to be refused identically.+ # Fail immediately with wording the caller can act on.+ raise RuntimeError(+ f"reference image refused for slot '{slot}': {last_reason}. "+ "The safety classifier rejects this prompt wording; rephrase the "+ "garment description and resubmit."+ )if attempt + 1 >= _IMAGE_ATTEMPTS:break # budget spent; fall through to the raise belowlog.warning("Vertex returned no image data (finishReason: %s); re-rolling "diff --git a/workers/garment-forge/test_reference_image.py b/workers/garment-forge/test_reference_image.pyindex 812fab367..8edff8f3f 100644--- a/workers/garment-forge/test_reference_image.py+++ b/workers/garment-forge/test_reference_image.py@@ -120,6 +120,16 @@ def empty_payload(reason: str | None = "IMAGE_SAFETY"):return {"candidates": [candidate]}+def blocked_payload(reason: str = "SAFETY", message: str | None = "The prompt is blocked due to safety"):+ """A refused PROMPT: Vertex returns no candidates at all and puts the reason+ in promptFeedback. Observed live for "tan suede desert boots with crepe+ soles", which was refused identically on 3 of 3 probes."""+ feedback: dict = {"blockReason": reason}+ if message is not None:+ feedback["blockReasonMessage"] = message+ return {"promptFeedback": feedback, "usageMetadata": {"promptTokenCount": 69}}++def run(responses: list[dict], attempts: int = 3):"""Drive generate_reference_image against a scripted response sequence.Returns (result_or_exception, number_of_calls_made)."""@@ -186,4 +196,26 @@ check("a missing finishReason degrades to a readable message",result, n = run([empty_payload()], attempts=1)check("attempts=1 disables the re-roll", isinstance(result, RuntimeError) and n == 1)+# A REFUSED PROMPT is deterministic, so re-rolling it only burns calls and time.+result, n = run([blocked_payload()])+check("a blocked prompt fails immediately, without re-rolling", n == 1)+check("a blocked prompt still raises", isinstance(result, RuntimeError))+check("the error names the block reason", "SAFETY" in str(result))+check("the error carries the upstream message",+ "blocked due to safety" in str(result))+check("the error names the slot so the caller knows what to rephrase",+ "outerwear" in str(result))+check("the error tells the caller what to do", "rephrase" in str(result).lower())++# promptFeedback without a message must not crash the error path.+result, n = run([blocked_payload("PROHIBITED_CONTENT", None)])+check("a block with no message is still readable",+ isinstance(result, RuntimeError) and "PROHIBITED_CONTENT" in str(result) and n == 1)++# A prompt block found on a LATER roll must also stop the loop there.+result, n = run([empty_payload(), blocked_payload()])+check("a block discovered mid-retry stops immediately", n == 2)+check("that block reports as a block, not as budget exhaustion",+ isinstance(result, RuntimeError) and "SAFETY" in str(result))+print(f"\nall {PASS} checks passed")