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(cad): flag multi-body parts, keep slider rejections out of the console, and name the crashing line on kernel threads
nirholas62dea18ca594
diff --git a/api/_lib/cad/prompt.js b/api/_lib/cad/prompt.jsindex 203e43a4a..270701000 100644--- a/api/_lib/cad/prompt.js+++ b/api/_lib/cad/prompt.js@@ -62,6 +62,8 @@ STANDARD PARTS (bd_warehouse 0.4): use these instead of modeling gears, threads- from bd_warehouse.fastener import HexNut, SocketHeadCapScrew, PlainWasher, ClearanceHole, TapHole: HexNut("M8-1.25", fastener_type="iso4032"), SocketHeadCapScrew("M6-1", length=20, fastener_type="iso4762"), PlainWasher("M6", fastener_type="iso7089"). Sizes are strings such as "M3-0.5", "M4-0.7", "M5-0.8", "M6-1", "M8-1.25", "M10-1.5".- from bd_warehouse.bearing import SingleRowDeepGrooveBallBearing: SingleRowDeepGrooveBallBearing("M8-22-7", "SKT").- Standard parts already have their real dimensions; still expose 3 to 8 parameters for whatever you build around them (count, thickness, bore, spacing).+- Inside a BuildPart, bd_warehouse objects are added to the part automatically, exactly like Box or Cylinder. Never also call add() on them, or the part gets a duplicate body.+- bd_warehouse parts are CENTERED on Z by default. Pass align=(Align.CENTER, Align.CENTER, Align.MIN) so the part sits on Z = 0, then features placed at Z = thickness (hubs, bosses) actually touch it.EXACT SIGNATURES AND PITFALLS (these are the mistakes that fail builds)- 2D shapes (Rectangle, RectangleRounded, Circle, Ellipse, RegularPolygon, SlotOverall, SlotCenterToCenter, Polygon, Text, Trapezoid) exist ONLY inside BuildSketch. 3D primitives (Box, Cylinder, Sphere, Cone, Torus, Hole...) exist ONLY inside BuildPart.diff --git a/api/cad.js b/api/cad.jsindex ce2e44294..81d6f063a 100644--- a/api/cad.js+++ b/api/cad.js@@ -14,7 +14,8 @@* POST /api/cad { action:'rebuild', id, values }* Rebuilds a saved design's own program with new parameter values (no* model involved). Each distinct value set is cached, so a shared- * configuration link builds once. → { variant }+ * configuration link builds once. → { ok:true, variant, cached }, or+ * { ok:false, message, buildError } when the kernel rejects the values.** GET /api/cad?id=<uuid>[&v=<key>] → { design, lineage, variant? }* GET /api/cad?id=<uuid>&format=py[&v=] → the program as a .py download@@ -190,9 +191,14 @@ async function handleRebuild(req, res, body) {if (!rl.success) throw Object.assign(new CadForgeError('rate_limited', 'Rebuilding too fast. Give it a moment.', 429), { rl });},});- return json(res, 200, { variant, cached });+ return json(res, 200, { ok: true, variant, cached });} catch (err) {if (err?.rl) return rateLimited(res, err.rl, err.message);+ // The kernel refusing a value set is an answer, not a failed request:+ // the page shows the reason beside the sliders.+ if (err instanceof CadForgeError && err.code === 'rebuild_failed') {+ return json(res, 200, { ok: false, error: err.code, message: err.message, buildError: err.detail || null });+ }return sendError(res, err, null);}}diff --git a/docs/cad-forge.md b/docs/cad-forge.mdindex c9ee098ae..c41368fd8 100644--- a/docs/cad-forge.md+++ b/docs/cad-forge.md@@ -128,7 +128,7 @@ curl -s https://three.ws/api/cad -H 'content-type: application/json' \{ "action": "rebuild", "id": "<design id>", "values": { "WIDTH": 120 } }```-Returns `{ "variant": { "key", "values", "metrics", "files", "adjustments", "url" }, "cached": false }`. Values are clamped to each parameter's range and snapped to its step. A value set that has been built before returns instantly with `cached: true`. `422 rebuild_failed` means the kernel cannot build those values; `buildError` carries its message.+Returns `{ "ok": true, "variant": { "key", "values", "metrics", "files", "adjustments", "url" }, "cached": false }`. Values are clamped to each parameter's range and snapped to its step. A value set that has been built before returns instantly with `cached: true`. When the kernel cannot build those values the answer is still `200`, as `{ "ok": false, "error": "rebuild_failed", "message", "buildError": { "kind", "message", "line" } }`.### Readdiff --git a/src/cad/cad.css b/src/cad/cad.cssindex 3a61ba16b..4744f39ba 100644--- a/src/cad/cad.css+++ b/src/cad/cad.css@@ -415,6 +415,8 @@.cad-card {display: grid;+ grid-template-rows: auto 1fr;+ align-content: start;border: 1px solid var(--stroke);border-radius: var(--radius-lg, 14px);overflow: hidden;@@ -431,20 +433,28 @@}.cad-card__paper {+ position: relative;aspect-ratio: 4 / 3;+ overflow: hidden;background-color: var(--cad-paper);background-image:repeating-linear-gradient(0deg, rgba(91, 141, 239, 0.08) 0 1px, transparent 1px 16px),repeating-linear-gradient(90deg, rgba(91, 141, 239, 0.08) 0 1px, transparent 1px 16px);display: grid;place-items: center;- padding: 14px;}.cad-card__paper img {- max-width: 100%;- max-height: 100%;+ position: absolute;+ inset: 12px;+ width: calc(100% - 24px);+ height: calc(100% - 24px);object-fit: contain;+ transition: transform 0.25s ease;+}++.cad-card:hover .cad-card__paper img {+ transform: scale(1.04);}.cad-card__nothumb {@@ -906,6 +916,13 @@color: var(--warn);}+.cad-metric-note {+ margin: 2px 0 0;+ font-size: 12px;+ line-height: 1.5;+ color: var(--warn);+}+.cad-masses {display: grid;grid-template-columns: repeat(3, 1fr);diff --git a/src/cad/main.js b/src/cad/main.jsindex 1997f2277..1a0f39230 100644--- a/src/cad/main.js+++ b/src/cad/main.js@@ -381,8 +381,15 @@ async function runRebuild() {badge.hidden = false;err.hidden = true;try {- const { variant } = await rebuildDesign(state.design.id, state.values, { signal: controller.signal });+ const result = await rebuildDesign(state.design.id, state.values, { signal: controller.signal });if (controller.signal.aborted) return;+ if (!result.ok) {+ const kernel = result.buildError;+ err.textContent = kernel ? `${result.message} Kernel: ${kernel.message}` : result.message;+ err.hidden = false;+ return;+ }+ const { variant } = result;state.variant = variant;const viewer = await ensureViewer();await viewer.load(variant.files.glb, variant.metrics.size_mm);@@ -418,11 +425,14 @@ function renderOutputs() {const d = state.design;const [x, y, z] = metrics.size_mm;$('#cadMetrics').replaceChildren(+ ...[metricRow('Size', `${fmtMm(x)} × ${fmtMm(y)} × ${fmtMm(z)} mm`),metricRow('Volume', `${(metrics.volume_mm3 / 1000).toFixed(2)} cm³`),metricRow('Surface', `${(metrics.area_mm2 / 100).toFixed(1)} cm²`),- metricRow('Topology', `${metrics.solids} solid${metrics.solids === 1 ? '' : 's'} · ${metrics.faces} faces · ${metrics.edges} edges`),+ metricRow('Topology', `${metrics.solids} solid${metrics.solids === 1 ? '' : 's'} · ${metrics.faces} faces · ${metrics.edges} edges`, metrics.solids > 1 ? 'warn' : null),+ metrics.solids > 1 ? el('p', { class: 'cad-metric-note', text: `This part is ${metrics.solids} separate bodies that do not touch. If it should be one piece, use Refine: "connect every feature to the main body".` }) : null,metricRow('Kernel check', metrics.valid ? 'Valid B-rep' : 'Built, with geometry warnings', metrics.valid ? 'ok' : 'warn'),+ ].filter(Boolean),);$('#cadMass').replaceChildren(...MATERIALS.map((m) =>diff --git a/workers/cad-forge/main.py b/workers/cad-forge/main.pyindex e6734a53b..31d328dbf 100644--- a/workers/cad-forge/main.py+++ b/workers/cad-forge/main.py@@ -197,7 +197,9 @@ def _signal_failure(returncode: int, stderr: str) -> dict:"""Explain a child that died before reporting, by the signal that killed it."""signum = -returncode if returncode and returncode < 0 else Nonematch = CRASH_LINE.findall(stderr or "")- line = int(match[-1]) if match else None+ # faulthandler prints the most recent call first: the first match is the+ # innermost program line.+ line = int(match[0]) if match else Noneif signum == signal.SIGXCPU:return {"kind": "timeout", "message": "The design used more CPU time than a build allows. Reduce feature counts or boolean operations.", "line": line}if signum in (signal.SIGKILL, signal.SIGABRT):diff --git a/workers/cad-forge/sandbox_child.py b/workers/cad-forge/sandbox_child.pyindex f96c9838a..66bfa208d 100644--- a/workers/cad-forge/sandbox_child.py+++ b/workers/cad-forge/sandbox_child.py@@ -370,9 +370,11 @@ def write_result(out: dict) -> None:def main() -> int:- # A segfault inside OpenCascade prints the Python stack to stderr, which is- # how the parent learns which program line crashed the kernel.- faulthandler.enable(file=sys.stderr, all_threads=False)+ # A segfault inside OpenCascade prints the Python stacks to stderr, which is+ # how the parent learns which program line crashed the kernel. All threads,+ # because OCCT often faults on one of its own worker threads while the+ # program line that called it sits on the main thread.+ faulthandler.enable(file=sys.stderr, all_threads=True)sys.stdout.write("READY\n")sys.stdout.flush()raw = sys.stdin.readline()diff --git a/workers/cad-forge/test_sandbox.py b/workers/cad-forge/test_sandbox.pyindex 5bf80110a..892b4b879 100644--- a/workers/cad-forge/test_sandbox.py+++ b/workers/cad-forge/test_sandbox.py@@ -172,6 +172,15 @@ class FailureClassificationTests(unittest.TestCase):self.assertEqual(failure["line"], 14)self.assertIn("line 14", failure["message"])+ def test_crash_on_a_kernel_thread_reports_the_innermost_program_line(self):+ stderr = (+ "Fatal Python error: Segmentation fault\n\n"+ "Thread 0x00007f2a9b512340 (most recent call first):\n"+ ' File "<design>", line 3 in run\n'+ ' File "<design>", line 4 in <module>\n'+ )+ self.assertEqual(main._signal_failure(-11, stderr)["line"], 3)+def test_cpu_and_memory_limits(self):self.assertEqual(main._signal_failure(-24, "")["kind"], "timeout")self.assertEqual(main._signal_failure(-9, "")["kind"], "memory")