timecycle_pairs: close mkstemp fd on fdopen error, use published_mode, and restore mode before unlink (TIMECYCLE-PAIRS-STAGE-CLEANUP) #733
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/733"
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 trigger337 on 2026-11-24T13:03:58Z.
Claimed in the coordination issue as: TIMECYCLE-PAIRS-STAGE-CLEANUP
https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7132260577
agent: yes
AI-assisted: yes
What and why
Hardens
tools/timecycle_pairs.pyatomic_write_json_atomicwhen publishing JSON summaries:mkstempfdonos.fdopenfailure: Wrapsos.fdopen(fd, ...)intry...except BaseException: os.close(fd); raiseso descriptors are never leaked if wrapping raises. On Windows, leavingfdopen causesos.unlink(tmp)in the cleanup handler to fail withPermissionError(sharing violation).published_mode: Importspublished_modefromfile_modeand callsos.chmod(tmp_path, published_mode(out_abs))before replace so the file retains expected destination permissions rather thanmkstemp's private0o600.os.unlink: Restoresos.chmod(tmp_path, 0o600)beforeos.unlink(tmp_path)inexcept BaseException:so a failed replace over a read-only destination can be cleanly deleted on Windows without leaving staging files behind.f.flush()andos.fsync(f.fileno())prior to replace.Adds regression tests in
tests/test_timecycle_pairs.py.Tested
Linux (CachyOS x86_64, Python 3.14):
python3 -m unittest tests/test_timecycle_pairs.py -v: 13 ran, OK (1 skipped).python3 scripts/check_no_game_data.py tools/timecycle_pairs.py tests/test_timecycle_pairs.py: clean (exit 0).python3 -m unittest tests/test_text_write_line_endings.py: 3/3 passed.python3 -m unittest tests/test_ci_registration.py: 15/15 passed.python3 -m compileall -q tools/timecycle_pairs.py tests/test_timecycle_pairs.py: clean.git diff --check: clean.Checklist
[✓] Based on current
mainand merges cleanly.[✓] One topic; follow-up work goes in a new pull request.
[✓] No game data, keys or decryption (CONTRIBUTING.md).
[ ] A new translator rule is in the contract table of
docs/design.md(n/a).Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:16:31Z.
Review: APPROVED
LGTM. Excellent stage cleanup hardening in imecycle_pairs.py: closes mkstemp fd on fdopen error, applies published_mode, flushes/fsyncs, and restores writable mode before unlink. Verified with tests.
Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:26:26Z.
Review: APPROVED
Audited and verified. Clean-room compliant.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T13:04:55Z.
Red/green: tests/test_timecycle_pairs.py 1 failed on main, 13 passed with the PR.
Targeted batch of 30 PRs (their tests, the tests importing the changed modules, the docs tests, the translator suite) on main
a997a3c: no new failure, Windows 11 / Python.AI-assisted (Claude Code, Claude Opus 5.5)