Skip to content

fix(autogen-ext): clean up temporary output dir in JupyterCodeExecutor#7226

Closed
weiguangli-io wants to merge 1 commit intomicrosoft:mainfrom
weiguangli-io:codex/autogen-7217-jupyter-tempdir-cleanup
Closed

fix(autogen-ext): clean up temporary output dir in JupyterCodeExecutor#7226
weiguangli-io wants to merge 1 commit intomicrosoft:mainfrom
weiguangli-io:codex/autogen-7217-jupyter-tempdir-cleanup

Conversation

@weiguangli-io
Copy link

Summary
This PR fixes a resource leak in JupyterCodeExecutor when output_dir is not provided.

Closes #7217.

Problem
JupyterCodeExecutor creates a temporary output directory by default, but stop() did not clean it up. In long-running/local-dev workflows this leaves temp directories behind.

Changes

  • Track ownership of the output directory (_owns_output_dir).
  • Use TemporaryDirectory for default output directory lifecycle management.
  • Clean up owned temp output directory in stop().
  • Re-create an owned temp output directory in start() after a previous stop() to keep restart() behavior safe.
  • Add regression tests for:
    • default temp output dir cleanup on stop
    • custom output dir preservation on stop
    • fallback behavior for unknown mime/output types
    • restart path recreating default temp output dir

Validation
Local checks run and passed:

  • uv run ruff check python/packages/autogen-ext/src/autogen_ext/code_executors/jupyter/_jupyter_code_executor.py python/packages/autogen-ext/tests/code_executors/test_jupyter_code_executor.py
  • cd python && uv run mypy packages/autogen-ext/src/autogen_ext/code_executors/jupyter/_jupyter_code_executor.py packages/autogen-ext/tests/code_executors/test_jupyter_code_executor.py
  • cd python && uv run pytest packages/autogen-ext/tests/code_executors/test_jupyter_code_executor.py -q
  • cd python && uv run pytest packages/autogen-ext/tests/code_executors/test_jupyter_code_executor.py -q --cov=autogen_ext.code_executors.jupyter._jupyter_code_executor --cov-report=term-missing

Coverage for autogen_ext.code_executors.jupyter._jupyter_code_executor in this test run: 100%.

@weiguangli-io
Copy link
Author

Closing — the autogen repo has shifted to maintenance mode and external PRs are no longer being reviewed. Thank you for the great framework!

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