Skip to content

feat(moe): generation-safe expert slot reservations and retirement (#18) - #24

Merged
saariuslystoned merged 4 commits into
mainfrom
feat/18-generation-safe-slot-retirement
Nov 30, 2026
Merged

saariuslystoned merged 4 commits into
mainfrom
feat/18-generation-safe-slot-retirement

Conversation

@saariuslystoned

Copy link
Copy Markdown
Contributor

Closes #18.

Summary

  • Monotonic slot generation & explicit retirement tokens (include/fs_moe_stream.h, src/fs_moe_stream.cpp): introduces fs_slot_reservation_t, fs_io_token_t, unique per-lease token_id, and 7 new C11-safe APIs for explicit reserve → staged read → generation-checked completion → accelerator lease → single-retirement lifecycle.
  • Zero stale publications: completions whose generation does not match the slot's current reservation discard staged bytes and retire the stale I/O without touching slot backing storage.
  • Deferred recycle / zero use-after-reuse: backing slot storage is never recycled or freed until both I/O retirement AND all accelerator consumer lease tokens have retired (exact single retirement enforced per token_id).
  • Exhaustive tests (tests/test_slot_retirement.cpp, tests/test_c11_abi.c, wired into Makefile & CMakeLists.txt): 7 suites covering stale completion, deferred recycle by consumer and I/O, exact-single retirement (double-retire rejection), real pread, 24-ordering permutation matrix, and 8-thread concurrency stress.

Verification

  • make clean && make verify: PASS (0 warnings under -std=c11/-std=c++17 -Wall -Wextra -Werror, clean-room audit 0 violations).
  • ASan+UBSan (-fsanitize=address,undefined -fno-sanitize-recover=all): PASS (0 errors).
  • TSan (-fsanitize=thread): PASS (0 data races under 8-thread stress).

- Serialize read vs complete/retire per token with read_in_progress guard (FS_ERR_BUSY, no staging memcpy race)
- Validate expert_id on publish/read so forged tokens cannot publish wrong bytes
- Evict all duplicate incarnations of one expert (evict-all)
- Snapshot in_speculative under mu in overlap execute (TSan race)
@saariuslystoned

Copy link
Copy Markdown
Contributor Author

Adversarial Hardening & Public-Roads Audit Receipt (d9764c90)

  • Prior PR head: c80dfdbe → Hardened head: d9764c90
  • 4 concurrency & security bugs fixed (src/fs_moe_stream.cpp, tests/test_slot_retirement.cpp):
    1. Staging TOCTOU data race (complete_io vs read_reserved): added read_in_progress BUSY guard preserving token
    2. TSan data race in fs_moe_execute_layer_overlap reading in_speculative/tile counts unlocked: converted to locked snapshot
    3. Incomplete eviction stopping at first matching slot across duplicate expert incarnations
    4. Forged expert_id publish bypass: require expert_id == pending_expert_id on publish & read
  • Verification: make verify PASS (11/11 retirement suites), ASan+UBSan PASS, TSan 20x soak 0 fails, strict -Wpedantic -Wshadow -Wconversion -Werror PASS, CTest 11/11 PASS, ./scripts/clean-room-audit.sh PASS (0 violations; private-term diff scan clean).

@saariuslystoned
saariuslystoned merged commit 89cc50a into main Nov 30, 2026
4 of 5 checks passed
@saariuslystoned
saariuslystoned deleted the feat/18-generation-safe-slot-retirement branch November 30, 2026 19:08
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.

Generation-safe expert slot reservations and retirement

1 participant