Repository navigation
Commit 0c25e88
authored
helios: fix deferred_prefill checkpoints, shared_pages accounting, drop teardown, and >64 MiB wire prepares (#613)
Why:
Four runtime defects affect Helios scheduling, KV cache accounting, CUDA resource teardown, and tensor-parallel wire transport:
1. On cores declaring `GraphKind::TerminalPrefill`, a non-terminal `GraphKind::Prefill` chunk skips trailing continuation layers and sets `request.deferred_prefill = true` until a `TerminalPrefill` graph completes. Previously, `resolve_prefill_kind`, `prefill_requires_terminal_completion`, `plan_checkpoints`, `complete_inner`, `allocate_terminal_capture`, `RefreshStart` filtering, and `resize_prefill` ignored `request.deferred_prefill` when remaining tokens fit in a smaller regular `Prefill` graph outside `terminal_prefill_catalog`. A dynamically selected checkpoint cut or short prompt tail could therefore run regular `Prefill` while `deferred_prefill` remained true, publishing prefix checkpoints missing continuation state and entering `Decode` with `deferred_prefill` permanently set. `CheckpointReservation.tla` did not model `deferred_prefill`.
2. In `RequestScheduler::refill_reservations`, held KV pages were counted as `private_pages.len() + reserved_pages.len()`, omitting `shared_pages.len()` (unlike `pages_through` and `admit`). A growable decoding request holding cached prefix pages that reached `limits.pages` was treated as starved instead of at the physical pool ceiling, triggering spurious preemption of active decoders and readmission failure with `AdmissionError::Context` for streaming requests.
3. In `NativeModel::drop`, `self.offload.reset()` and `self.engram.clear()` ran before `rank.release_execution_resources()` stopped persistent workers and synchronized CUDA contexts, risking deadlock or use-after-free against host slabs and staging buffers; `prepare_offload` and pool registration bound the primary context instead of `execution_context()` (`compute_context` under green-context partitions); and `Event::drop`, `PinnedHost::drop`, and `Stream::drop` did not bind or restore their allocating CUDA context, silently failing and leaking pinned host memory when dropped on another thread.
4. `wire::prepare` splits >64 MiB uploads across `PREPARE_MORE` and `PREPARE` packets, but `wire::receive_prepare` appended fragments without coalescing. Peer ranks rejected split logprob gate/count/ID uploads in `transport::validate_uploads` and silently truncated split Engram `table.hashes` uploads via `.find(...)` in `engram.rs`. In addition, `TensorParallelExecutor::poll` and `ThreadedExecutor::poll_ranks` only selected `agree_speculative` for `GraphKind::Speculative`, omitting speculative `GraphKind::Mixed` graphs (`token_capacity > 1`).
What exactly changed:
- Deferred prefill & checkpoint safety (`helios/src/scheduler.rs`, `helios/src/scheduler/checkpoints.rs`, `helios/src/scheduler/policy.rs`, `verification/helios-lifecycle/CheckpointReservation.{tla,cfg}`, `verification/helios-lifecycle/check.py`, `verification/helios-lifecycle/README.md`, `helios/src/scheduler/checkpoint_lifecycle_tests.rs`, `helios/src/scheduler/policy_tests.rs`):
- `resolve_prefill_kind` now returns `GraphKind::TerminalPrefill` when `request.deferred_prefill` is true and a candidate step reaches `next_stop` or enters the tail window, even for capacities outside `terminal_prefill_catalog`.
- `prefill_requires_terminal_completion` now requires terminal completion whenever `request.deferred_prefill` is true and remaining work fits in `terminal_prefill_catalog.last()`.
- `plan_checkpoints`, `allocate_terminal_capture`, and `complete_inner` refuse to arm, allocate, or capture checkpoints while `deferred_prefill` remains set after the step.
- `select_plan` (`RefreshStart`), `available_plan`, and `resize_prefill` now enforce `prefill_requires_terminal_completion` and resize against `terminal_prefill_catalog` when terminal completion is required.
- Extended `CheckpointReservation.tla` (`MaxFence = 3`, 16-integer projection) with `deferred` request state, `DeferredHasNoReadyCapture`, `DeferPrefill`, `ArmAndProduceTerminal`, and `CompleteTerminal`, plus Rust conformance and TLA+/Rust mutation coverage. Updated `retiring_boundary_capture_stamps_terminal_start_and_resuming_capture_leaves_it_unset` and added `deferred_prefill_requires_terminal_prefill_for_small_cuts_refresh_and_decode`.
- KV page accounting (`helios/src/scheduler.rs`, `helios/src/scheduler/tests.rs`):
- Included `request.shared_pages.len()` in `held` inside `refill_reservations` and added `growable_request_with_shared_prefix_longer_than_pool_finishes_instead_of_preempting`.
- CUDA teardown and context RAII (`helios/src/runtime_core/model.rs`, `helios/src/runtime_core/memory.rs`, `helios/src/runtime_core/mod.rs`, `helios/src/cuda.rs`):
- Reordered `NativeModel::drop` so Phase 1 runs `rank.release_execution_resources()` across all ranks first, then calls `self.offload.reset()` and `self.engram.clear()` only if every rank drained (retaining them via `mem::forget` alongside undrained ranks otherwise), followed by Phase 2 `rank.release_reservations_and_context()`.
- Moved `GreenContextPartition::destroy_green_contexts` from Phase 1 to Phase 2 so compute green contexts remain live while offload host registrations and handles unregister.
- Updated `prepare_offload` and pool registration to pass `rank.execution_context()`.
- Recorded the allocating CUDA context on `Stream`, `Event`, and `PinnedHost`, added `Driver::with_context`, bound/restored context on `Drop` and `Stream::destroy`, and added GPU test `pinned_host_event_and_stream_release_when_dropped_on_another_thread`.
- Wire prepare coalescing and Mixed speculative agreement (`helios/src/execution/parallel/wire.rs`, `helios/src/execution/transport.rs`, `helios/src/execution/parallel.rs`, `helios/src/execution/threaded.rs`, `helios/src/execution/parallel/tests.rs`):
- Coalesced contiguous same-buffer fragments in `wire::receive_prepare` and updated `transport::validate_uploads` to slice `logprob_token_ids` by offset range inside covering uploads.
- Shared `uses_speculative_agreement` across `TensorParallelExecutor::poll` and `ThreadedExecutor::poll_ranks` to apply `agree_speculative` to both `GraphKind::Speculative` and `GraphKind::Mixed` with `token_capacity > 1`.
- Updated `prepare_packets_preserve_large_and_partial_uploads_on_both_transports` and added `receive_prepare_coalesces_split_uploads_across_64mib_packet_boundaries` and `speculative_agreement_applies_to_speculative_and_speculative_mixed_graphs`.
Claimed benefit:
Prevents corrupted prefix checkpoints and stuck `deferred_prefill` state on `TerminalPrefill` cores, prevents spurious preemptions and `AdmissionError::Context` failures on growable decoders reusing cached prefixes, prevents teardown UAF/deadlock and cross-thread pinned-host leaks during CUDA shutdown, and prevents >64 MiB prepare-upload truncation and unchecked speculative `Mixed` peer divergence.
Supporting evidence and limitations:
- Helios CPU unit suite on rebased `origin/main` (`f7256584`): `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target --lib -- scheduler:: execution::parallel::tests:: execution::threaded::tests:: execution::tests:: cuda::tests:: runtime_core:: engram:: offload::` passed (`709 passed, 0 failed, 30 ignored`).
- Flare library suite on rebased `origin/main`: `cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target` passed (`242 passed, 0 failed, 4 ignored`).
- CUDA cross-thread drop tests on RTX PRO 6000 Blackwell (GPU 0): `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target --lib -- --ignored cuda::tests::pinned_host_event_and_stream_release_when_dropped_on_another_thread cuda::tests::host_registration_unregisters_when_dropped_on_another_thread` passed (`2 passed, 0 failed`).
- Formal lifecycle verification and mutation suite (`python3 verification/helios-lifecycle/check.py --tlc-jar /home/luke/.cache/flare-formal/tla2tools-1.7.4.jar --target-dir flare-cli/target --mutations`, run against the same scheduler/TLA+ diff prior to rebasing onto Selene-only commits): passed all 9 TLA+ models + `Speculation16.cfg` (`CheckpointReservation.tla`: 502,765 states generated, 45,448 distinct), all 8 observed-edge Rust conformance suites (40 observed transitions for `CheckpointReservation.tla`), all 12 auxiliary tests, and all TLA+ and Rust mutations (including `DeferredHasNoReadyCapture`, `deferred prefill terminal capture bypass`, and `deferred prefill small cut bypass`).
- Unrelated pre-existing failures observed during broader runs: `helios` `model::tests::packed_combined_budget_keeps_width_one_batches_without_a_useful_packed_shape` and `flare-cli` `distribution::tests::source_waits_for_receiver_file_verification` (broken pipe after 130s).
- Limitations: live exported-core serving with persistent workers + host offload teardown, multi-GPU TP `GraphKind::Mixed` collective execution, and cross-host >64 MiB socket Engram runs were not executed in this pass.
Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: Luke Alonso <lalonso@gmail.com>1 parent 9a054b4 commit 0c25e88
19 files changed
Lines changed: 888 additions & 113 deletions
File tree
- helios/src
- execution
- parallel
- runtime_core
- scheduler
- verification/helios-lifecycle
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
351 | 371 | | |
352 | 372 | | |
353 | 373 | | |
| |||
677 | 697 | | |
678 | 698 | | |
679 | 699 | | |
| 700 | + | |
680 | 701 | | |
681 | 702 | | |
682 | 703 | | |
| |||
743 | 764 | | |
744 | 765 | | |
745 | 766 | | |
| 767 | + | |
746 | 768 | | |
747 | 769 | | |
748 | 770 | | |
| |||
774 | 796 | | |
775 | 797 | | |
776 | 798 | | |
| 799 | + | |
777 | 800 | | |
778 | 801 | | |
779 | 802 | | |
| |||
848 | 871 | | |
849 | 872 | | |
850 | 873 | | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
851 | 883 | | |
852 | 884 | | |
853 | 885 | | |
| |||
857 | 889 | | |
858 | 890 | | |
859 | 891 | | |
| 892 | + | |
860 | 893 | | |
861 | 894 | | |
862 | 895 | | |
| |||
878 | 911 | | |
879 | 912 | | |
880 | 913 | | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
881 | 923 | | |
882 | 924 | | |
883 | 925 | | |
884 | 926 | | |
885 | 927 | | |
886 | 928 | | |
887 | 929 | | |
| 930 | + | |
888 | 931 | | |
889 | 932 | | |
890 | 933 | | |
| |||
1059 | 1102 | | |
1060 | 1103 | | |
1061 | 1104 | | |
1062 | | - | |
1063 | | - | |
1064 | | - | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1065 | 1116 | | |
1066 | 1117 | | |
1067 | 1118 | | |
| |||
1272 | 1323 | | |
1273 | 1324 | | |
1274 | 1325 | | |
| 1326 | + | |
1275 | 1327 | | |
1276 | 1328 | | |
1277 | 1329 | | |
| |||
1310 | 1362 | | |
1311 | 1363 | | |
1312 | 1364 | | |
1313 | | - | |
1314 | | - | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
1315 | 1378 | | |
1316 | 1379 | | |
1317 | 1380 | | |
1318 | 1381 | | |
1319 | 1382 | | |
1320 | 1383 | | |
| 1384 | + | |
1321 | 1385 | | |
1322 | 1386 | | |
1323 | 1387 | | |
| |||
1336 | 1400 | | |
1337 | 1401 | | |
1338 | 1402 | | |
1339 | | - | |
1340 | | - | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
1341 | 1419 | | |
1342 | 1420 | | |
1343 | 1421 | | |
| |||
1346 | 1424 | | |
1347 | 1425 | | |
1348 | 1426 | | |
1349 | | - | |
1350 | | - | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
1351 | 1437 | | |
1352 | 1438 | | |
1353 | 1439 | | |
| |||
1694 | 1780 | | |
1695 | 1781 | | |
1696 | 1782 | | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
1697 | 1863 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
381 | | - | |
| 381 | + | |
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
502 | 507 | | |
503 | 508 | | |
504 | 509 | | |
| |||
0 commit comments