Skip to content

fix: keep the reload readiness pipe private to the app and safe across restarts - #58

Merged
AdamMusa merged 2 commits into
mainfrom
fix/run-reload-ready-pipe-hardening
Nov 2, 2026
Merged

AdamMusa merged 2 commits into
mainfrom
fix/run-reload-ready-pipe-hardening

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Depends on #57. This branch is stacked on #57's approved head (5f38b63b). #57 itself is unchanged, and the only new commit here is a7f4ff94.

Three QA follow-ups to the readiness pipe that #57 introduced.

1. The ready fd and env var leaked into processes the app spawns while booting

ruflet run maps the pipe to fd 3 of the app child, which has no close-on-exec, and sets RUFLET_READY_FD. The harness took them only after loading the app, so anything the app started during load inherited the open pipe and saw the variable. Such a process could write "ready" early, and a reload would then kill the booting app. A probe confirmed this: a subprocess spawned during load reported inherited env="7".

Fix. Runner#claim_ready_fd runs at the very start of Runner#run, before the app script loads. It takes the fd, sets close_on_exec = true, and deletes RUFLET_READY_FD. signal_ready then writes to that IO and closes it.

2. Test for dropping a queued reload on "R"

#57 resets a reload queued during boot when the app is respawned. A new test now covers it: "r" during boot is queued, then "R", then the respawn. The test checks that the pending flag is cleared, and that no reload signal reaches the new app once it reports ready. A fresh "r" then reloads the restarted app (L2).

3. "r" between "R" and the respawn ended the key reader (pre-existing)

Once the app had reported ready, "R" left it marked ready. An "r" before the respawn sent USR1 to the reaped pid, got ESRCH, and returned false, which ends start_reload_input_thread. After that no key worked for the rest of the session.

This reproduces on #57's head with $SP/team/qa-logs/dev-wave4/r_after_restart_repro.rb:

R => true
r between R and respawn => false (start_reload_input_thread breaks: no key works for the rest of the session)

Fix. "R" now calls mark_restarting, which marks the app not-ready and clears any queued reload under the readiness lock before it sends TERM. While a restart is pending, "r" prints "Restart in progress: the restarted app loads the current code", because the respawned process loads the current files anyway, and the key reader stays alive. The reload signal goes through one send_reload_signal method, and the ready-watcher thread is kept in run_state[:ready_thread], so tests can wait on events instead of time.

Tests (deterministic, pipe/FIFO readiness only)

  • hot_reload_test.rb#test_processes_spawned_while_the_app_loads_do_not_inherit_the_ready_fd: the app script runs a real subprocess probe while loading. It must report closed env=nil, and the runner must still send its ready byte. This failed on fix: queue a hot reload requested while the app is still booting #57's head with inherited env="7".
  • run_command_test.rb#test_restart_drops_a_reload_queued_during_boot (item 2).
  • run_command_test.rb#test_r_between_restart_and_respawn_keeps_the_key_reader_alive (item 3). It checks that "r" returns true, prints the restart message, and sends no signal, and that "r" works again once the app is back.

Both CLI tests use #57's FIFO-gated real-harness app and a signal-spy runner, and they wait on ready_thread.join and FIFO reads, with no sleeps. They error on #57's head, because the hooks don't exist there; the behavioural evidence is the repro above.

Proof

  • 30 consecutive passes at this head (a7f4ff9) of the 3 CLI boot/restart tests plus the 3 harness ready-fd tests. An engine flutter test loop and the ruflet_core suite loop ran alongside (1-minute load average 32–72). Log: hardening_proof.log.
  • verify_pr.sh with RUBY_PKGS="ruflet_core ruflet ruflet_server": ruflet_core 145/145, ruflet 13/13 (166 runs), ruflet_server 11/11. PASS.
  • Merges cleanly with test: signal the reload child only after it has booted #56.

QA follow-up 2

@AdamMusa
AdamMusa merged commit 2c7349a into main Nov 2, 2026
12 checks passed
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