Skip to content

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.

docs(segment): document the merge-pass rewrite, durable tasks, and the real deploy command

nirholas6d54f24f6d1d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 68ee56b18..674101bfd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr
- **Photo to 3D no longer fails when the image host has one slow moment**: Turning a photo into a 3D model starts by downloading the image you pointed at. If that download stalled for even a moment, the whole generation failed and you had to start over. The image is now fetched up to three times with a growing pause between tries, so a single slow moment costs a couple of seconds instead of the job. When an image genuinely cannot be used, the failure now names the reason and the host (unreachable, HTTP 404, not a decodable image) instead of an opaque error code, so you can tell a broken link from a hiccup. (`/create`) `[fix, improvement]`
- **Sending your agent a task on its live screen actually works again**: The agent screen lets you queue a task for your own agent and watch it browse the web to carry it out. None of that path worked. Queuing a task failed on the server because it looked your agent up in a table that does not exist, so the browser worker polled forever and never saw a task. The worker was broken twice over on its own side too: it read the agent's id from the wrong place, so every frame it published was rejected before it reached the stream, and it drove the browser through a method that moved in version 3 of the automation library, so typing, clicking, reading a page, and even taking a screenshot all failed. All three are fixed and the worker now runs end to end: it picks up your task, navigates, narrates each step, and streams real screenshots. The same bad lookup also blocked grinding a vanity wallet address for an agent, which is fixed as well. (`/agent-screen`) `[fix]`
- **Sniper positions that exit on a dead market now close properly**: When a sniped coin's market went quiet, the worker sold the bag on-chain but could not record the close, because the database did not recognise the reason it gave. The sale had already happened, so the position was reset and retried forever: it never booked its profit or loss and it kept holding one of the agent's position slots. Those exits now record correctly, the freed slots go back to the agent, and the trade card names the exit in plain language instead of leaving it blank. `[fix]`
+- **Splitting a model into parts finishes in seconds instead of hours**: Parts Studio splits a 3D model into named, separately editable pieces. On detailed models that split could take hours: the step that merges tiny fragments back together got dramatically slower as the fragment count grew, and the longest real jobs ran close to four hours before returning anything, sometimes exhausting the service's memory and taking other people's jobs down with it. That step has been rebuilt and now runs hundreds of times faster while producing exactly the same parts, so a detailed model splits in seconds. Three related fixes came with it: a finished split is no longer lost when a network hiccup interrupts the upload, results stay available if the service restarts while you are waiting, and a rejected request now tells you why (for example, which part names actually exist) instead of showing a generic error. (`/segment`) `[fix, improvement, infra]`
- **Stylizing a model no longer throws away the finished result over a momentary network hiccup, and plain models keep their intended color**: The stylize filters (voxel, brick, voronoi shell, low-poly) rebuild your model and then upload the result to storage. A brief interruption on that last upload step was not retried, so roughly once a week a job that had already done all its work was reported to you as failed. That upload now retries by itself. Two more repairs ride along: a model that carries no colors of its own now comes back in the soft neutral tone the filters were designed around, instead of the flat gray the geometry library hands out by default, and a model with no size at all is refused with a clear reason rather than returning a file with nothing visible in it. (`/forge`) `[fix, improvement]`
- **The 3D forge now tells a broken GPU worker apart from a healthy one, and stops routing your generation at it**: Our own Hunyuan3D image-to-3D workers answer web requests within seconds of starting, then spend several minutes loading multi-gigabyte model weights in the background. The platform checked only whether a worker answered at all, so a worker that had answered but then failed to load its model looked exactly as healthy as a working one: the forge status page showed it green and generations kept being sent to it. Both the status page and the routing that picks a backend now read the worker's real readiness, so a worker that cannot generate is reported as down and skipped, and one that is still warming up is marked as such instead of promising a fast turnaround it cannot deliver. (`/forge`) `[fix, infra]`
- **The market anchor keeps real headlines on air when its intel feed goes down**: The newsroom anchor on the agent screen builds every bulletin from a paid narrative-intel feed, and when that subscription started being refused the anchor was left reading a price-only bulletin with nothing to say. It now falls back to the platform's own aggregated news feed, narrowed to major publishers, so the anchor still leads with real, attributed headlines. The fallback only fires when the primary feed comes back empty, and the anchor still refuses to name any ticker other than $THREE. (`/agent-screen`) `[fix, improvement]`
diff --git a/data/changelog.json b/data/changelog.json
index 0e00d0e13..575af427b 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,17 @@
{
"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-08-11",
+ "title": "Splitting a model into parts finishes in seconds instead of hours",
+ "summary": "Parts Studio splits a 3D model into named, separately editable pieces. On detailed models that split could take hours: the step that merges tiny fragments back together got dramatically slower as the fragment count grew, and the longest real jobs ran close to four hours before returning anything, sometimes exhausting the service's memory and taking other people's jobs down with it. That step has been rebuilt and now runs hundreds of times faster while producing exactly the same parts, so a detailed model splits in seconds. Three related fixes came with it: a finished split is no longer lost when a network hiccup interrupts the upload, results stay available if the service restarts while you are waiting, and a rejected request now tells you why (for example, which part names actually exist) instead of showing a generic error.",
+ "tags": [
+ "fix",
+ "improvement",
+ "infra"
+ ],
+ "link": "/segment"
+ },
{
"date": "2026-08-11",
"title": "Sniper positions that exit on a dead market now close properly",
diff --git a/prompts/swarm-100/worker-segment.md b/prompts/swarm-100/worker-segment.md
deleted file mode 100644
index 9c0abe689..000000000
--- a/prompts/swarm-100/worker-segment.md
+++ /dev/null
@@ -1,98 +0,0 @@
-# Worker audit: workers/segment
-
-How to run: paste this file's repo path into a fresh Claude Code chat in this
-repository and say "run this work order". This file is fully self-contained:
-it depends on no other prompt file anywhere. If neighboring files in
-prompts/swarm-100/ are gone, that work is done; if present, ignore them.
-Every claim below rots; step 0 re-measures, and what you measure wins.
-
-## Operating clause (binding)
-
-- Read CLAUDE.md first. Its rules override everything, including this file.
-- Finish 100% in this session. Never end the turn with a question, an option
- list, or an unexecuted plan. A judgment call goes in one line of the final
- report; it never becomes a question that halts work.
-- The only permitted stops are the CLAUDE.md stop-and-ask gates: spending real
- funds or any irreversible on-chain write, git push or a production deploy,
- committing content that references a crypto project other than $THREE, and
- destroying unrecoverable data.
-- No mocks, no fake data, no placeholder stubs, no unfinished-work markers, no
- commented-out code. Real APIs and real integrations only.
-- The em-dash and en-dash characters are banned in everything you write.
-- Concurrent agents share this worktree: stage explicit paths only (never a
- bare add-everything), and commit finished work promptly.
-- Before committing, run: npm run check:rules -- --paths <files you touched>.
- It must exit 0.
-
-## Step 0: re-derive the current state
-
-1. Read workers/segment/README.md and its build config (cloudbuild.yaml,
- Dockerfile, package.json; whichever exist).
-2. Is it deployed?
-
- export PATH="$HOME/google-cloud-sdk/bin:$PATH"
- gcloud run services list --project aerial-vehicle-466722-p5 --region us-central1 | grep -i "segment" || echo "not deployed as its own service"
-
-3. If deployed: which commit is the running revision built from, and does main
- contain fixes it has not picked up? A fix in main can sit undeployed for
- days; never call a bug unfixed without checking the running revision.
-4. Logs, last 24h, if deployed:
-
- gcloud logging read 'resource.type="cloud_run_revision" resource.labels.service_name="<service name from step 2>"' --freshness=24h --limit 100 --project aerial-vehicle-466722-p5
-
-## Task: bring this worker to verified-healthy
-
-1. README accuracy: what it does, how to run it, its inputs and outputs. Fix
- every stale claim; a README that lies fails the audit.
-2. Build it the way its own config says. The build must succeed from a clean
- checkout of this worktree. Model workers that need weights stage them from
- gs://three-ws-model-weights (staging weights is part of the job, not a
- blocker).
-3. Run its tests; add a smoke test if it has none that proves its core path.
-4. If deployed: last 24h of logs free of unhandled errors; fix root causes in
- code and commit. Redeploying is owner-gated: prepare everything so the
- deploy is one command and say so in the report.
-5. If not deployed by design: its README must state how and where it runs, and
- that path must be verified locally.
-
-## Definition of done
-
-- [ ] Build succeeds from this worktree with the worker's own config.
-- [ ] Tests pass, including at least one core-path smoke test.
-- [ ] README verified accurate against the code.
-- [ ] If deployed: running revision identified, 24h logs clean or root causes
- fixed and committed (deploy itself flagged for the owner).
-- [ ] npm run check:rules -- --paths <touched files> exits 0.
-
-## Never blocked
-
-| Blocker | Resolution (act, do not ask) |
-|---|---|
-| Missing env var or credential | Check .env and .env.local, then the Cloud Run service env, then Secret Manager (the CLAUDE.md self-unblock playbook has the exact commands). If it truly exists nowhere, wire the code fully behind the env var, prove the wiring with a dry run, and name the single missing var in the report. |
-| gcloud not on PATH | Run: export PATH="$HOME/google-cloud-sdk/bin:$PATH" |
-| Dev server port 3000 busy | Another agent may be serving this repo; probe it and reuse if so. Otherwise start your own on a free port: npx vite --port 3101 |
-| Playwright browser missing | npx playwright install chromium |
-| A surface needs a signed-in user | Register a fresh account through the real /register flow against the real API and use it. Never mock the session. |
-| A defect sits in code you did not touch | Fix it if it blocks a Definition of done line (root cause it, never mask it). Otherwise note it in the report and continue. |
-| An unrelated test is red | Same rule. Never pipe npm test through tail; it masks exit codes. |
-
-## Close out (required)
-
-1. Verify every Definition of done line with the actual command output in
- front of you. Never claim a line you did not verify.
-2. Commit with explicit paths and a subject that describes the diff (house
- style: type(scope): what changed and why a reader cares).
-3. Delete this prompt file in that same commit:
-
- git rm prompts/swarm-100/worker-segment.md
-
- The shrinking directory is this campaign's only progress ledger; there is
- no progress log to update.
-4. Final report: what step 0 measured, what changed (file list), evidence per
- Definition of done line, and any one-line judgment calls. No trailing
- questions, no unexecuted plans.
-
-If a line genuinely cannot pass inside this session (an external party must
-respond, or an owner-gated action is the final step), finish everything else,
-leave this file in place, and state exactly which line remains and who owns
-it. Never delete this file on a partial.
diff --git a/public/changelog.json b/public/changelog.json
index 341d5a63e..cf66bd931 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-08-11T02:02:28.997Z",
+ "generated_at": "2026-08-11T02:04:43.813Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
@@ -123,6 +123,18 @@
"fix"
]
},
+ {
+ "date": "2026-08-11",
+ "type": "update",
+ "title": "Splitting a model into parts finishes in seconds instead of hours",
+ "summary": "Parts Studio splits a 3D model into named, separately editable pieces. On detailed models that split could take hours: the step that merges tiny fragments back together got dramatically slower as the fragment count grew, and the longest real jobs ran close to four hours before returning anything, sometimes exhausting the service's memory and taking other people's jobs down with it. That step has been rebuilt and now runs hundreds of times faster while producing exactly the same parts, so a detailed model splits in seconds. Three related fixes came with it: a finished split is no longer lost when a network hiccup interrupts the upload, results stay available if the service restarts while you are waiting, and a rejected request now tells you why (for example, which part names actually exist) instead of showing a generic error.",
+ "link": "/segment",
+ "tags": [
+ "fix",
+ "improvement",
+ "infra"
+ ]
+ },
{
"date": "2026-08-11",
"type": "update",
diff --git a/public/changelog.xml b/public/changelog.xml
index a57de17ab..850a75d72 100644
--- a/public/changelog.xml
+++ b/public/changelog.xml
@@ -94,6 +94,14 @@
<category>fix</category>
<description>When a sniped coin's market went quiet, the worker sold the bag on-chain but could not record the close, because the database did not recognise the reason it gave. The sale had already happened, so the position was reset and retried forever: it never booked its profit or loss and it kept holding one of the agent's position slots. Those exits now record correctly, the freed slots go back to the agent, and the trade card names the exit in plain language instead of leaving it blank.</description>
</item>
+ <item>
+ <title>Splitting a model into parts finishes in seconds instead of hours</title>
+ <link>https://three.ws/segment</link>
+ <guid isPermaLink="false">2026-08-11:Splitting a model into parts finishes in seconds instead of hours</guid>
+ <pubDate>Tue, 11 Aug 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>Parts Studio splits a 3D model into named, separately editable pieces. On detailed models that split could take hours: the step that merges tiny fragments back together got dramatically slower as the fragment count grew, and the longest real jobs ran close to four hours before returning anything, sometimes exhausting the service's memory and taking other people's jobs down with it. That step has been rebuilt and now runs hundreds of times faster while producing exactly the same parts, so a detailed model splits in seconds. Three related fixes came with it: a finished split is no longer lost when a network hiccup interrupts the upload, results stay available if the service restarts while you are waiting, and a rejected request now tells you why (for example, which part names actually exist) instead of showing a generic error.</description>
+ </item>
<item>
<title>Stylizing a model no longer throws away the finished result over a momentary network hiccup, and plain models keep their intended color</title>
<link>https://three.ws/forge</link>
diff --git a/public/features.json b/public/features.json
index 3b7c6fba2..ce0326e9d 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-08-11T02:02:28.989Z",
+ "generated_at": "2026-08-11T02:04:43.801Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/workers/segment/README.md b/workers/segment/README.md
index 86ef1cb0f..e02015452 100644
--- a/workers/segment/README.md
+++ b/workers/segment/README.md
@@ -36,33 +36,74 @@ Supported input formats: `.glb`, `.gltf`, `.obj`, `.stl`, `.ply`, `.fbx`,
`worker_security.fetch_remote_bytes` (https-only, private/loopback/metadata IPs
rejected, redirects re-validated per hop).
+The parts are a strict **partition** of the input: same faces, redistributed,
+never repaired and never invented. (trimesh patches holes while splitting by
+default, which grew a real 17031-face forge model to 17050 faces across its
+parts and made the manifest contradict its own `source_faces`.)
+
+## Cost
+
+Measured on this repo's dev machine, whole path, load through GLB export, one
+job at a time:
+
+| Faces in | Wall clock | Peak RSS |
+|---|---|---|
+| 20 k | 1.5 s | 122 MB |
+| 82 k | 6.8 s | 193 MB |
+| 328 k | 23 s | 476 MB |
+| 1.3 M | 81 s | 1.5 GB |
+
+Roughly 1.1 KB of peak memory per input face, so the 128 MiB input cap and
+`MAX_CONCURRENT=2` sit comfortably inside the 16 GiB instance. `JOB_TIMEOUT_S`
+bounds the tail.
+
+These numbers are the point of the 2026-08-11 merge-pass rewrite. The previous
+implementation rebuilt the entire label-adjacency map and rescanned the whole
+label array on *every single merge*, which is cubic in the number of crease
+regions: a 20 k-face mesh took **328 s** in the merge pass alone, and real jobs
+in production ran for **2.9 to 4 hours** while repeatedly OOM-killing the 16 GiB
+instance. The rewrite keeps regions in a union-find with incrementally
+maintained neighbour sets and one lazily-invalidated min-heap, applies exactly
+the same merge policy, and writes the label array once at the end. Verified
+identical output on 20 of 20 mesh/parameter combinations against the original
+implementation.
+
## Files
| File | Role |
|------|------|
-| `main.py` | FastAPI app: request validation, async job queue (`MAX_CONCURRENT` semaphore), GCS upload of the GLB + manifest, task-status store. |
+| `main.py` | FastAPI app: request validation, async job queue (`MAX_CONCURRENT` semaphore), GCS upload of the GLB + manifest, durable task records. |
| `segment_core.py` | The geometry engine: `load_concatenated`, `segment`, `build_scene`, `manifest`. Trimesh + numpy + scipy. |
-| `worker_security.py` | Shared bearer-auth + SSRF-hardened fetch + opaque error helper. Byte-identical copy across all workers — keep it in sync when editing. |
-| `Dockerfile` | `python:3.11-slim` + native libs (`libgl1`, `libassimp5`, `libopenblas`); serves via `uvicorn` on port 8080. |
-| `cloudbuild.yaml` | Cloud Build → Artifact Registry → Cloud Run deploy. |
+| `test_segment_core.py` | Core-path tests for the geometry engine. No GCS, no network. Run as a Docker build gate. |
+| `worker_security.py` | Shared bearer-auth + SSRF-hardened fetch + opaque error helper. Byte-identical copy across all workers, so keep it in sync when editing. |
+| `Dockerfile` | `python:3.11-slim` + native libs (`libgl1`, `libassimp5`, `libopenblas`); runs the test gate, then serves via `uvicorn` on port 8080. |
+| `cloudbuild.yaml` | Cloud Build to Artifact Registry to Cloud Run deploy. |
## How it ships
Built and deployed by **Cloud Build** to **Google Cloud Run**:
- Service: **`segment-service`**, region **`us-central1`**
-- Runs on CPU only — `--cpu=8 --memory=16Gi`, no GPU — scale-to-zero
- (`min-instances=0`, `max-instances=3`), 300 s request timeout.
+- CPU only (`--cpu=8 --memory=16Gi`, no GPU), **kept warm** at
+ `min-instances=1` / `max-instances=3`, 300 s request timeout. It is not
+ scale-to-zero: Parts Studio calls it the moment a user asks to split a model,
+ and a cold start is a visible stall.
- Service account `avatar-reconstruction-sa`; `API_KEY` is mounted from the
- `avatar-reconstruction-key` Secret Manager secret — the **same shared bearer
+ `avatar-reconstruction-key` Secret Manager secret, the **same shared bearer
secret** every model worker checks (`GCP_RECONSTRUCTION_KEY` on the platform
side).
```bash
# from repo root, deploy the current tree
-gcloud builds submit --config workers/segment/cloudbuild.yaml .
+gcloud builds submit --config workers/segment/cloudbuild.yaml \
+ --region us-central1 --project aerial-vehicle-466722-p5 \
+ --substitutions=SHORT_SHA=manual$(date +%s) .
```
+`SHORT_SHA` is required on a manual submit: the config tags the image with it,
+and an unsubstituted tag fails the build. The build runs `test_segment_core.py`
+as a gate, so a regressed merge pass never reaches a deployed image.
+
The platform wires it in through `api/_providers/gcp.js` (`segment` mode): set
**`GCP_SEGMENT_URL`** to this service's Cloud Run URL and **`GCP_RECONSTRUCTION_KEY`**
to the shared bearer secret. Read the URL after deploy with:
@@ -142,8 +183,25 @@ Response: `{ "task_id": "<uuid>", "status": "queued" }`.
```
`result_url`/`manifest_url` and the enriched fields appear once `status` is
-`done`. On failure, `error` carries an opaque, correlation-id-tagged message
-(the full traceback is logged server-side only, never returned).
+`done`.
+
+**Task records are durable.** Every status change is mirrored to
+`segment/<id>.task.json` in `GCS_BUCKET`, and a poll for an id this instance
+does not know reads that record. Task state used to live only in the
+submitting instance's memory, so with `min-instances=1`/`max=3` a poll routed
+to a sibling, or arriving after a restart, returned a bare `404` and the caller
+reported a phantom failure. Verified by polling a completed job against a
+freshly started instance: it answers `done` with the full manifest, while an id
+that never existed still `404`s.
+
+**Failures say what went wrong when they safely can.** A caller's mistake
+(unknown `only_part`, a mesh with no triangles, an SSRF-refused URL) returns
+the real reason, e.g. `part 'part_99' not found. Available: part_01 (upper-back),
+...` or `refused to fetch mesh: host resolves to a disallowed address:
+169.254.169.254`. Anything unexpected still returns an opaque,
+correlation-id-tagged message with the traceback logged server-side only. The
+split is by exception type (`SegmentInputError` / `SegmentTimeout` are echoed,
+everything else is not), so a library-internal message can never leak.
### `GET /health` → `200`
@@ -153,9 +211,11 @@ Response: `{ "task_id": "<uuid>", "status": "queued" }`.
| Var | Required | Default | Meaning |
|-----|----------|---------|---------|
-| `API_KEY` | ✅ | — | Bearer secret checked on `/segment` and `/tasks` (constant-time). |
-| `GCS_BUCKET` | ✅ | — | Output bucket for `segment/<id>.glb` + `segment/<id>.parts.json`. Deployed as `three-ws-avatar-reconstructions`. |
+| `API_KEY` | ✅ | n/a | Bearer secret checked on `/segment` and `/tasks` (constant-time). |
+| `GCS_BUCKET` | ✅ | n/a | Output bucket for `segment/<id>.glb`, `segment/<id>.parts.json`, and `segment/<id>.task.json`. Deployed as `three-ws-avatar-reconstructions`. |
| `MAX_CONCURRENT` | | `2` | In-process semaphore bounding concurrent segmentation jobs. |
+| `JOB_TIMEOUT_S` | | `600` | Wall-clock ceiling per job, covering the mesh fetch and the segmentation. Exceeding it fails the task instead of holding a slot. |
+| `TASK_TTL_S` | | `3600` | How long a finished task stays in instance memory. The durable GCS record outlives it. |
## Run locally
@@ -185,6 +245,31 @@ curl -s http://localhost:8080/tasks/<task_id> \
-H "Authorization: Bearer $API_KEY" | jq .
```
-GCS uploads need real credentials — run with Application Default Credentials
+GCS uploads need real credentials: run with Application Default Credentials
(`gcloud auth application-default login`) pointed at a project that can write
`GCS_BUCKET`. There is no mock storage path.
+
+Uploads retry on transient transport faults. A single
+`SSLEOFError: UNEXPECTED_EOF_WHILE_READING` from `storage.googleapis.com` used
+to discard an otherwise finished segmentation, because the client library
+treats an upload as non-idempotent and does not retry it by default. Every blob
+is named after a fresh uuid, so replaying the write is safe.
+
+## Tests
+
+```bash
+python3 workers/segment/test_segment_core.py
+```
+
+80 checks over the geometry engine: loading and scene concatenation, connected
+and crease segmentation, the `max_parts` cap, the face-partition property, run
+to run determinism, the time budget, GLB node naming, and the manifest shape.
+No GCS, no network, no GPU. The Docker build runs it, so a regression fails the
+image rather than the deploy.
+
+Two of them are the load-bearing ones: a **performance** check that fails if the
+merge pass regresses toward its pre-2026-08-11 cost, and a **determinism** check
+that the same mesh segments identically twice. Determinism is not cosmetic here:
+the merge picks the largest neighbour, and resolving ties by Python set
+iteration order made the same model produce differently grouped parts between
+runs. Ties now break on the lowest label.