Skip to content
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

Add rollback functionality to setup wizard #75

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HYPRGK
Copy link

@HYPRGK HYPRGK commented Dec 1, 2024

Fixes #9

Add error handling and rollback functionality to the setup wizard.

  • Add rollback_actions function in agentstack/cli/cli.py to undo actions like directory creation and file writing.
  • Update init_project_builder in agentstack/cli/cli.py to catch exceptions and call rollback_actions.
  • Track created files and directories in insert_template for potential rollback in agentstack/cli/cli.py.
  • Add rollback_actions function in agentstack/generation/agent_generation.py and agentstack/generation/task_generation.py to undo actions.
  • Update generate_agent in agentstack/generation/agent_generation.py and generate_task in agentstack/generation/task_generation.py to catch exceptions and call rollback_actions.
  • Add tests in tests/test_cli_loads.py to verify rollback functionality.

For more details, open the Copilot Workspace session.

Fixes AgentOps-AI#9

Add error handling and rollback functionality to the setup wizard.

* Add `rollback_actions` function in `agentstack/cli/cli.py` to undo actions like directory creation and file writing.
* Update `init_project_builder` in `agentstack/cli/cli.py` to catch exceptions and call `rollback_actions`.
* Track created files and directories in `insert_template` for potential rollback in `agentstack/cli/cli.py`.
* Add `rollback_actions` function in `agentstack/generation/agent_generation.py` and `agentstack/generation/task_generation.py` to undo actions.
* Update `generate_agent` in `agentstack/generation/agent_generation.py` and `generate_task` in `agentstack/generation/task_generation.py` to catch exceptions and call `rollback_actions`.
* Add tests in `tests/test_cli_loads.py` to verify rollback functionality.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/AgentOps-AI/AgentStack/issues/9?shareId=XXXX-XXXX-XXXX-XXXX).
@@ -20,86 +20,100 @@
from .. import generation
from ..utils import open_json_file, term_color, is_snake_case

created_files = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

These variables should be created inside the function scope, not at the module level.

os.remove(file)
for dir in created_dirs:
if os.path.exists(dir):
shutil.rmtree(dir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be very careful about deleting files when any exception occurs. Possible that running this command on an already initialized project would permanently erase user data.

@tcdent
Copy link
Collaborator

tcdent commented Dec 2, 2024

Thanks for taking the time to submit this PR!

I like the sentiment here, but we need to be careful about the implementation.

The module-level variable names and rollback functions have no indication of what feature they're specifically related to.

Stylistically, indenting the entire method inside a try/except statement is a bit much.

Potential solution to this is to create a forward and backward method inside the relevant function which makes the scope more implicit.

def init_project_builder(...):
    def forward():
        ...
    def backward():
        ...

    try:
        forward()
    except:
        backward()

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.

if an error occurs while using the setup wizard, undo any actions that have succeeded
2 participants