Architecture

Dylib Loading (load-once per process)

yesnofailokyesnoany tool/hook call → _load_dylib()pick first existing candidate:APHRODITE_HERMES_DYLIB_PATH → shipped plugin-dirbinaries/(immutable release assets) → canonical runtimehome($HERMES_HOME/aphrodite/binaries) → legacyplugin-dir copy→ monorepo target/release_ensure_binaries(): presence-only check - NEVERdownloads.Missing binaries → log the explicit setup step(bash download.sh / aphrodite setup); register()has no download path.APHRODITE_AUTO_DOWNLOAD=1 restores the legacyfetch for dev loops_state.dylib already set?return cached handle - load-once-per-process(a rebuilt dylib is picked up only after arestart)first load_probe_dylib(path) - smoke-test in a SUBPROCESS(once per unique path; a ctypes SIGSEGV cannot becaught bytry/except and would kill the whole Hermesgateway)RuntimeError - plugin disabled, graceful log,never SIGSEGVctypes.CDLL(resolved_path) - direct load, nocopies_configure_ffi: generated _bindings.pybind_to(dylib) →manual fallback → _REQUIRED_VOID_P assertion (7exports)(restype=c_void_p - prevents 64-bit pointertruncation)AttributeError (missing symbol)?RuntimeError naming path+symbol -stale/mismatched dylib_state.dylib set; return_call_json → FFI
LOAD FLOW
CDLL load (startup,gen 0)calls mutateAphroditeState(bridge OnceLock /core HANDLES)process exitsnext Hermes sessionloads the new dylibImageAImageBImageBstarts withDEFAULTstate(re-readsaphrodite.toml at dylibinit).ImageA'sinline_store+ markersare GONE:old markersunresolvableagainst thenew image.
STATE HANDLING ACROSS PROCESSES
IN THIS DOCUMENT

Crimson marks the heading currently in view; every entry is one of the document's own headings.

The Python shim loads the Rust dylib exactly once per process from the resolved path (ctypes.CDLL on the canonical candidate).

There is no hot-reload: dlopen memoizes loaded images by canonical path, and the plugin does not work around that with fresh copies.

To pick up a newly built dylib, restart the Hermes session - a new process loads the new image; a running process keeps the image it loaded at startup.

Load flow

yesnofailokyesnoany tool/hook call → _load_dylib()pick first existing candidate:APHRODITE_HERMES_DYLIB_PATH → shipped plugin-dirbinaries/(immutable release assets) → canonical runtimehome($HERMES_HOME/aphrodite/binaries) → legacyplugin-dir copy→ monorepo target/release_ensure_binaries(): presence-only check - NEVERdownloads.Missing binaries → log the explicit setup step(bash download.sh / aphrodite setup); register()has no download path.APHRODITE_AUTO_DOWNLOAD=1 restores the legacyfetch for dev loops_state.dylib already set?return cached handle - load-once-per-process(a rebuilt dylib is picked up only after arestart)first load_probe_dylib(path) - smoke-test in a SUBPROCESS(once per unique path; a ctypes SIGSEGV cannot becaught bytry/except and would kill the whole Hermesgateway)RuntimeError - plugin disabled, graceful log,never SIGSEGVctypes.CDLL(resolved_path) - direct load, nocopies_configure_ffi: generated _bindings.pybind_to(dylib) →manual fallback → _REQUIRED_VOID_P assertion (7exports)(restype=c_void_p - prevents 64-bit pointertruncation)AttributeError (missing symbol)?RuntimeError naming path+symbol -stale/mismatched dylib_state.dylib set; return_call_json → FFI
LOAD FLOW

Notes

  • _state is a process-global holder (a module registered in sys.modules). Hermes builds one plugin manager per home and executes the shim once per home under a distinct module name; without the holder, the second load would call CDLL again on the same canonical path and reuse the mapped image (or fail on Windows where a second open of a loaded library is denied). The early-return makes later shim copies reuse the mapped handle.
  • _dylib_lock (a threading.Lock) guards the first-load window because ctypes releases the GIL during foreign calls - two Hermes threads could otherwise race through _load_dylib.
  • Hooks and tools call _load_dylib() fresh inside each closure (not a registration-time handle); the holder early-return makes that cheap.
  • The subprocess probe runs once per unique path per process - spawning a subprocess on every call would add latency to every hook/tool call.
  • No hotreload/ directory is ever created; no copies are written anywhere in the runtime home.

State handling across processes

CDLL load (startup,gen 0)calls mutateAphroditeState(bridge OnceLock /core HANDLES)process exitsnext Hermes sessionloads the new dylibImageAImageBImageBstarts withDEFAULTstate(re-readsaphrodite.toml at dylibinit).ImageA'sinline_store+ markersare GONE:old markersunresolvableagainst thenew image.
STATE HANDLING ACROSS PROCESSES