Skip to content

fix: clean up temporary output directory in JupyterCodeExecutor.stop()#7218

Open
veeceey wants to merge 1 commit intomicrosoft:mainfrom
veeceey:fix/issue-7217-jupyter-executor-temp-dir-cleanup
Open

fix: clean up temporary output directory in JupyterCodeExecutor.stop()#7218
veeceey wants to merge 1 commit intomicrosoft:mainfrom
veeceey:fix/issue-7217-jupyter-executor-temp-dir-cleanup

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 7, 2026

Summary

Fixes #7217

JupyterCodeExecutor creates a temporary directory via tempfile.mkdtemp() when no output_dir is provided, but never cleans it up in stop(). This causes leaked directories and their contents (generated images, HTML files) to accumulate on disk over time.

This is inconsistent with every other executor in the codebase (LocalCommandLineCodeExecutor, DockerCommandLineCodeExecutor, AzureContainerCodeExecutor) which all properly clean up their temporary directories.

Changes

  • Replace tempfile.mkdtemp() with tempfile.TemporaryDirectory() in __init__, matching the pattern used by all other executors
  • Add cleanup() call in stop() to properly clean up the temporary directory
  • User-provided output_dir directories are not affected (only auto-created temp dirs are cleaned up)
  • Remove the unused _temp_dir_path field

Tests

Added two new tests:

  • test_temp_dir_cleanup_on_stop -- verifies the temporary directory is removed after stop()
  • test_user_provided_output_dir_not_cleaned_up -- verifies user-provided directories are preserved after stop()

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.

JupyterCodeExecutor leaks temporary output directory on stop — inconsistent with other executors

1 participant