Skip to content

fix(elision): elide ungated dev-only prose + :doc non-literal + directory sentinel#4959

Merged
mike-thompson-day8 merged 1 commit into
mainfrom
worker/elision-sweep-ymkr2z
Jun 25, 2026
Merged

fix(elision): elide ungated dev-only prose + :doc non-literal + directory sentinel#4959
mike-thompson-day8 merged 1 commit into
mainfrom
worker/elision-sweep-ymkr2z

Conversation

@mike-thompson-day8

Copy link
Copy Markdown
Contributor

Summary

Three production-bundle-elision fixes on the shared elision-probe surface (implementation/scripts/check-elision.cjs sentinels + implementation/core/test/re_frame/elision_probe.cljs probe roots). One worker on one branch because all three share the two coupling files. Refs rf2-7czrms, rf2-7xz70g, rf2-tfiutq.

1. Ungated dev-only diagnostic emits — STEP-0 empirical re-evaluation

The ~18 app-facing warning/diagnostic emits (resources / routing / machines / ssr-client) call trace/emit! / trace/emit-error! directly on a runtime data branch (when-some / when (seq …) / doseq / a catch), building (str …) or literal-string prose, with no call-site interop/debug-enabled? gate.

STEP-0 finding (the load-bearing surprise): I rooted a representative site (routing advise-query-promotion!emit! + (str …) :advice; machines emit-destroy-exit-failure!emit-error! + literal string) in the :advanced probe and grepped both builds. The prose is already elided in production:

sentinel control (DEBUG=true) production (DEBUG=false)
stays a STRING in the route slice present (1) absent (0)
An :exit action threw during destroy-time cascade present (1) absent (0)

A directly-called emit! / emit-error! folds its body to nil under goog.DEBUG=false; Closure inlines the now-no-op call and drops the pure prose args as dead. The bead's stated root cause — emit!'s identity escaping into a late-bind registry — applies to the framework's own emit machinery (storage.cljc, registrar.cljc, which capture emit! via (late-bind/get-fn :trace/emit!) and are already gated), not to these direct-call sites.

Per the bead's own STEP-0 escape hatch ("if it does NOT survive — already DCE'd — re-evaluate, do not blindly gate"), no mass-gating was applied — gating 18 already-elided sites would add redundant noise implying a leak that does not exist (ELEGANCE / CLARITY). Instead I closed the systemic probe gap the bead correctly identifies: the probe previously pinned dev-only prose absence only inside already-gated branches and via the require boundary — it never rooted an ungated direct-emit site, so the fold-path's production absence was unverified. Added two DEV_ONLY_SENTINELS + a touch-direct-emit-diagnostics! root so the control build exercises the path and a future regression (e.g. capturing emit! into a var, escaping its identity like the framework machinery) is caught.

2. :doc macro-DCE gap on reg-machine opts map

expand-reg-machine forwarded its opts-form verbatim, bypassing gate-doc-args — so a literal (reg-machine :id {:doc "…"} spec) left its :doc string bytes in the :advanced bundle (the splice-through defreg-macro / defreg-event-macro surfaces gate every literal doc-bearing arg; reg-machine did not). Fix: route opts-form through gate-doc-arg when it is a literal map (the idiomatic shape), emitting the same (if interop/debug-enabled? <full> <stripped>) gate Closure folds. A non-literal opts expression (symbol / computed map / merge) passes through unchanged — its :doc still strips from stored handler-meta via the runtime register! strip, but its bytes are outside the macro's reach.

