FTNN Path B (LD_PRELOAD CefInitialize interposition) — build & test report
====================================================================
Date: 2026-11-16 ~03:00 HKT. Old machine 213.35.112.20 (ARM64, box64 v0.4.5).
FTNN v16.39 x86_64, CEF 109 / Chromium 109.0.5414.120, libcef.so 317,996,616 B.

BOTTOM LINE
------------
Path B shim BUILT, DEPLOYED, and VERIFIED WORKING at the login screen.
LD_PRELOAD loads under box64; CefInitialize is intercepted; no_sandbox=1 is
set in CefSettings and honored by CEF (subprocess cmdlines show --no-sandbox).
FTNN starts cleanly and shows the Log In screen with the shim.
READY for the owner-login definitive test (start FTNN on :1 with the shim,
owner logs in, watch cef_main.log for GPU crash lines).

(a) SHIM SOURCE + .SO + SHA256
-------------------------------
Source: ~/workspace/ftnn-cef-nogpu.c  (v2, 4,471 B)
  sha256: <see below — source was rewritten v1 -> v2; .so sha is authoritative>
Compiled .so (this VM, x86_64 gcc 13.3):
  ~/workspace/ftnn-cef-nogpu.so  (15,952 B)
  sha256: 750acd1cac6d7003461ba7e19bc7a5188eb96779046adeda6cf0ee5b36a2cae1
  file: ELF 64-bit LSB shared object, x86-64, dynamically linked
  exports: T cef_initialize
Deployed: /tmp/ftnn/cef-nogpu.so on 213.35.112.20 (same sha256, verified).

(b) LOGIN-SCREEN TEST RESULT
----------------------------
Test: FTNN on :99, LD_PRELOAD=/tmp/ftnn/cef-nogpu.so, CLI --disable-gpu,
started ~02:59 HKT, observed ~03:00-03:01 HKT.
- FTNN main process PID 1544746 alive, Log In screen CONFIRMED by screenshot
  /tmp/ftnn-pathb2-screen.png (400,633 B, viewed; local copy
  ~/workspace/ftnn-pathb2-screen.png).
- cef_main.log: 0 bytes, 0 crash lines at login screen (expected — the GPU
  process does not spawn at the pure-Qt login screen; same as the no-flag
  baseline in the flag tests).
- FTNN starts cleanly with the shim; CEF initializes successfully
  (v2 — see the v1 failure note below).

(c) EXACT CefSettings FIELDS SET
---------------------------------
Only ONE field is set: no_sandbox = 1.
- Offset: 12 (int) in cef_settings_t on x86_64
  (size_t size @0, int single_process @8, int no_sandbox @12).
- Intercept log: "settings=0xecdd331ffd88 size=440 no_sandbox 0 -> 1".
  size=440 confirms the CEF 109 cef_settings_t layout.
- no_sandbox is the formal CefSettings field for --no-sandbox (A2 Path B).
- disable_gpu is NOT set: there is NO disable_gpu field in cef_settings_t
  (CEF 109 or any version). Verified two ways:
  (1) strings on libcef.so: "disable-gpu" appears only as command-line
      switch names, never as a settings field.
  (2) CefSharp CefSettings docs: DisableGpuAcceleration is a METHOD that
      "Set[s] command line argument to disable GPU Acceleration" — i.e. GPU
      is disabled in CEF via the --disable-gpu switch, not a struct field.
  A2's "settings.disable_gpu (some versions have it)" is not correct for
  this CEF. This does not lose anything: --disable-gpu already reaches CEF
  here (proven: FTWebRender shows --use-gl=disabled) and is already
  insufficient post-login (1085 crash lines), so a struct disable_gpu
  would add nothing. The launch failure (error_code=1002) is a
  sandbox/process-spawn problem, which no_sandbox targets directly.

(d) DOES LD_PRELOAD WORK UNDER box64? — YES (with a v1 caveat, fixed in v2)
----------------------------------------------------------------------
YES. Verified three independent ways:
1. Constructor marker: /tmp/cef-nogpu-loaded.log on the old machine shows
   "cef-nogpu.so v2 loaded pid=1544746" (FTNN main) plus subprocess PIDs.
