Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

WritingGate never engages on non-Latin prose: the activation threshold counts only ASCII-letter words (and splits accented Latin words into fragments)

Open IvanLeontev-stack opened this issue 2 months ago • 1 comments

Version

LifeOS 7.40.4 / WritingGate 1.0.7 — also reproduced on a clean checkout of main at 5e2f2e8c.

What is broken

WritingGate decides whether a response ships authored outbound prose by counting words with /[A-Za-z][A-Za-z'’-]+/g. Prose in any non-Latin script scores zero, so both activation branches — strong && words >= 40 (block) and weak && words >= 60 (telemetry) — are unreachable, and every such response falls through to no-content. A #ad / #sponsored caption written in Cyrillic, Greek, Hebrew or Arabic is never gated no matter how strong the DISCLOSURE_CAPTION or DELIVER_LABEL signal is, because the word-count conjunct can never be satisfied. Unlike the detector-unavailable path, which degrades to telemetry and says so, this one writes no-content, which is indistinguishable from an ordinary chat turn: the gate looks installed and healthy on an install where it can never fire. The same regex also splits accented Latin words at the accent, so it undercounts French, Spanish, Portuguese and German prose in an English-language install.

Where (file:line)

hooks/WritingGate.hook.ts:151 (proseWordCount(), feeds the words >= 40 / words >= 60 branches at :205 and :236) and hooks/WritingGate.hook.ts:98 (deliverableBlocks(), the ">= 40 words" paragraph candidate). Same regex literal at both sites.

Repro on a clean tree

gh api repos/danielmiessler/LifeOS/tarball/5e2f2e8c > main.tar.gz
mkdir clean && tar xzf main.tar.gz -C clean --strip-components=1

cat > r3.ts <<'TS'
import { readFileSync } from "node:fs";
const ROOT = process.env.LIFEOS_ROOT!;
const src = readFileSync(`${ROOT}/hooks/WritingGate.hook.ts`, "utf8");
// Neither function is exported; lift both out of the shipped source.
const lift = (re: RegExp) => { const m = src.match(re)!; return new Function(m[1], m[2].replace(/: string\[\]/g, "")) as (s: string) => any; };
const proseWordCount    = lift(/function proseWordCount\((\w+): string\): number \{([\s\S]*?)\n\}/);
const deliverableBlocks = lift(/function deliverableBlocks\((\w+): string\): string\[\] \{([\s\S]*?)\n\}/);

const en = "word ".repeat(60).trim();
const ru = "Слово ".repeat(60).trim();
console.log("EN 60-word paragraph -> proseWordCount", proseWordCount(en), "| deliverableBlocks", deliverableBlocks(en).length);
console.log("RU 60-word paragraph -> proseWordCount", proseWordCount(ru), "| deliverableBlocks", deliverableBlocks(ru).length);

const accented = "café naïve résumé";
console.log("accented Latin, current  ->", JSON.stringify(accented.match(/[A-Za-z][A-Za-z'’-]+/g)));
console.log("accented Latin, proposed ->", JSON.stringify(accented.match(/[\p{L}][\p{L}'’-]+/gu)));
console.log("proposed on EN/RU        ->", (en.match(/[\p{L}][\p{L}'’-]+/gu)||[]).length, (ru.match(/[\p{L}][\p{L}'’-]+/gu)||[]).length);
TS

LIFEOS_ROOT="$PWD/clean/LifeOS/install" bun r3.ts

Negative control

On unpatched main@5e2f2e8c the probe is red:

EN 60-word paragraph -> proseWordCount 60 | deliverableBlocks 1
RU 60-word paragraph -> proseWordCount 0 | deliverableBlocks 0
accented Latin, current  -> ["caf","na","ve","sum"]
accented Latin, proposed -> ["café","naïve","résumé"]
proposed on EN/RU        -> 60 60

Stated without reference to any fix: a 60-word paragraph counts as 60 words in English and 0 words in Russian, so the gate's two activation thresholds are unreachable for that install, and café naïve résumé counts as the four words caf, na, ve, sum.

Suggested fix

One line at each of the two sites:

-  return (stripped.match(/[A-Za-z][A-Za-z'’-]+/g) || []).length;
+  return (stripped.match(/[\p{L}][\p{L}'’-]+/gu) || []).length;
-    const words = para.match(/[A-Za-z][A-Za-z'’-]+/g);
+    const words = para.match(/[\p{L}][\p{L}'’-]+/gu);

Parity verified against the production functions on the clean tree, in the output above: English 60 → 60 unchanged, Russian 0 → 60, accented Latin 4 fragments → 3 words. Scripts without spaces (CJK) still need a segmenter and are out of scope here — this change moves them from "silently zero" to "still zero", not backwards.

Related

#2131 — the same ASCII-filter family in the KNOWLEDGE filename writers. The NFKD-normalize-then-strip-marks fix ported there recovers accented Latin, but leaves non-Latin scripts at the same zero-output behaviour, since Cyrillic, Greek and CJK have no Latin decomposition. Also #1865, #1787.


  • [x] I searched open and closed issues for this defect.
  • [x] The repro runs against a clean tree of the version above, not against a modified install.
  • [x] The pasted output carries no personal data — no names, no home paths, no tokens, no own content. The Russian string is an invented test word repeated 60 times.

IvanLeontev-stack avatar Sep 19 '26 17:09 IvanLeontev-stack

Thanks @IvanLeontev-stack. WritingGate has since been retired: the Stop chain went from twelve gates to seven, and writing quality is no longer enforced per response by a hook, so the ASCII-only word count no longer runs anywhere. On upgrade, the installer's retirement list moves the old hook aside so it stops firing.

danielmiessler avatar Oct 03 '26 04:10 danielmiessler