Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

pin UTF-8 when reading the file the fill-holes gate patches

Adam Eivya5e84604e8f6
diff --git a/server/services/imageTo3d/trellis2GenerateRunner.py b/server/services/imageTo3d/trellis2GenerateRunner.py
index 75a6dafd57..e1d79a341d 100644
--- a/server/services/imageTo3d/trellis2GenerateRunner.py
+++ b/server/services/imageTo3d/trellis2GenerateRunner.py
@@ -378,7 +378,9 @@ def _enable_fill_holes(generate_dir):
/ "mesh" / "base.py")
if not base.exists():
raise AdapterContractError(f"--fill-holes requested but {base} is missing")
- if FILL_HOLES_ENV not in base.read_text():
+ # Explicit codec for the same reason the patcher needs one: a locale-default read
+ # of a UTF-8 source mangles non-ASCII and can turn a present gate into an absent one.
+ if FILL_HOLES_ENV not in base.read_text(encoding="utf-8"):
raise AdapterContractError(
"--fill-holes was requested but trellis2/representations/mesh/base.py "
"still carries the unconditional mps_compat stub. Repair the TRELLIS.2 "
diff --git a/server/services/imageTo3d/trellis2GenerateRunner.test.js b/server/services/imageTo3d/trellis2GenerateRunner.test.js
index a04c898ec9..cfa2eb81cc 100644
--- a/server/services/imageTo3d/trellis2GenerateRunner.test.js
+++ b/server/services/imageTo3d/trellis2GenerateRunner.test.js
@@ -345,6 +345,21 @@ describe.skipIf(!pyBin)('trellis2RestoreFillHoles', () => {
expect(out).toMatch(/def simplify\(self, target=1000000\):\n\s+return\n/);
});
+ it('finds the stub when the interpreter default codec is not UTF-8', () => {
+ // The Windows-only failure this pins: UPSTREAM_STUB contains an en dash, and a
+ // locale-default read (cp1252 on a Windows runner) mangles it so the literal match
+ // fails and the patcher reports "upstream changed the patch". PYTHONUTF8=0 plus a
+ // legacy locale reproduces that on any platform; without an explicit encoding= in
+ // the patcher this test fails here too.
+ writeFileSync(basePath(), STUBBED);
+ const out = execFileSync(pyBin, [trellis2FillHolesScript(), dir], {
+ encoding: 'utf8',
+ env: { ...process.env, PYTHONUTF8: '0', LC_ALL: 'C', LANG: 'C' },
+ });
+ expect(out).toMatch(/now gated/);
+ expect(readNormalized()).toContain('PORTOS_TRELLIS2_FILL_HOLES');
+ });
+
it('finds and replaces the stub in a CRLF file', () => {
// The Windows condition, reproduced on any platform. The patcher matches
// UPSTREAM_STUB literally and that literal contains \n, so it only works because
diff --git a/server/services/imageTo3d/trellis2RestoreFillHoles.py b/server/services/imageTo3d/trellis2RestoreFillHoles.py
index eb3c9b3d22..98bdd794b4 100644
--- a/server/services/imageTo3d/trellis2RestoreFillHoles.py
+++ b/server/services/imageTo3d/trellis2RestoreFillHoles.py
@@ -55,7 +55,13 @@ def main():
if not path.exists():
raise SystemExit(f"not found: {path}")
- source = path.read_text()
+ # encoding="utf-8" is load-bearing, not hygiene. UPSTREAM_STUB contains an EN DASH,
+ # and `read_text()` without an explicit codec uses the LOCALE default — cp1252 on a
+ # Windows runner — which mangles it to "—" so the literal match silently fails and
+ # this reports "upstream changed the patch". That failed only on Windows CI and
+ # nowhere else. Same reason on the write side: round-tripping through cp1252 would
+ # corrupt every non-ASCII byte in the file we are rewriting.
+ source = path.read_text(encoding="utf-8")
if GATE_ENV in source:
print(f"[portos] fill_holes gate already present in {path.name}")
@@ -73,7 +79,7 @@ def main():
# which stay stubbed deliberately: neither has the independent at-scale
# evidence fill_holes has, and `simplify` additionally interacts with the
# decimation-target override in trellis2GenerateRunner.py.
- path.write_text(source.replace(UPSTREAM_STUB, GATED, 1))
+ path.write_text(source.replace(UPSTREAM_STUB, GATED, 1), encoding="utf-8")
print(f"[portos] fill_holes is now gated on ${GATE_ENV} in {path.name}")