2. /proc/1544746/maps shows cef-nogpu.so mapped (3 segments,
   0x7fff00000000-0x7fff00003000).
3. Intercept works: the real cef_initialize was resolved and called, and
   no_sandbox was set 0 -> 1. Bonus proof CEF honored it: the FTWebRender
   zygote cmdline contained "--no-sandbox" (propagated from CefSettings).

v1 FAILURE (documented, fixed in v2):
- v1 used dlsym(RTLD_NEXT, "cef_initialize") to resolve the real function.
  It FAILED: log showed "ERROR dlsym(RTLD_NEXT, cef_initialize) failed",
  the shim returned 0, and CEF was never initialized (FTNN still showed
  the Qt login screen, but CEF was dead).
- Root cause: FTNN does NOT link libcef.so as DT_NEEDED (readelf shows only
  libstdc++/libm/libgcc_s/libc). libcef.so is dlopened at runtime with
  RTLD_LOCAL, so its symbols are invisible to RTLD_NEXT.
- v2 fix: resolve via dlopen(RTLD_NOLOAD) on the already-loaded libcef.so
  (full path first, then soname), with RTLD_NEXT kept as a first try.
  Log confirms: "real cef_initialize resolved via dlopen NOLOAD (full path)".
- The C++ CefInitialize is a LOCAL symbol (t) in libcef.so and cannot be
  interposed; the C cef_initialize is a DYNAMIC symbol (T @0x4165df0) and
  is what FTNN's statically-linked libcef_dll_wrapper calls. Interposing
  the C symbol is the correct target.

READY FOR OWNER-LOGIN DEFINITIVE TEST
-------------------------------------
To run it: on the old machine, start FTNN on :1 with the shim + --disable-gpu:
  cd /tmp/ftnn/opt/FTNN
  DISPLAY=:1 HOME=/tmp/ftnn-home FTNN_HOME=/tmp/ftnn/opt/FTNN \
    LD_PRELOAD=/tmp/ftnn/cef-nogpu.so nohup box64 ./FTNN --disable-gpu \
    > /tmp/FTNN-pathb-login.log 2>&1 < /dev/null &
Owner logs in via VNC (5901). Watch:
  /tmp/ftnn-home/Library/Containers/FTNN/2.0/Data/Library/Application Support/Logs/FTLog/cef_main.log
  (note the full path — the earlier short path .../Data/Logs/cef_main.log is wrong)
  + /tmp/cef-nogpu-loaded.log (should show a fresh intercept line).
- 0 crash lines post-login + main interface loads = Path B works.
- Crash loop returns = no_sandbox alone insufficient; next options are
  --in-process-gpu, or investigating the box64 ioctl path (A2 cause 3).

CLEANUP / STATE
---------------
- Test FTNN on :99 (PID 1544746) + subprocesses killed after the test.
  No FTNN/FTWebRender/CrashReporter processes remain.
- x.js (PID 693552) and m.js (PID 695238) untouched and running throughout.
- No FTNN files modified. Only additions: /tmp/ftnn/cef-nogpu.so,
  /tmp/cef-nogpu-loaded.log, /tmp/cef_main.log.pre-pathb (backup of the
  1085-crash cef_main.log, 207,330 B), screenshots and logs under /tmp.
- cef_main.log was truncated to 0 for a clean baseline before the v2 test
  (backup at /tmp/cef_main.log.pre-pathb).

FILES
-----
- Shim source: ~/workspace/ftnn-cef-nogpu.c
- Compiled .so: ~/workspace/ftnn-cef-nogpu.so
  (deployed copy: /tmp/ftnn/cef-nogpu.so on 213.35.112.20)
- This report: ~/workspace/goals/telegram-ai/hidden_files/ftnn-pathb-report.txt
- Login-screen screenshot: ~/workspace/ftnn-pathb2-screen.png
  (server copy /tmp/ftnn-pathb2-screen.png, 400,633 B)
- Background: /tmp/a2-cef-diagnosis.html (A2, relay 63320),
  ~/workspace/goals/telegram-ai/hidden_files/ftnn-gpu-flag-test-results.txt
