Skip to content

launcher: the output pump takes a bounded batch a turn, so the window answers with -Log off (LAUNCHER-OUTPUT-PUMP) - #3192

Open
1mshy wants to merge 1 commit into
ProjectLeonida:mainfrom
1mshy:fix/launcher-output-pump
Open

1mshy wants to merge 1 commit into
ProjectLeonida:mainfrom
1mshy:fix/launcher-output-pump

Conversation

@1mshy

@1mshy 1mshy commented Dec 2, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: LAUNCHER-OUTPUT-PUMP

Fixes: #3175

What and why

With "Log to a file (-Log)" unchecked, the runtime's stderr comes through the launcher's pipe. Launcher.pump
(tools/leonida_launcher.py) drained the reader thread's whole queue in one Tk after callback, with an
insert and a see("end") per line. see("end") forces a layout pass, about 2.5 ms of the ~3 ms a line costs. Tk
could not handle clicks or redraw until the queue was empty: 30,000 queued lines held the window for 90 s, and while
the runtime wrote faster than about 400 lines/s the callback never returned. With -Log on, the pipe stays quiet,
which is why the launcher stayed responsive in that case.

  • New take_output(lines, limit=OUTPUT_BATCH): takes at most 2000 queue items per turn without waiting, in order,
    and joins each run of lines from one process into one item, so the output box gets one insert and one see per run.
  • pump() uses it. The status heuristic (state_for_line) is applied over the run and set once. A turn that leaves
    lines queued comes back after OUTPUT_RESUME_MS (10 ms) instead of 100 ms, so a backlog drains fast while clicks
    and redraws run between turns. Exit, update-check and stale-process handling are unchanged.

Tested

macOS, Python 3.13.5, Tk 8.6.14:

  • python -I tests/test_leonida_launcher.py: 28 tests OK (2 new: OutputPumpTests)
  • python -I tests/test_shell_launchers.py: 7 OK
  • python -I tests/test_launcher_serve.py: 10 OK
  • python -I tests/test_win_launchers.py: 6 run, 5 skipped (Windows-only)
  • python -I scripts/check_no_game_data.py (all tracked files): clean
  • python -m compileall -q make_game.py tools tests: OK
  • python -m unittest discover -s tests -p "test_docs_*.py": 57 OK

Red/green: python -I scripts/red_green.py fix/launcher-output-pump --base origin/main --no-cargo --mutate
reports red then green. Both new tests fail on main and pass with the fix; the other 24 pass on both. The mutation
pass catches undoing take_output. It does not catch undoing the pump() hunk, because Launcher is nested in
run_gui() and can't be reached without a display. A Tk benchmark (below) covers that.

Tk measurement (real Text widget set up like the output box; a 5 ms timer stands in for a click):

Queued lines Before: longest turn / timer late by After: longest turn / timer late by / drained in
2,000 5.9 s / 5.9 s —
30,000 89.4 s / 90 s 5 ms / 13 ms / 0.23 s
300,000 — 8 ms / 14 ms / 2.3 s
30,000 into a box already holding 200,000 — 5 ms / 11 ms / 0.23 s

The independent reviewer reproduced these figures. It also ran a live producer: before, 1,000 lines/s gave one
7.4 s turn; after, at 50k–300k lines/s, turns stay at 4–6 ms and the timer is at most 20 ms late.

Not run: Windows (Launcher.bat) by hand. The fix is platform-independent Tk/queue code, but nobody has clicked the
real launcher on Windows with the game.

GPUs tested: n/a (launcher UI only, no GPU work)

AI-assisted: yes. Work: Claude Opus 5.5 (claude-opus-5-5). Independent read-only reviewer: Claude Opus 5.5
(claude-opus-5-5); no blockers. Its nits (a line over 120 characters, commit-message precision) are applied.

Checklist

  • Based on current main (45dc41f) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md — n/a, no translator change.

…r run

With "Log to a file (-Log)" off the runtime's stderr comes through the
launcher's pipe. Launcher.pump drained the reader thread's whole queue in
one Tk callback with an insert and a see("end") per line; see("end")
forces a layout pass (about 2.5 ms), so a line cost about 3 ms. The
window answered no click and drew nothing until the queue was empty:
30,000 queued lines held it 90 s, and while the runtime wrote faster than
about 400 lines a second the callback never returned (ProjectLeonida#3175).

take_output() now hands a turn at most OUTPUT_BATCH (2000) items, with
each run of lines of one process joined into one insert (one see), and a
turn that leaves more queued comes back after 10 ms instead of 100 ms.
Measured with Tk 8.6 on macOS: the longest turn is 5-8 ms, a repeating
5 ms timer is at most 14 ms late while 300,000 lines drain (2.3 s), and a
box already holding 200,000 lines changes neither.

Fixes ProjectLeonida#3175.

AI-assisted: Claude Opus 5.5 (claude-opus-5-5); review: Claude Opus 5.5.
@fiestorra

Copy link
Copy Markdown
Contributor

Verified here: it applies on the current main, its two new tests pass, and the launcher suite is green - but the change carries something the body does not mention.

merge base 5b1fff821 (= current origin/main), head b713fdd8d
git apply on main   (9 files)

python -I tests/test_leonida_launcher.py    Ran 28 tests   OK

new, and they are the ones that matter:
  OutputPumpTests.test_a_turn_takes_at_most_the_batch_and_leaves_the_rest_queued
  OutputPumpTests.test_runs_are_joined_per_process_and_kept_in_order

The fix is the right shape for #3175: Launcher.pump drained the reader thread's whole queue inside one Tk after callback, with an insert and a see("end") per line, so a chatty runtime (stderr with -Log off) starved the event loop. A bounded batch per turn is the standard answer, and the two tests pin exactly the property that makes it one - a turn takes at most the batch and leaves the rest queued, and runs stay joined per process and in order.

What the body does not mention: the same diff changes precompile_all's default from False to True and rewrites switch_args to emit -PrecompileUsed when it is off - that is #3172's territory, not #3175's, and a reviewer reading "the output pump takes a bounded batch" will not expect it. It may be a deliberate follow-up to #3172 (which merged today); if so it deserves its own line in the body, and if it is drift, it deserves its own pull request.

What I could not test: the unresponsiveness itself. That needs the launcher's window with a runtime writing to a pipe, and this session has no interactive desktop - the tests hold the batch logic, not the event loop it protects.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

MoonEyes commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Third-party verification of #3192 (LAUNCHER-OUTPUT-PUMP, fixes #3175)

Tested here (Linux, Python 3.13.18, detached checkout of the head, which equals the merge with main):

python3 -I tests/test_leonida_launcher.py                  Ran 28 tests OK
python3 -I tests/test_shell_launchers.py                   Ran 7 tests OK
python3 -I scripts/check_no_game_data.py tools/leonida_launcher.py tests/test_leonida_launcher.py   rc=0
python3 -m compileall -q tools/leonida_launcher.py tests/test_leonida_launcher.py                   rc=0
python3 -m unittest discover -s tests -p "test_docs_*.py"  Ran 57 tests OK

Red/green, python3 -I scripts/red_green.py pr/3192 --base origin/main --no-fetch --no-cargo --mutate:

red then green (2): OutputPumpTests.test_a_turn_takes_at_most_the_batch_and_leaves_the_rest_queued
                    OutputPumpTests.test_runs_are_joined_per_process_and_kept_in_order
pass on both: 24
mutations: tools/leonida_launcher.py:464 caught, tools/leonida_launcher.py:793 not caught
verdict: red then green

As the PR says, nothing tests the pump() hunk (Launcher is nested in run_gui()). This machine has no tkinter, so I could not reproduce the Tk timings.

Review

  • take_output (tools/leonida_launcher.py:471) keeps queue order and joins runs by process identity (is). Non-line items (exit, update) split runs, so ordering relative to an exit is preserved.
  • pump() (tools/leonida_launcher.py:792): the per-run state_for_line fold gives the same final state as the old per-line calls. Calling set_state only on a change is equivalent because set_state only sets self.state and status_var. The rescheduling at :817 (10 ms while the queue is non-empty, else 100 ms) is sound. The exit and stale-process handling is unchanged.
  • Not a defect of this PR: the output Text widget still grows without bound over a long -Log-off session (pre-existing).

Defects

  1. Missing claim in Coordinating who works on what (continued from #1608) #2570 (Maintainer quick guide: "It is claimed in the coordination issue by the pull request's author"). The author should post claiming: LAUNCHER-OUTPUT-PUMP / done: LAUNCHER-OUTPUT-PUMP -> #3192 there.

Verdict: defects (claim only). The code is correct, small and on one topic; red then green confirmed here. It is ready once the claim is posted. A Windows Launcher.bat click-through with -Log off would still be useful.

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

@lixonik

lixonik commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Verified PR #3192 (b713fdd8d) merged cleanly onto main (f1a559851) on Windows 10 x64:

  • Clean-room check: python -I scripts/check_no_game_data.py PASS.
  • Green (merged b713fdd8d onto f1a559851): python -I tests/test_leonida_launcher.py -- 28 tests, OK (0.267 s).
  • Red -> Green proof (main tools/leonida_launcher.py + PR tests/test_leonida_launcher.py): FAILED (errors=2) on the two new output-pump batch tests.

Verdict: PASS (Python unit tests; no game launch).

AI-assisted: yes (Antigravity).

@Kal0s-design

Copy link
Copy Markdown
Contributor

Ran natively on Windows 11, head b713fdd8d merged into current main (8d82a34ae, clean merge). Python 3.11 with Tk 8.6.

The unit tests are already covered above, so briefly: the launcher test file has 26 tests on main and 28 on the merge, all green, and the two new OutputPumpTests error on main's launcher. Same result as the others.

What nobody could run yet is the part the PR is about, the Tk event loop. Tk is available here, so I ran the real pump, append, read_output and set_state bodies (pulled from the file on each side, not rewritten) against a Text set up like the launcher's output box (word wrap, Consolas 9, scrollbar). Output came from a throwaway Python child writing to the pipe, never the game. A 5 ms after heartbeat measured how long the window went without getting a turn.

Measured, PR vs main

child output PR: longest turn / longest heartbeat gap main: same text identical to child output, exit line last
100k short lines 5 ms / 29 ms, done in 0.9 s 44 to 51 s in one turn (two runs), window frozen yes on both
5000 lines of 4 KB 19 ms / 34 ms ~44 s in one turn (measured with a plain Text, before I matched the launcher's) yes on both
5 \r progress runs of 20k each, then 1000 lines 66 ms / 81 ms still stuck in the first turn when I stopped it, minutes later yes (PR)
2 s of writing flat out (2.78M lines) 76 ms / 136 ms, done ~22 s after the child exited still stuck in the first turn after 3 minutes, stopped yes (PR, checked line by line)
50k lines with invalid UTF-8, last line without newline 51 ms / 67 ms ~51 s in one turn yes on both

On main the window does not get a single event until the whole backlog is in the box. With the PR it keeps answering the whole time. Take the absolute numbers as rough; the difference is three orders of magnitude.

Ordering and exit (measured). In every case the box text matched the child's bytes split on \n and decoded with errors="replace", plus Exited with code 0. at the very end. Nothing was lost, duplicated or reordered. The unterminated last line arrives at EOF. The exit line only shows up after the whole backlog has been drawn, since read_output queues exit after EOF and take_output keeps queue order.
Limits worth knowing (not defects of this PR)

  • The batch counts items, not bytes. With 2000 lines of 4 KB already queued, one turn took 237 ms (measured). Still far better than before, but a run with very long lines can stutter.
  • The queue is an unbounded queue.Queue() (read). A child that writes faster than the box draws just makes it grow. Measured: the 2 s flat-out writer peaked at about 2.7M queued items, which then drained at roughly 120k lines/s while the window kept answering. So the window stays usable, but a runtime that spams for minutes leaves a long tail. I did not measure process memory.
  • readline only splits on \n (read), so \r-only progress lines show up as one line when the next \n arrives. Same as on main.
  • The Text widget itself still grows without limit, as already noted above.

Correction to the first comment. The diff against current main is 2 files, tools/leonida_launcher.py and tests/test_leonida_launcher.py, with only the pump change. There is no precompile_all or switch_args change in this head (measured with git diff).

Other open PRs touching tools/leonida_launcher.py (git merge-tree against the PR head)

PR result note
#3182 (launcher overhaul) conflict in pump() Keeps the old drain-everything loop and adds info and rail kinds (read). It does not replace the pump, so whoever merges second has to keep the bounded loop or #3175 comes back. take_output passes non-line kinds through unchanged, so the new kinds fit as they are.
#3209 (custom parameters) conflict in pump() Adds a per-line check for F1 settings applied. (read). With runs joined into one item, that check has to move into the for line in value loop, or it misses lines in the middle of a batch.
#3130 clean
#2958 clean

Not checked: a real Launcher.bat click-through with -Log off and the actual runtime, the full Launcher window (I tested the pump methods with a matching output box and stubbed status widgets), process memory, Linux/macOS Tk.

GPUs tested: n/a (Python launcher tests only).

AI-assisted: yes (Claude Code).

OreoFR added a commit to OreoFR/leonida that referenced this pull request Dec 2, 2026
…menu's console

Two review findings by merzleckeier on ProjectLeonida#3182.

Output pump (on dafad4c): the window's pump drained the whole output queue and
appended once per line, so a run that floods the pipe (the runtime's stderr with
-Log off, ProjectLeonida#3175) could freeze the window. Ported the design and names of ProjectLeonida#3192
by 1mshy: OUTPUT_BATCH = 2000, OUTPUT_RESUME_MS = 10 and a pure take_output()
that joins each run of one process's lines into one ("lines", proc, [...]) item,
keeps exit/update/info/rail items in order and leaves the rest queued; one
insert per run, rescheduled after 10 ms while more is queued. The overhaul's
info, rail and finished() handling is kept. ProjectLeonida#3192's two OutputPumpTests ported
(with info and rail items), plus 10,001 lines = one insert a turn and a check
that the pump goes through take_output.

Low-commit warning (on 7768d10): the Play card's warning took the profile from
the launcher's settings alone, while play-d3d12.ps1 -Chosen / play-nvidia.ps1
("What the F1 menu saved") let the F1 menu's LEONIDA_MENU_CONSOLE win when the
launcher's profile has not changed since the last PLAY (and at the first PLAY,
-Chosen none). New pure effective_console(settings, menu) with that order; the
Play card's line uses it and is refreshed when the F1 file is read again (focus,
finished()). The Settings note keeps following the live control; the existing
"F1 menu: Series X" note under the profile says when the menu holds another.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fiestorra

Copy link
Copy Markdown
Contributor

VERIFY-3192 — Windows nativo: red then green en el bombeo de la salida

Own commit b713fdd8d — tools/leonida_launcher.py (+76), tests/test_leonida_launcher.py (+35)

Ran at the head

python -I tests/test_leonida_launcher.py     Ran 28 tests — OK

Negative control: the commit's own hunk does not revert cleanly (the branch also carries a merged main on that file), so I put main's leonida_launcher.py back and re-ran:

Ran 28 tests — FAILED (errors=2)

It bites.

What the change is: the launcher's output pump takes a bounded batch per turn — instead of draining whatever is in the pipe — and makes one insert per run. Both halves are about a pump that runs every frame-ish: an unbounded drain starves the next turn, and an insert per line per turn with a run of lines grows without bound (the classic "the launcher is fine for ten minutes").

Why a bounded batch is the right shape: a pump that takes everything available is correct exactly as long as the producer is slower than the consumer — and a game's log is not.

What I could not test

  • A real launch with the pump under load: the tests drive the pump's bookkeeping; the title's log volume is the condition that matters.

Written with an AI assistant.

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.

Launcher.bat window becomes unresponsive when file logging is disabled

5 participants