tools: harden stage_timeline.py parsing, OSError handling and stdout guard #1789
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1789"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T12:11:57Z.
Claimed in the coordination issue as: STAGE-TIMELINE-STDOUT-GUARD-AND-PARSER-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162011238)
What and why
sys.stdout.reconfigure(errors="replace")guard intools/stage_timeline.py's__main__block so redirected Windowspython -Iruns do not failtests/test_tool_stdout_encoding.py(tools/stage_timeline.pyis removed frommissing).PRESStimestamp regex ([0-9]+(?:\.[0-9]+)?) and makefirst_value()returnNonesafely for empty strings, leading commas (e.g.,1234), partial?hex tokens, or non-hex values instead of raisingValueError.encoding="utf-8-sig", errors="replace"and catchOSErrorinmain()to print a concise error line to stderr and return exit code2instead of a traceback.p["game"] == 3before reporting"story load (loading screen ended)"intimeline().tests/test_stage_timeline.py.Tested
python -I tests/test_stage_timeline.py -v->Ran 7 tests in 0.146s,OK(verified in a detachedupstream/mainworktree that the new test file fails before the fix:FAILED (failures=4, errors=2)).python -I tests/test_tool_stdout_encoding.py->tools/stage_timeline.pyis no longer inmissing(only pre-existing['tools/compute_heap_layout_census.py']fails).python -I tests/test_ci_registration.py->Ran 16 tests in 4.545s,OK.python -I tests/test_text_write_line_endings.py->Ran 3 tests in 12.772s,OK.python -I scripts/check_no_game_data.py tools/stage_timeline.py tests/test_stage_timeline.py-> exit0.python -I -m compileall -q tools/stage_timeline.py tests/test_stage_timeline.pyandgit diff --check-> clean.GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)
AI-assisted: yes
Checklist
needs rebase).Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T19:16:52Z.
Reviewed
dacbc165:python -I tests/test_stage_timeline.pypasses on the PR tree (7/7); on main 6/7 fail (first_value crash on empty/mid-? hex, float('.') press stamps, traceback on an unreadable log), so the tests pin the fix. A probe on both trees reproduced the main-side crashes the PR removes and found no input the PR handles worse; the tightened PRESS regex only stops accepting a trailing-dot timestamp the emitter (%.1f) never writes. The game==3 "ended" gate matches the documented state table but needs a real boot log to confirm.AI-assisted review.
Recommendation: Merge
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:04:39Z.
#1789 | head
dacbc16566(merged cleanly with maind48a957bb) |python -I tests/test_stage_timeline.py| red on main:FAILED (failures=3, errors=2)(ValueErroron empty/malformed hex/press fields, false loading-ended transition whengame != 3, and rawOSErrortracebacks) | green on PR+main:7 tests OK| Windows 11, Python 3.12.10 | AI-assisted: yesAudited
PRESS,first_value,read,timeline, andmainintools/stage_timeline.pyandtests/test_stage_timeline.py(rejecting bare./ multi-dot timestamps, empty or partial-?hex heads, requiringgame == 3before reportingstory load (loading screen ended), readingutf-8-siglogs, returning exit2without tracebacks on missing/directory paths, and guardingstdout.reconfigureunder-Ion Windows). Also verifiedtests/test_ci_registration.py(18 OK),tests/test_runner_calls_all_tests.py(3 OK),tests/test_text_write_line_endings.py(3 OK), andscripts/check_no_game_data.py.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:58:51Z.
Red/green: classified READY by cloud-4 (red on main
09c153948, green on head merged with main); headdacbc16566unchanged since 2026-11-25, before that run.Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)