Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

chore: merge

Sidwebworkscc5533f324e5
diff --git a/apps/assembler/occt-patches/0001-common-base-allocator-thread-local.patch b/apps/assembler/occt-patches/0001-common-base-allocator-thread-local.patch
index 07418b778e..0f116caf95 100644
--- a/apps/assembler/occt-patches/0001-common-base-allocator-thread-local.patch
+++ b/apps/assembler/occt-patches/0001-common-base-allocator-thread-local.patch
@@ -1,4 +1,4 @@
-Subject: [PATCH] NCollection_BaseAllocator: make CommonBaseAllocator thread_local
+Subject: [PATCH] NCollection_BaseAllocator: per-thread CommonBaseAllocator (freed at thread exit)
The single process-wide CommonBaseAllocator singleton is copied into every
NCollection container ctor/dtor, so its atomic refcount is a true-sharing
@@ -8,10 +8,19 @@ box regardless of jemalloc/mutex changes. A per-thread instance keeps refcount
traffic core-local (measured 3.5x -> ~8.5x, output bit-identical). The allocator
is stateless (a malloc wrapper) and handle refcounting keeps each thread's
instance alive across any cross-thread handoff, so this is semantics-preserving.
+
+Held BY VALUE (not a thread_local raw pointer): a `new occ::handle<...>` per
+thread would leak one Handle + allocator for every worker thread that ever
+touches OCCT. A by-value thread_local Handle runs its destructor at thread exit,
+dropping only that thread's ref — containers that copied the Handle keep the
+allocator alive until their own refs drop, so freeing here is safe (and the main
+thread's instance lives for the whole process as before).
--- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseAllocator.cxx
+++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseAllocator.cxx
@@ CommonBaseAllocator
- static occ::handle<NCollection_BaseAllocator>* THE_SINGLETON_ALLOC =
-+ static thread_local occ::handle<NCollection_BaseAllocator>* THE_SINGLETON_ALLOC =
- new occ::handle<NCollection_BaseAllocator>(new NCollection_BaseAllocator);
- return *THE_SINGLETON_ALLOC;
+- new occ::handle<NCollection_BaseAllocator>(new NCollection_BaseAllocator);
+- return *THE_SINGLETON_ALLOC;
++ static thread_local occ::handle<NCollection_BaseAllocator> THE_SINGLETON_ALLOC(
++ new NCollection_BaseAllocator);
++ return THE_SINGLETON_ALLOC;
diff --git a/apps/assembler/occt-patches/apply.sh b/apps/assembler/occt-patches/apply.sh
index 3452a5072f..f5611727ff 100755
--- a/apps/assembler/occt-patches/apply.sh
+++ b/apps/assembler/occt-patches/apply.sh
@@ -1,9 +1,26 @@
#!/usr/bin/env bash
-# Apply Carbon's OCCT source patches in-place. Idempotent-ish; fails loud.
+# Apply Carbon's OCCT source patches in-place. Idempotent; fails loud.
set -euo pipefail
SRC="${1:?usage: apply.sh <occt-src-dir>}"
f="$SRC/src/FoundationClasses/TKernel/NCollection/NCollection_BaseAllocator.cxx"
-grep -q 'static thread_local occ::handle<NCollection_BaseAllocator>\* THE_SINGLETON_ALLOC' "$f" && { echo "already patched"; exit 0; }
-perl -0pi -e 's/static (occ::handle<NCollection_BaseAllocator>\* THE_SINGLETON_ALLOC)/static thread_local $1/' "$f"
-grep -q 'static thread_local occ::handle<NCollection_BaseAllocator>\* THE_SINGLETON_ALLOC' "$f" || { echo "PATCH FAILED"; exit 1; }
-echo "patched CommonBaseAllocator -> thread_local"
+
+# CommonBaseAllocator(): make the singleton PER-THREAD to kill the refcount
+# cache-line hotspot (see 0001-...patch), AND hold it BY VALUE so its Handle
+# destructor runs at thread exit — a thread_local RAW pointer `new`'d per thread
+# would leak one Handle + allocator for every worker thread that ever touches
+# OCCT. Handle refcounting keeps the allocator alive across any cross-thread
+# handoff (containers hold their own ref), so freeing this thread's ref is safe.
+if grep -q 'static thread_local occ::handle<NCollection_BaseAllocator> THE_SINGLETON_ALLOC(new NCollection_BaseAllocator);' "$f"; then
+ echo "already patched"
+ exit 0
+fi
+
+# Declaration: `static [thread_local] occ::handle<...>* X = new occ::handle<...>(new NCollection_BaseAllocator);`
+# -> `static thread_local occ::handle<...> X(new NCollection_BaseAllocator);`
+perl -0pi -e 's/static(?:\s+thread_local)?\s+occ::handle<NCollection_BaseAllocator>\*\s+THE_SINGLETON_ALLOC\s*=\s*new\s+occ::handle<NCollection_BaseAllocator>\(new NCollection_BaseAllocator\);/static thread_local occ::handle<NCollection_BaseAllocator> THE_SINGLETON_ALLOC(new NCollection_BaseAllocator);/s' "$f"
+# Return: deref the pointer no longer applies now that it's by value.
+perl -0pi -e 's/return \*THE_SINGLETON_ALLOC;/return THE_SINGLETON_ALLOC;/' "$f"
+
+grep -q 'static thread_local occ::handle<NCollection_BaseAllocator> THE_SINGLETON_ALLOC(new NCollection_BaseAllocator);' "$f" || { echo "PATCH FAILED (declaration)"; exit 1; }
+grep -q 'return THE_SINGLETON_ALLOC;' "$f" || { echo "PATCH FAILED (return)"; exit 1; }
+echo "patched CommonBaseAllocator -> thread_local (by value, freed at thread exit)"
diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
index 76d5ecc6b9..9a2677e65a 100644
--- a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
@@ -1,5 +1,5 @@
{
- "generated": "2026-07-12T23:58:14.390Z",
+ "generated": "2026-07-13T00:20:05.651Z",
"totalTools": 1306,
"modules": 15,
"tools": [