Pinned by: a new DEV_ONLY sentinel + probe touch (rf2-tfiutq-machine-opts-doc-sentinel — prod absent, control present, confirmed); a JVM handler-meta-strip parity test in the machines artefact (re-frame.machine-doc-opts-prod-elision-test); a cross-reference note in the core doc-elision suite (the core :test classpath lacks day8/re-frame2-machines, so the machine surface's semantic strip test lives in the machines artefact).

3. Reachability sentinel for the late-bind directory :description corpus

re-frame.late-bind.directory/hooks carries ~150 paragraph-length :description strings — plain ungated CLJC data, kept out of production solely by reachability DCE (verified: zero production src namespace :requires the directory; only test files and one docstring mention it). No leak today, but no sentinel guarded that absence. Added a PROD_ABSENT_WHEN_UNUSED_SENTINELS entry (Enqueue an event for processing by the drain loop, the :router/dispatch! row's :description, unique across tracked source) mirroring the EP-0023 image-assembly reachability guard, so an accidental future production :require is caught by CI. Pure test-guard addition — no source change.

Gate results

  • npm run test:elisionPASS: production 45/45 absent (was 42), control 45/45 present, EP-0023 1/1 provenance-survives + 2/2 assembly-DCE.
  • npm run test:cljs7999 tests / 36798 assertions, 0 failures, 0 errors.
  • machines JVM suite (clojure -M:test) — 845 tests / 2743 assertions, 0 failures, 0 errors.
  • core doc-elision JVM test — 5 tests / 27 assertions, 0 failures.
  • new machines doc-opts test — 2 tests / 4 assertions, 0 failures.

Files changed

  • implementation/core/src/re_frame/core_reg_macros.cljc — route reg-machine literal opts through gate-doc-arg (only production-source change).
  • implementation/scripts/check-elision.cjs — +2 direct-emit DEV_ONLY sentinels, +1 reg-machine opts-:doc DEV_ONLY sentinel, +1 directory-corpus PROD_ABSENT_WHEN_UNUSED sentinel.
  • implementation/core/test/re_frame/elision_probe.cljstouch-direct-emit-diagnostics! + reg-machine literal-opts :doc touch.
  • implementation/machines/test/re_frame/machine_doc_opts_prod_elision_test.clj — new JVM parity test for the reg-machine opts :doc strip.
  • implementation/core/test/re_frame/doc_metadata_prod_elision_test.clj — cross-reference note pointing at the machines-artefact parity test.

…c opts, directory corpus

Three production-bundle-elision fixes on the shared elision-probe surface
(check-elision.cjs sentinels + elision_probe.cljs probe roots).

1. Ungated dev-only diagnostic emits (rf2-7czrms / rf2-tfiutq) — STEP-0 empirical
   re-evaluation. The ~18 app-facing warning/diagnostic emits (resources /
   routing / machines / ssr-client) call trace/emit! / emit-error! DIRECTLY on a
   runtime data branch with no call-site interop/debug-enabled? gate. Rooting a
   representative site in the :advanced probe proved the (str ...) / literal-
   string prose is ALREADY elided in production (control build DEBUG=true keeps
   it; production DEBUG=false drops it): a directly-called emit fn folds its body
   to nil under goog.DEBUG=false, Closure inlines the no-op call, and the pure
   prose args drop as dead. The bead's premise (emit identity escaping into a
   late-bind registry) applies to the framework's OWN emit machinery (already
   gated), not these direct-call sites. So no mass-gating — instead close the
   systemic probe gap: the probe previously pinned prose absence only inside
   already-gated branches, never at an ungated direct-emit site. Add two
   DEV_ONLY sentinels + a touch rooting one emit! and one emit-error! direct
   site, pinning the fold-path elision against a future regression that captures
   emit! into a var.

2. :doc opts-map DCE gap on reg-machine (rf2-7xz70g / rf2-tfiutq). expand-reg-
   machine forwarded its opts-form verbatim, bypassing gate-doc-args, so a
   literal (reg-machine :id {:doc "..."} spec) left its :doc string bytes in the
   :advanced bundle. Route the opts-form through gate-doc-arg when it is a
   literal map (the idiomatic shape), emitting the same
   (if interop/debug-enabled? <full> <stripped>) gate Closure folds. Pin via a
   new DEV_ONLY sentinel + probe touch, a JVM handler-meta-strip parity test in
   the machines artefact, and a cross-reference note in the core doc-elision
   suite.

3. Reachability sentinel for the late-bind directory :description corpus
   (rf2-7czrms / rf2-tfiutq). The ~150 paragraph :description strings in
   re-frame.late-bind.directory/hooks are plain ungated CLJC data kept out of
   production solely by reachability DCE (no production src namespace requires
   the directory). No sentinel guarded that absence; add a PROD_ABSENT_WHEN_
   UNUSED sentinel mirroring the EP-0023 image-assembly guard so an accidental
   future production require is caught by CI.

Gates: npm run test:elision PASS (production 45/45 absent, control 45/45
present); npm run test:cljs 7999 tests / 36798 assertions 0 failures; machines
JVM 845 tests 0 failures; core doc-elision JVM 5 tests 0 failures.
@mike-thompson-day8 mike-thompson-day8 merged commit df67660 into main Jun 25, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant