hotfix: fix malformed string literals in safety.el/sessions.el that break elc #77

Merged
will.anderson merged 3 commits from hotfix/elc-source-typos into main 2026-07-15 18:41:02 +00:00
Owner

Fix malformed string literals that break elc compilation

Three unescaped-quote typos produce malformed El string literals:

  • safety.el:282 — a stray extra " at the tail of safety_soft_phrases
    (\"having a breakdown\""]" vs the correct sibling line 278 \"...\"]")
    closes the El string early, desyncing the lexer's string/code phase for the
    rest of the file. Downstream, apostrophe text in comments (can't, i'm)
    lands in code-phase and shatters into bare identifiers (can; t; i; m; none; soft; hard;) → invalid C. (This is the real cause of the reported
    "apostrophe → broken C"; the lexer's apostrophe handling is fine.)
  • sessions.el:517str_replace(topic_snip, """, "'"): the bare """
    lexes as an empty string plus an unterminated string that swallows the
    closing ) and }. With the current elc this leaves an unclosed call-arg
    list and triggers the parser overrun → ~700GB OOM.
  • sessions.el:520 — unescaped nested quotes in the topic_tags literal.

All three now use escaped inner quotes ("\"", "[\"...\"]").

Verification (bounded, existing elc — no compiler rebuild)

  • Fixed safety.el → compiles clean, complete brace-balanced C,
    safety_soft_phrases is a single well-formed literal, zero apostrophe shards.
  • Fixed sessions.el → compiles clean, 626 lines of C, braces 311/311, no OOM
    (previously OOM-killed at ~700GB).
  • All elc runs were bound by an RSS watchdog + wall timeout, one at a time.

These fixes unblock compilation immediately with the current elc binary. The
underlying compiler robustness fix (elc should emit a syntax error, not OOM, on
such input) is proposed separately in neuron-technologies/el#<hotfix/elc-fixes>.

## Fix malformed string literals that break elc compilation Three unescaped-quote typos produce malformed El string literals: - **safety.el:282** — a stray extra `"` at the tail of `safety_soft_phrases` (`\"having a breakdown\""]"` vs the correct sibling line 278 `\"...\"]"`) closes the El string early, desyncing the lexer's string/code phase for the rest of the file. Downstream, apostrophe text in comments (`can't`, `i'm`) lands in code-phase and shatters into bare identifiers (`can; t; i; m; none; soft; hard;`) → invalid C. (This is the real cause of the reported "apostrophe → broken C"; the lexer's apostrophe handling is fine.) - **sessions.el:517** — `str_replace(topic_snip, """, "'")`: the bare `"""` lexes as an empty string plus an unterminated string that swallows the closing `)` and `}`. With the current elc this leaves an unclosed call-arg list and triggers the parser overrun → ~700GB OOM. - **sessions.el:520** — unescaped nested quotes in the `topic_tags` literal. All three now use escaped inner quotes (`"\""`, `"[\"...\"]"`). ### Verification (bounded, existing elc — no compiler rebuild) - Fixed `safety.el` → compiles clean, complete brace-balanced C, `safety_soft_phrases` is a single well-formed literal, zero apostrophe shards. - Fixed `sessions.el` → compiles clean, 626 lines of C, braces 311/311, no OOM (previously OOM-killed at ~700GB). - All elc runs were bound by an RSS watchdog + wall timeout, one at a time. These fixes unblock compilation immediately with the current elc binary. The underlying compiler robustness fix (elc should emit a syntax error, not OOM, on such input) is proposed separately in neuron-technologies/el#<hotfix/elc-fixes>.
will.anderson added 2 commits 2026-07-14 19:22:41 +00:00
safety: route threat-to-others to refusal+911, not 988/self-harm (Track B)
Neuron Soul CI / build (pull_request) Successful in 6m7s
Neuron Soul CI / deploy (pull_request) Has been skipped
3bb88330da
A homicide/assault threat (going to kill, going to hurt, etc.) had no
bucket in safety_classify_hard_bell and fell through to the self_harm
default, showing the user the 988 suicide line and (via the desktop gate)
their safety contact. That framing is wrong and potentially dangerous for
someone voicing intent to harm another person.

