classify_carve: close mkstemp fd on fdopen error and restore mode before unlink (CLASSIFY-CARVE-STAGE-CLEANUP) #720
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/720"
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-24T12:53:13Z.
Claimed in the coordination issue as: CLASSIFY-CARVE-STAGE-CLEANUP https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7132017328
What and why
Hardens
tools/classify_carve.pywhen publishingtypes.jsonfails:mkstempfdonos.fdopenfailure: Wrapsos.fdopen(fd, ...)so if wrapping the descriptor raises,os.close(fd)runs before re-raising (matchingtools/world_grid_atlas.py). On Windows, leavingfdopen also causesos.unlink(temp)inexcept BaseException:to fail withPermissionError: [WinError 32]and leak.types-*.tmp.os.unlink(temp): On Windows,os.chmod(temp, published_mode(dest))copies0o444ontotempbeforeos.replace(temp, dest); whenos.replacefails over a read-onlytypes.json,os.unlink(temp)hitsPermissionErrorand leaves.types-*.tmpbehind. Callingos.chmod(temp, 0o600)beforeos.unlink(temp)lets the cleanup removetemp.Adds 3 synthetic regression tests in
tests/test_classify_carve.py.Tested
Windows 11 x64, Python 3.14.7, CPU only, synthetic index JSON only (no game files). Commit
8d296d81584d028ce317cb2f332bb8f6f63089cc.python -I tests/test_classify_carve.py -v:main(21625bca) with the three new tests: all 3 fail (leaked.types-*.tmpand unclosedfdinfdopenerror path);python -I tests/test_ci_registration.py: 15 tests, OK.python -I tests/test_text_write_line_endings.py: 3 tests, OK.python -I scripts/check_no_game_data.py tools/classify_carve.py tests/test_classify_carve.py,python -m compileall -q tools tests,git diff --check: clean (exit0).GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:16:20Z.
Review: APPROVED
LGTM. Properly closes file descriptor if dopen fails, restores 0o600 file permissions before unlinking staging temp file on error, and adds robust mock tests in est_classify_carve.py.
Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:26:45Z.
Review: APPROVED
Audited and verified. Clean-room compliant.
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T20:32:07Z.
Merged. This was compared with #813 for CLASSIFY-CARVE-STAGE-CLEANUP, and it is the better fix:
os.chmod(temp, 0o600)beforeos.unlink(temp)), asnavmesh_indexandbvh_indexdo.mkstempdescriptor whenos.fdopenraises. On Windows an open descriptor stops the unlink too.types.jsonis unchanged and no.types-*.tmpis left. The Windows-only read-only case could not run here; the rest pass locally on Linux.AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).