Skip to content

Safer execution #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2025
Merged

Safer execution #1

merged 3 commits into from
Apr 20, 2025

Conversation

andrewm4894
Copy link
Owner

This pull request introduces enhancements to the Makefile for running example notebooks, updates the documentation to reflect these changes, and improves the visualization logic in examples/example_5.ipynb. The modifications aim to streamline workflows and improve the clarity and usability of example outputs.

Makefile and Workflow Enhancements:

  • Added a new run-examples target to the Makefile for executing example notebooks with a specified number of workers (--max-workers 3). This simplifies running all examples in-place. ([[1]](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52L1-R1), [[2]](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R13-R21))
  • Updated the clean target in the Makefile to remove executed notebook files (examples/executed/). ([MakefileR13-R21](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R13-R21))

Documentation Updates:

  • Updated examples/README.md to include instructions for running example notebooks using the new make run-examples command. ([examples/README.mdR6-R11](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-49aaa2819e35a856818ecec8c9fa7e1c79ad028d3f44bd749736353cfb51bac9R6-R11))

Visualization Improvements in examples/example_5.ipynb:

  • Enhanced the bar chart visualization by:
    • Updating the color scale to use the Viridis palette for better readability. ([examples/example_5.ipynbL4000-R4084](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-06bd46c80f62355b923ca5bb3f8877818b0e4b938590df655d01d0955f713c35L4000-R4084))
    • Adding text labels to each bar to display total quantities directly on the chart. ([examples/example_5.ipynbL3968-R4032](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-06bd46c80f62355b923ca5bb3f8877818b0e4b938590df655d01d0955f713c35L3968-R4032))
    • Adjusting axis titles for clarity (e.g., changing "Item" to "Items"). ([examples/example_5.ipynbL4826-R4884](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-06bd46c80f62355b923ca5bb3f8877818b0e4b938590df655d01d0955f713c35L4826-R4884))
  • Refined the code and metadata for better maintainability and execution tracking:
    • Improved the grouping and sorting logic for data visualization. ([examples/example_5.ipynbL6-R94](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-06bd46c80f62355b923ca5bb3f8877818b0e4b938590df655d01d0955f713c35L6-R94))
    • Included execution metadata in the notebook for tracking execution status and duration. ([examples/example_5.ipynbL6-R94](https://github.com/andrewm4894/plot-agent/pull/1/files#diff-06bd46c80f62355b923ca5bb3f8877818b0e4b938590df655d01d0955f713c35L6-R94))

… message in test_handle_syntax_error for improved clarity and safety handling.
…ance example notebooks with execution metadata. Remove deprecated execution_safer.py file and refactor execution handling in execution.py for improved security and clarity.
@andrewm4894 andrewm4894 requested a review from Copilot April 20, 2025 11:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances the safe execution of dynamically generated Plotly code while streamlining workflow and improving visualization outputs. Key changes include:

  • A new Makefile target (“run-examples”) and updated clean target to run notebooks in parallel.
  • Enhanced error handling in code execution with stricter AST validation and refined error messages.
  • Updates and improvements to notebook visualizations and metadata, along with documentation updates.

Reviewed Changes

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

Show a summary per file
File Description
tests/unit/test_plot_execution.py Updated tests to expect a specific safety rejection error message for syntax errors.
scripts/run_examples.py Introduced a new script for executing example notebooks in parallel with logging.
pyproject.toml Bumped version from 0.3.0 to 0.3.1.
plot_agent/*.py Added module-level docstrings and updated agent/execution code for clarity and safety.
examples/*.ipynb Improved chart visualizations (e.g., axis titles, color scales, text labels) and metadata.
examples/README.md Updated instructions to include the new “make run-examples” command.
Files not reviewed (2)
  • Makefile: Language not supported
  • requirements-dev.txt: Language not supported
Comments suppressed due to low confidence (1)

tests/unit/test_plot_execution.py:56

  • The test now checks for an exact error message when a syntax error occurs. Consider using a looser matching strategy (e.g. a substring or regex) so that minor changes in error formatting do not cause the test to fail.
assert "Error: Code rejected on safety grounds: '(' was never closed (<unknown>, line 2)" in result

@andrewm4894 andrewm4894 merged commit b91a1b5 into main Apr 20, 2025
1 check passed
@andrewm4894 andrewm4894 deleted the safer-execution branch April 20, 2025 11:59
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.

1 participant