Add a distinct Track B (safety_threat_to_others_phrases + a threat_other
classification and a safety_hard_directive branch) that refuses to assist,
de-escalates, and directs to 911 for a credible imminent threat, and that
never surfaces 988 or involves the safety contact. Track A (abuse /
self_harm) is checked first and unchanged, so victim and self-directed
phrasings still route correctly.

Source-only change: requires a soul rebuild + dist/soul.c regen to ship.
safety/sessions: fix malformed string literals that crash elc
Neuron Soul CI / build (pull_request) Successful in 4m11s
Neuron Soul CI / deploy (pull_request) Has been skipped
b0fb2bf085
Three unescaped-quote typos produced malformed El string literals that broke
compilation:

- safety.el:282  stray extra double-quote at the tail of safety_soft_phrases
  (\"having a breakdown\""]") closed the string early, desyncing the lexer's
  string/code phase for the rest of the file and shattering later apostrophe
  text (can't, i'm) into bare identifiers -> invalid C.
- sessions.el:517  str_replace(topic_snip, """, ...) — the bare """ is an
  empty string plus an unterminated string that swallowed the closing ) and };
  with the current elc this triggers the parser overrun -> ~700GB OOM.
- sessions.el:520  unescaped nested quotes in the topic_tags literal.

All three now use escaped inner quotes. Verified: both files compile clean
under the current elc (safety.c and sessions.c well-formed, brace-balanced).
will.anderson added 1 commit 2026-07-14 23:45:23 +00:00
regen dist: rebuild soul.c from corrected sources (OOM gone, Track B compiled in)
Neuron Soul CI / build (pull_request) Successful in 4m12s
Neuron Soul CI / deploy (pull_request) Has been skipped
1011d8e5be
Regenerates the combined dist/soul.c and per-module dist/*.c from the current
El sources, on top of the elc-source-typo fixes (PR #77) and the Track B
threat-to-others routing (PR #76), both already on this branch.

Validated end to end under a physical-RSS watchdog (macOS silently ignores
ulimit -v / RLIMIT_AS, so every elc/elb run was RSS-polled and kill -9'd at a
3GB ceiling, one module at a time):

- OOM is GONE. The stale dist/soul-with-nlg.el (which still carries the
  malformed string literals) explodes to 3.3GB+ and is watchdog-killed at ~90%.
  With the typos fixed, every one of the 48 modules compiles at <=18MB peak RSS,
  and the full flat amalgamation compiles as a single translation unit at ~68MB.
  The 700GB pathology was purely the unbounded-parser-on-malformed-literal loop;
  no malformed construct means no loop.
- The regenerated soul.c contains Track B: safety_classify_hard_bell ->
  threat_other -> safety_hard_directive routes credible threat-to-others to 911
  and explicitly NOT to 988 / the safety contact. Verified in source, in the
  emitted C, and in the linked binary's strings. Track A (abuse / self_harm)
  is unchanged and still checked first.
- The regenerated soul links to a working native arm64 binary and boots: serves
  on a throwaway port, /health returns 200, awareness loop runs.

Also fixes one source blocker discovered during regen (unrelated to the typos
or Track B): chat.el handle_chat_agentic left a void `if { println(...) }` in
value position, which the current elc lowers to `_if_result = (println(...))`
(assigning void) -> invalid C. Bound an explicit Bool so the branch is
non-void; behavior unchanged (still only logs on persist failure).

NOTE (runtime dependency, for controlled deploy): this branch's chat.el calls
engram_get_node_by_label, which the canonical el-compiler/runtime does not yet
declare/define (the release runtime v1.0.0-20260501 has it; the newest runtime
has arena + http_serve_async but not this). Building the soul requires a runtime
that has all three. Land engram_get_node_by_label into the runtime package
before this soul.c can be built in CI.

Do not merge — regen + Track B going live is a controlled-deploy call.
will.anderson merged commit 64c1789fcc into main 2026-07-15 18:41:01 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: neuron-technologies/neuron#77