Skip to content

fix(execution): let one process at a time follow the runs in a runs folder - #263

Merged
harenome merged 1 commit into
ThinkFlowLab:mainfrom
harenome:fix/one-server-per-profile
Nov 20, 2026
Merged

harenome merged 1 commit into
ThinkFlowLab:mainfrom
harenome:fix/one-server-per-profile

Conversation

@harenome

@harenome harenome commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #257

What

execution.restore now takes an exclusive, non-blocking fcntl.flock on <runs folder>/.lock and holds it until the process ends. It takes it before it reads a record. A second process on the same runs folder gets execution.Followed. app.py turns that into one line and exit status 1:

nullius: another Nullius follows the runs in /home/me/.local/share/nullius/runs: stop it before starting this one

The kernel releases the lock when its process ends, however it ends, so a crash leaves nothing to clean up. A second restore in the same process reuses the lock it holds. app.py now calls restore before it opens or creates a workspace, so a refused start writes nothing. With --debug, the reloader's watcher process runs main too. It now leaves the runs to the server process it starts (werkzeug.serving.is_running_from_reloader). Before this change, both of those processes resumed the runs (read from the code, not run).

The second server is refused. It does not start read-only. A server that does not follow the runs would still show them, take Stop and Continue on records it does not follow, and start new runs that only it knows of. Each of these needs its own guard. A refusal keeps one writer for every run.json, and the message says what to do. The lock is on the runs folder, not on the profile, because the runs folder is what two processes share: two profiles with one RUNS_DIR are refused too. The suite's modules, each with its own temporary runs folder, do not block each other.

Windows is not a target: execution already imports fcntl through nullius.standard, and runs are POSIX shell scripts.

Touches

backend (nullius/execution.py) · app/app.py · docs (docs/builder.md) · tests

Verified

In a rootless Podman container (python:3.12, with uv for the Harbor build fixtures):

  • python3 app/tests/parallel.py: 3107 tests in 158 modules, OK.
  • pip install -r app/requirements.txt, then python3 app/tests/parallel.py app/ui_tests: 560 tests in 57 modules, OK.
  • New test, tests/test_execution_recovery.py, Restart.test_a_second_process_on_one_runs_root_resumes_nothing. It records a running part, lets the first process go, and starts two processes that each call restore on the same root. One resumes the run, and the other is refused. The log says "Nullius is back" once, and the next part is launched once. After both processes end, a restore in the test process is not refused. On main, it fails: both processes resume the run, and each log line appears twice.
  • New route test, ui_tests/test_run_routes.py, ReopenAtStart.test_a_second_server_on_the_runs_folder_stops_with_one_line: the start exits with the message, and --debug in the reloader's watcher calls no restore.
  • The issue's test (test_execution_two_instances.py) passes on this branch.
  • By hand, in the container: with python3 app/app.py --port 5099 running, a second python3 app/app.py --port 5098 printed the line above and exited 1. With python3 app/app.py --debug --port 5097 running, the page answered 200 and a second server was refused.

Not checked: a second server started while a live host run is followed.

Risk

  • A runs folder on a file system without flock support (some network mounts) may refuse every start, or lock nothing. A runs folder that cannot be created takes no lock, as before, when there was nothing to restore.
  • A user who ran two servers on one profile on purpose now gets a refusal. Each server needs its own NULLIUS_HOME or RUNS_DIR.
  • To undo, revert the commit. The .lock file left in the runs folder is ignored: a run name cannot start with a dot.

…older

Two Nullius processes on one profile both resumed every live run: the
run log held each line twice and both wrote run.json. restore now holds
an flock on the runs folder's .lock for the rest of the process, and a
second nullius serve on that folder stops with one line. The lock goes
with the process. With --debug, the reloader's watcher leaves the runs
to the server it starts.
@harenome
harenome force-pushed the fix/one-server-per-profile branch from 77a0ff4 to 50b5e7a Compare November 20, 2026 13:16
@harenome
harenome merged commit 593e2ca into ThinkFlowLab:main Nov 20, 2026
2 checks passed
@harenome
harenome deleted the fix/one-server-per-profile branch November 20, 2026 13:20
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.

Execution: two Nullius processes on one profile both resume the same run

1 participant