Skip to content

fix: stale import path and resource leak cleanups - #102

Merged
ImKeTT merged 3 commits into
aiming-lab:mainfrom
sylearn:fix/stale-import-and-resource-leak-cleanups
Mar 19, 2026
Merged

ImKeTT merged 3 commits into
aiming-lab:mainfrom
sylearn:fix/stale-import-and-resource-leak-cleanups

Conversation

@sylearn

@sylearn sylearn commented Mar 19, 2026 •

Copy link
Copy Markdown

Summary

Consolidates #96, #97, and #98 into a single PR as requested.

Three small, related fixes for stale references and resource management:

  1. Stale import path (experiment/runner.py): from arc.experiment_git import ExperimentGitManager references a pre-rename module. Updated to researchclaw.experiment.git_manager. Passing git_repo_dir to ExperimentRunner currently raises ModuleNotFoundError.

  2. PyMuPDF fd leak (web/pdf_extractor.py): If any exception occurs between fitz.open() and doc.close(), the document is never closed. Replaced manual open/close with a with context manager to guarantee cleanup during batch PDF processing.

  3. Checkpoint fd double-close (pipeline/runner.py): _write_checkpoint passes a raw mkstemp() fd to open(fd, "w"). If the write fails, the with block closes the fd, then the except handler tries os.close(fd) again. Simplified by closing the fd immediately and reopening by path.

Closes #96, #97, #98.

Test plan

  • Verified researchclaw.experiment.git_manager.ExperimentGitManager exists and defines is_git_repo()
  • Verified fitz.Document supports the context manager protocol
  • Confirmed mkstemp creates the file atomically (no TOCTOU race on reopen)

sylearn added 3 commits March 19, 2026 14:39
The import `from arc.experiment_git import ExperimentGitManager` references
the pre-rename module path. The actual class lives in
`researchclaw.experiment.git_manager`. Any call passing `git_repo_dir`
to ExperimentRunner raises ModuleNotFoundError.

Made-with: Cursor
If any exception occurs between fitz.open() and doc.close(), the
document object is never closed, leaking a file descriptor. During
batch PDF processing in the literature collection stage this can
exhaust the OS file descriptor limit.

Replace manual open/close with a `with` statement so the document
is always closed, even on error.

Made-with: Cursor
mkstemp() returns a raw fd which is then passed to open(fd, "w").
If open() succeeds but the write fails, the with-block closes the fd,
then the except handler calls os.close(fd) again. On systems where fd
numbers are quickly reused, this can close an unrelated file descriptor.

Simplify by closing the mkstemp fd immediately and reopening by path.
The temp file already exists on disk so there is no TOCTOU race.

Made-with: Cursor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR consolidates three small fixes to address stale module references and ensure file descriptors are reliably cleaned up during PDF processing and checkpoint writing.

Changes:

  • Fix stale ExperimentGitManager import path in ExperimentRunner to prevent ModuleNotFoundError.
  • Prevent PyMuPDF document fd leaks by using a context manager around fitz.open().
  • Eliminate potential checkpoint fd double-close by closing the mkstemp() fd immediately and reopening by temp path.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
researchclaw/experiment/runner.py Updates ExperimentGitManager import to the post-rename module path.
researchclaw/web/pdf_extractor.py Wraps fitz.open() in a with block to guarantee document closure on exceptions.
researchclaw/pipeline/runner.py Simplifies checkpoint temp-file handling to avoid ambiguous fd ownership and double-closing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ImKeTT

ImKeTT commented Mar 19, 2026

Copy link
Copy Markdown
Collaborator

thanks @sylearn this PR lgtm

@ImKeTT
ImKeTT merged commit 10540fc into aiming-lab:main Mar 19, 2026
3 of 4 checks passed
@sylearn
sylearn deleted the fix/stale-import-and-resource-leak-cleanups branch March 19, 2026 08:03
Jacky628 pushed a commit to Jacky628/AutoResearchClaw that referenced this pull request Aug 17, 2026
…esource-leak-cleanups

fix: stale import path and resource leak cleanups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants