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(remesh): build Manifold so a quad remesh of a real character survives
nirholas25bbecb61763
diff --git a/workers/model-hunyuan3d/test_worker_api.py b/workers/model-hunyuan3d/test_worker_api.pyindex 9b69bf7b4..bd8c391e3 100644--- a/workers/model-hunyuan3d/test_worker_api.py+++ b/workers/model-hunyuan3d/test_worker_api.py@@ -43,10 +43,12 @@ os.environ.setdefault("GCS_BUCKET", "test-bucket")sys.path.insert(0, str(Path(__file__).resolve().parent))+import httpx # noqa: E402from fastapi.testclient import TestClient # noqa: E402from PIL import Image # noqa: E402import app21 # noqa: E402+import image_source # noqa: E402API_KEY = os.environ["API_KEY"]AUTH = {"Authorization": f"Bearer {API_KEY}"}@@ -180,6 +182,133 @@ def test_decode_image_refuses_unsafe_sources():raise AssertionError(f"expected a refusal for {src}")+def test_decode_image_reports_a_dead_url_as_a_caller_fault():+ # Every fetch failure must arrive as ImageSourceError naming the host and+ # the status. Before this, a 403/404 reference image became an opaque+ # `internal error (ref …)` in forge_creations.error, which hid the single+ # most common real cause of a failed generation and made the platform+ # re-dispatch a URL that can never work onto a second GPU lane.+ def dead(src, timeout=None):+ request = httpx.Request("GET", src)+ raise httpx.HTTPStatusError(+ "404", request=request, response=httpx.Response(404, request=request)+ )++ original = image_source.fetch_remote_bytes+ image_source.fetch_remote_bytes = dead+ try:+ app21._decode_image("https://cdn.example/missing.png")+ except image_source.ImageSourceError as exc:+ assert "cdn.example" in str(exc), str(exc)+ assert "404" in str(exc), str(exc)+ else:+ raise AssertionError("expected an ImageSourceError for a 404 source")+ finally:+ image_source.fetch_remote_bytes = original+++def test_image_fetch_retries_a_read_timeout_then_succeeds():+ # A single mid-stream read timeout against a public image host used to fail+ # the whole generation (observed live 2026-08-10, ref 16485b338fc5).+ calls = {"n": 0}+ payload = base64.b64decode(_png_data_uri().split(",", 1)[1])++ def flaky(src, timeout=None):+ calls["n"] += 1+ if calls["n"] == 1:+ raise httpx.ReadTimeout("the read operation timed out")+ return payload++ original = image_source.fetch_remote_bytes+ image_source.fetch_remote_bytes = flaky+ try:+ img = image_source.decode_image(+ "https://cdn.example/ref.png", sleep=lambda _delay: None+ )+ assert calls["n"] == 2, calls["n"]+ assert img.size == (8, 8)+ finally:+ image_source.fetch_remote_bytes = original+++def test_image_fetch_does_not_retry_a_permanent_status():+ # 404/403 will fail identically on every attempt; retrying only adds latency+ # to a failure the caller must fix. 429/503 do get the retry budget.+ calls = {"n": 0}++ def gone(src, timeout=None):+ calls["n"] += 1+ request = httpx.Request("GET", src)+ raise httpx.HTTPStatusError(+ "403", request=request, response=httpx.Response(403, request=request)+ )++ original = image_source.fetch_remote_bytes+ image_source.fetch_remote_bytes = gone+ try:+ try:+ image_source.decode_image("https://cdn.example/private.png", sleep=lambda _d: None)+ except image_source.ImageSourceError:+ pass+ else:+ raise AssertionError("expected an ImageSourceError for a 403 source")+ assert calls["n"] == 1, calls["n"]+ finally:+ image_source.fetch_remote_bytes = original++ for status in (429, 503):+ request = httpx.Request("GET", "https://cdn.example/x.png")+ exc = httpx.HTTPStatusError(+ str(status), request=request, response=httpx.Response(status, request=request)+ )+ assert image_source.is_transient_fetch_error(exc), status+++def test_decode_image_reports_undecodable_bytes_as_a_caller_fault():+ original = image_source.fetch_remote_bytes+ image_source.fetch_remote_bytes = lambda src, timeout=None: b"this is not a png"+ try:+ app21._decode_image("https://cdn.example/not-an-image.png")+ except image_source.ImageSourceError as exc:+ assert "not a decodable image" in str(exc), str(exc)+ else:+ raise AssertionError("expected an ImageSourceError for undecodable bytes")+ finally:+ image_source.fetch_remote_bytes = original+++def test_inference_records_an_image_source_failure_verbatim():+ # The wire contract that makes all of the above visible: a caller-fault+ # failure lands in the task record (and so in forge_creations.error) as its+ # own reason, never as an opaque error ref.+ bucket = RecordingBucket()+ app21._bucket = bucket+ app21._tasks.clear()+ app21._sem = asyncio.Semaphore(1)+ app21._ready = asyncio.Event()+ app21._ready.set()+ original = image_source.fetch_remote_bytes+ image_source.fetch_remote_bytes = lambda src, timeout=None: (_ for _ in ()).throw(+ httpx.HTTPStatusError(+ "404",+ request=httpx.Request("GET", src),+ response=httpx.Response(404, request=httpx.Request("GET", src)),+ )+ )+ try:+ asyncio.run(app21._run_inference("task-img", ["https://cdn.example/missing.png"]))+ task = app21._tasks["task-img"]+ assert task["status"] == "failed", task+ assert "cdn.example" in task["error"], task["error"]+ assert not task["error"].startswith("internal error (ref "), task["error"]+ finally:+ image_source.fetch_remote_bytes = original+ app21._bucket = None+ app21._sem = None+ app21._ready = None+ app21._tasks.clear()++def test_task_records_round_trip_through_the_durable_blob():bucket = RecordingBucket()app21._bucket = bucketdiff --git a/workers/remesh/Dockerfile b/workers/remesh/Dockerfileindex 4e467c158..54096c340 100644--- a/workers/remesh/Dockerfile+++ b/workers/remesh/Dockerfile@@ -19,6 +19,17 @@ RUN git clone --depth 1 --recursive https://github.com/hjwdzh/QuadriFlow /tmp/qu&& install -m 0755 /tmp/quadriflow/build/quadriflow /usr/local/bin/quadriflow \&& rm -rf /tmp/quadriflow+# ── Build Manifold (MIT) from source ─────────────────────────────────────────+# QuadriFlow's own README requires a watertight manifold input and points at this+# tool by the same author to produce one. Without it, a quad remesh of any real+# character export (open at the wrists, neck, and hems) aborts in QuadriFlow's+# index-map solve with "wrong init".+RUN git clone --depth 1 --recursive https://github.com/hjwdzh/Manifold /tmp/manifold \+ && cmake -S /tmp/manifold -B /tmp/manifold/build -DCMAKE_BUILD_TYPE=Release \+ && cmake --build /tmp/manifold/build -j "$(nproc)" \+ && install -m 0755 /tmp/manifold/build/manifold /usr/local/bin/manifold \+ && rm -rf /tmp/manifold+# ── Runtime deps for trimesh / open3d / assimp / usd / Blender ───────────────# The X11/GL libs are for the `bpy` (Blender) module, which links against them# even when running headless for FBX export.diff --git a/workers/remesh/main.py b/workers/remesh/main.pyindex 9f5a77e6a..0aba9e1c5 100644--- a/workers/remesh/main.py+++ b/workers/remesh/main.py@@ -85,6 +85,9 @@ API_KEY = os.environ["API_KEY"]GCS_BUCKET = os.environ["GCS_BUCKET"]MAX_CONCURRENT = int(os.environ.get("MAX_CONCURRENT", "2"))QUADRIFLOW_BIN = os.environ.get("QUADRIFLOW_BIN", "quadriflow")+MANIFOLD_BIN = os.environ.get("MANIFOLD_BIN", "manifold")+MANIFOLD_RESOLUTION = int(os.environ.get("MANIFOLD_RESOLUTION", "50000"))+MANIFOLD_TIMEOUT = int(os.environ.get("MANIFOLD_TIMEOUT", "120"))_bucket: Optional[storage.Bucket] = None_sem: Optional[asyncio.Semaphore] = None@@ -298,6 +301,34 @@ QUADRIFLOW_ATTEMPTS = (QUADRIFLOW_BUDGET_S = 600.0+def _watertight_obj(src: Path, dst: Path) -> bool:+ """Rebuild an OBJ as a watertight manifold with hjwdzh/Manifold (MIT).++ QuadriFlow requires watertight manifold input and ships this tool by the same+ author for the purpose. Real character exports are open at the wrists, neck,+ and hems, and QuadriFlow's index-map solve aborts on them with "wrong init"+ no matter which flow solver it uses. Returns False when the tool is missing+ or produced nothing, so the caller falls back to the raw mesh rather than+ failing outright."""+ binary = shutil.which(MANIFOLD_BIN) or MANIFOLD_BIN+ if shutil.which(MANIFOLD_BIN) is None and not os.path.isfile(binary):+ log.warning("manifold binary not found (%s); using the raw mesh", MANIFOLD_BIN)+ return False+ try:+ proc = subprocess.run(+ [binary, str(src), str(dst), str(MANIFOLD_RESOLUTION)],+ capture_output=True, text=True, timeout=MANIFOLD_TIMEOUT, check=False,+ )+ except subprocess.TimeoutExpired:+ log.warning("manifold rebuild timed out after %ss; using the raw mesh", MANIFOLD_TIMEOUT)+ return False+ if proc.returncode != 0 or not dst.exists() or dst.stat().st_size == 0:+ tail = (proc.stderr or proc.stdout or "").strip().splitlines()[-3:]+ log.warning("manifold rebuild failed (%s); using the raw mesh", " | ".join(tail))+ return False+ return True++def _quad_remesh(mesh, target_faces: int):"""Run QuadriFlow to produce quad-dominant topology.@@ -316,6 +347,14 @@ def _quad_remesh(mesh, target_faces: int):src = Path(tmp) / "in.obj"_write_obj_geometry(mesh, src)+ # An open mesh is rebuilt watertight first; a mesh that is already closed+ # is handed over untouched, since the rebuild is an approximation.+ if not mesh.is_watertight:+ healed = Path(tmp) / "watertight.obj"+ if _watertight_obj(src, healed):+ log.info("quad remesh: rebuilt an open mesh as watertight for QuadriFlow")+ src = healed+deadline = time.monotonic() + QUADRIFLOW_BUDGET_Slast_error = "quad remesh produced no attempts"dst = Nonediff --git a/workers/remesh/test_remesh.py b/workers/remesh/test_remesh.pyindex bef6fef45..bdeeb8b5d 100644--- a/workers/remesh/test_remesh.py+++ b/workers/remesh/test_remesh.py@@ -446,6 +446,24 @@ if shutil.which(remesh.QUADRIFLOW_BIN) or os.path.isfile(remesh.QUADRIFLOW_BIN):).faces) > 0,)+ # QuadriFlow needs watertight input; the rebuild is what makes an open+ # character mesh usable at all, so prove it closes one.+ with tempfile.TemporaryDirectory() as tmp:+ raw = Path(tmp) / "open.obj"+ healed = Path(tmp) / "healed.obj"+ remesh._write_obj_geometry(open_sphere, raw)+ check("fixture for the rebuild is not watertight", not open_sphere.is_watertight)+ if remesh._watertight_obj(raw, healed):+ rebuilt = trimesh.load(str(healed), force="mesh", process=False)+ check(+ "manifold rebuild closes an open mesh",+ rebuilt.is_watertight,+ f"{len(rebuilt.faces)} faces, watertight={rebuilt.is_watertight}",+ )+ check("manifold rebuild keeps geometry", len(rebuilt.faces) > 0)+ else:+ skip("manifold rebuild", f"binary not found ({remesh.MANIFOLD_BIN})")+check("the solver ladder starts with minimum-cost flow and ends bare",remesh.QUADRIFLOW_ATTEMPTS[0] == ("-mcf", "-sharp")diff --git a/workers/stylize/test_stylize.py b/workers/stylize/test_stylize.pyindex 51f0cdf67..f6f62af5b 100644--- a/workers/stylize/test_stylize.py+++ b/workers/stylize/test_stylize.py@@ -103,6 +103,53 @@ for label, header in (("a missing", None), ("an empty", ""), ("a non-bearer", "tmain._require_api_key(f"Bearer {main.API_KEY}")check("the configured key is accepted", True)+# The helper above is only half the contract: the routes have to declare the+# header optional so it runs at all. Declared required, FastAPI answers a+# credential-less caller with a 422 validation dump before the handler is+# reached, which is what the deployed image did until this was fixed. Drive the+# real app so a regression to Header(...) is caught here and not in production.+from fastapi.testclient import TestClient # noqa: E402++# Not used as a context manager on purpose: entering one runs the lifespan,+# which builds a GCS client this suite deliberately never touches.+client = TestClient(main.app)+JOB = {"mesh": "https://example.com/a.glb", "style": "voxel"}++check(+ "POST /process without a header is 401, not a 422 validation dump",+ client.post("/process", json=JOB).status_code == 401,+ str(client.post("/process", json=JOB).status_code),+)+check(+ "GET /tasks without a header is 401",+ client.get("/tasks/nope").status_code == 401,+ str(client.get("/tasks/nope").status_code),+)+check(+ "a wrong key on /process is 401",+ client.post("/process", json=JOB, headers={"authorization": "Bearer nope"}).status_code == 401,+)+for public in ("/styles", "/health"):+ check(+ f"{public} stays public",+ client.get(public).status_code == 200,+ str(client.get(public).status_code),+ )+check(+ "an authenticated request with a bad style is still a 422",+ client.post(+ "/process",+ json={"mesh": "https://example.com/a.glb", "style": "hologram"},+ headers={"authorization": f"Bearer {main.API_KEY}"},+ ).status_code == 422,+)+check(+ "an unknown task id is 404 for an authenticated caller",+ client.get(+ "/tasks/nope", headers={"authorization": f"Bearer {main.API_KEY}"}+ ).status_code == 404,+)+# ── task tracking ───────────────────────────────────────────────────────────────main._tasks.clear()