Conversation
…uglasmonsky#418) `with sqlite3.connect(...)` commits but does not close; the leaked handle makes the following os.replace fail with WinError 32 on Windows (POSIX is unaffected, so CI never caught it). Explicit close() before the rename/copy.
…uglasmonsky#418) `with sqlite3.connect(...)` commits but does not close; the leaked handle makes the following os.replace fail with WinError 32 on Windows (POSIX is unaffected, so CI never caught it). Explicit close() before the rename/copy.
…uglasmonsky#418) `with sqlite3.connect(...)` commits but does not close; the leaked handle makes the following os.replace fail with WinError 32 on Windows (POSIX is unaffected, so CI never caught it). Explicit close() before the rename/copy.
…uglasmonsky#418) `with sqlite3.connect(...)` commits but does not close; the leaked handle makes the following os.replace fail with WinError 32 on Windows (POSIX is unaffected, so CI never caught it). Explicit close() before the rename/copy.
…uglasmonsky#418) `with sqlite3.connect(...)` commits but does not close; the leaked handle makes the following os.replace fail with WinError 32 on Windows (POSIX is unaffected, so CI never caught it). Explicit close() before the rename/copy.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #418.
with sqlite3.connect(staging) as connection:commits but never closes theconnection.
sqlite3.Connectionsits in a reference cycle, so its file handleoutlives the block, and the following
os.replace(staging, target)then fails onWindows with:
POSIX allows renaming an open file, which is why Linux/macOS CI never caught this.
On Windows both
setupandrefreshfail deterministically and leave a partial.building-*file behind each time.Minimal standalone reproduction (no project code involved):
Change
12 explicit
close()calls across 5 files, each placed after thewithblock andbefore the staging file is renamed/copied:
kernel/database.pyos.replace) + validator / schema-header readerskernel/operational.pyos.replace)kernel/content.pyos.replace)kernel/ingest.pykernel/application/jobs.pycontextlib.closing(...)would also work, but it drops the implicitcommit-on-exit that the surrounding code relies on, so an explicit
close()isthe smaller change.
Verification (Windows 11, Python 3.12, 0.28.0)
codex-usage-tracker setup→{"cache_root": "...", "state": "absent"}, no leftoverscodex-usage-tracker refresh→{"disposition": "started", ...}codex-usage-tracker status→state: active,generation: 1,history_coverage: 28 sources / 11.8 MB / preset recent_30dcodex-usage-tracker _mcp):initialize→serverInfo {name: codex-usage-tracker, version: 0.28.0};tools/list→ 6 toolsSuggested guardrail
A regression test that builds a staging DB through the same helper and asserts the
file is then renameable passes on Linux both before and after the fix, so it would
not catch this class. Consider a
windows-latestjob (or at least anos.name == "nt"-marked variant).