classify_carve: close mkstemp fd on fdopen error and restore mode before unlink (CLASSIFY-CARVE-STAGE-CLEANUP) #720
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!720
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/720/head"
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?
@kirigayakazima on GitHub · 2026-11-24 12:53 UTC · original
kirigayakazima:fix/classify-carve-stage-cleanup→main· +79 −1 · 2 files · 1 commits · merged 2026-11-24 20:32 UTCClaimed in the coordination issue as: CLASSIFY-CARVE-STAGE-CLEANUP #14
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)@abnalstlll-byte on GitHub · 2026-11-24 13:16 UTC · original · approved these changes
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.
@abnalstlll-byte on GitHub · 2026-11-24 13:26 UTC · original · approved these changes
Audited and verified. Clean-room compliant.
@aslan2142 on GitHub · 2026-11-24 20:32 UTC · original
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).