Skip to content

Keep web launcher job status tied to its process - #2798

Open
weeeeeeeeees1 wants to merge 1 commit into
ProjectLeonida:mainfrom
weeeeeeeeees1:fix/launcher-job-state-ownership
Open

weeeeeeeeees1 wants to merge 1 commit into
ProjectLeonida:mainfrom
weeeeeeeeees1:fix/launcher-job-state-ownership

Conversation

@weeeeeeeeees1

Copy link
Copy Markdown

Claimed in the coordination issue as LAUNCHER-JOB-STATE-OWNERSHIP.

What and why

The web launcher can accept a new job as soon as the previous child exits, while its output worker is still draining stdout. The previous worker could then overwrite the new job’s status or clear its kind.

This change passes the exact spawned process to its worker and checks process ownership under the launcher lock before publishing progress or recording an exit status. It also updates the current job’s kind and exit status together.

Tested

  • The stale-worker regression fails on main and passes with the fix. The current-worker test confirms exit status is still recorded.
  • On Windows, 12 web launcher, 15 launcher core, and 3 Windows launcher tests passed. The 7 shell launcher tests were skipped because they require a non-Windows host.
  • scripts/check_no_game_data.py and git diff --check passed.

GPUs tested: n/a. The tests use synthetic processes and do not launch the game.

AI-assisted: yes. OpenAI Codex (GPT-6) prepared the patch, and GPT-6.2 Astra independently reviewed the diff.

Checklist

  • Based on current main.
  • One topic.
  • No game data, keys or decryption.
  • No translator changes.

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head 6e317eadc, main 2878a3911. CPU only, no game.

MEASURED

  • Red (main + only this PR's tests/test_launcher_serve.py): 1 failed, 11 passed. The only failure is JobTests::test_old_follower_leaves_the_new_job_state_intact. test_current_follower_publishes_its_exit_status passes on main, as expected, since it guards the existing behavior.
  • Green (main + this PR, merged with merge-tree): 12 passed, 10 runs out of 10 (so no flakiness seen in the threaded tests).
  • Every launcher test file (test_launcher_serve, test_leonida_launcher, test_shell_launchers, test_win_launchers), main vs green: 33 → 35 passed, 2 skipped on both sides (test_win_launchers.py:42 and :99, which need PowerShell or cmd.exe). This includes the 7 shell-launcher tests you had to skip on Windows; they pass here on both sides.

READ IN CODE

  • The spawned process goes into a local variable first and is assigned to self.process only after spawn succeeds, so a failed spawn no longer leaves a half-set state behind. The worker gets that exact object, not self.process read again later.
  • set_state(process, …) and the exit path both check self.process is not process under self.lock, then update kind and job_state together inside the lock. A worker whose process has been replaced therefore neither publishes progress nor clears the new job's kind or state.
  • A stale worker still logs Exited with code N. through say(), and returns before _send("state"). Fine as is: the log line is accurate, and the new job has already sent its own state.

AI-assisted: Claude Code

@aegish-zagi

Copy link
Copy Markdown
Contributor

Verification — VERIFY-2798

Verdict: PASS

  • PR: Keep web launcher job status tied to its process #2798 | head sha: 6e317eadc1c5dc11b1b6ee802778e0b570ca88de | merge state vs main: clean merge with current main 5dd6d444f in a scratch worktree (merge commit e13280ac0), no conflicts. Diff: launcher/serve.py (+15/−5) and tests/test_launcher_serve.py (+36).
  • Tests run: python -I tests/test_launcher_serve.py
    • On PR (merged with main): 12 tests, OK
    • On plain main: 10 tests, OK
    • Red check (MEASURED): the PR's 12-test file run against main's unmodified launcher/serve.py FAILED (failures=1) — the new ownership case: an old follower clearing the new job's state ('' != 'play'). It passes with the fix: clean red→green.
  • Audit (READ IN CODE): set_state now takes the owning process and returns early under the lock when self.process is not process; the exit path in _follow makes the same ownership check before clearing kind/job_state; start captures the spawned process in a local and passes that exact object to its follower thread instead of re-reading self.process. The change is confined to the race described; no other launcher behaviour touched. No game data.
  • Platform: Linux, Python 3.12.3, no GPU.

AI-assisted: yes (Muse Wonder, Muse by Meta)

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state half is right and the test genuinely guards it: identity against the live Popen closes the race (launcher/serve.py:322-325, repeated on the exit path at :370-374), running() polls the same object, so there is no pid-reuse hole, and nothing is left behind on a crash. On origin/main a stale worker leaves kind='' state='Exited with code 7'; here it stays kind='play' state='Starting'. Real-process checks (immediate exit, kill, still running) behave as described, and the tests are 12 / 15 / 3 green.

One leak remains, and it is the same race in the log rather than the state:

  • _follow still calls self.say(f"Exited with code {code}.") before the ownership check (serve.py:369 vs :371), and the per-line self.say(line) at :362 is never gated. I reproduced it deterministically (holding the launcher lock so the old follower cannot finish draining): after the new job's > <command> header, the shared log received the old worker's old-a, old-b, old-c and Exited with code 0., while the state correctly stayed Starting. That line also feeds the page's log drawer and, as the last line, the log chip (launcher/index.html:596) — so the pill says "Starting" and the chip says "Exited with code 0." The Tk launcher already drops every event from a non-current process (tools/leonida_launcher.py:614-615); please gate the appends the same way (keep draining, drop the writes) and move the check ahead of the exit say.

Also: both new tests are Mock-based and neither asserts launcher.log — in the stale test the log is ['loading', 'Exited with code 7.'] even on this head, so the leak passes. assertNotIn("Exited with code 7.", launcher.log) fails today and would pin the fix.

Out of scope but worth a sentence: a restarted launcher forgets the job entirely (new Launcher reports Ready while the old child runs), since tracking is in-memory only — "tied to its process" holds for one launcher lifetime.

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent check of 6e317eadc merged onto bf30e2585. The three launcher suites passed 34 tests. I also tested a specific start-order case with stub processes. Job B begins while job A has spawned its process but has yet to create its output follower. Checking that each follower receives the process started by its own request extends the existing job-status coverage.

Using the verifier from #2817, reversing individual source edits in launcher/serve.py was detected in 4 of 8 cases with the original tests and 7 of 8 with that extra test_launcher_serve.py case. The test pauses thread creation deterministically and requires neither a game executable nor a timing delay.

AI-assisted with OpenAI Codex.

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.

5 participants