Skip to content

feat(safety): native real-time safe-projection via PyO3#7

Merged
joemunene-by merged 1 commit into
mainfrom
m4-rt-safety-native
Jun 17, 2026
Merged

feat(safety): native real-time safe-projection via PyO3#7
joemunene-by merged 1 commit into
mainfrom
m4-rt-safety-native

Conversation

@joemunene-by

Copy link
Copy Markdown
Owner

What

Ports ghostloop's safe-projection workspace envelope (AABB clamp plus radial sphere push-out) into an allocation-free Rust core, exposed to Python as ghostloop._rt_safety.

Why

The safety-envelope projection sits on the control hot path. A native, heap-free implementation makes it real-time-grade (deterministic, WCET-bounded) while keeping the pure-Python path as the reference and fallback.

How

  • New crate native/rt_safety (PyO3): in_envelope and project_to_workspace, fixed-capacity stack arrays, no heap on the hot path.
  • policies/safe_projection.py dispatches to the native path for sphere-only workspaces and falls back to the unchanged pure-Python implementation when the module is not built. Return shape and the projected_from audit field are identical.

Verification

  • tests/test_rt_safety_equivalence.py: native vs Python projection is an exact match (max per-axis error 0.0) across index-seeded cases, and projected points satisfy the workspace envelope.
  • Full existing ghostloop test suite still passes (non-regressive).

Build note

Build the module with maturin (maturin develop in native/rt_safety). The compiled .so is gitignored; without it, the guarded import simply uses the pure-Python path.

Port the safe_projection workspace envelope (AABB clamp plus radial sphere
push-out) into an allocation-free Rust core, exposed to Python as
ghostloop._rt_safety. policies/safe_projection.py now dispatches to the
native path for sphere-only workspaces and falls back to the unchanged
pure-Python implementation when the module is not built, preserving
identical results and the projected_from audit field.

Adds tests/test_rt_safety_equivalence.py: native vs Python projection is
an exact match (max per-axis error 0.0) across index-seeded cases, and
projected points satisfy the workspace envelope. Build the module with
maturin; the compiled artifact is gitignored.
@joemunene-by joemunene-by merged commit e09ab6e into main Jun 17, 2026
5 checks passed
@joemunene-by joemunene-by deleted the m4-rt-safety-native branch June 17, 2026 23:21
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