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

chore: state poc #37

Closed
wants to merge 1 commit into from
Closed

chore: state poc #37

wants to merge 1 commit into from

Conversation

MicaiahReid
Copy link
Member

@MicaiahReid MicaiahReid commented Feb 12, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced runbook execution with snapshot tracking and flow comparison to update plans.
    • Introduced a configurable default environment setting, replacing hardcoded values.
    • Improved error handling now preserves execution state, enabling smoother troubleshooting.
  • Chores

    • Updated dependency management to ensure more consistent builds.

Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request updates dependency management and runbook execution. In the Cargo.toml file, version specifications for txtx-core and txtx-addon-network-svm have been replaced with local path declarations, along with comments indicating the previous version values. In the runbook module, a new constant (DEFAULT_ENVIRONMENT) is introduced to centralize environment configuration. Additionally, the runbook execution flow is enhanced by adding logic to load snapshots when a state file is present, perform differential comparisons, and update error handling to write the state instead of exiting immediately.

Changes

File(s) Change Summary
crates/cli/Cargo.toml Updated dependency definitions for txtx-core and txtx-addon-network-svm: replaced version specifications with local path declarations and added comments documenting the previous version specifications.
crates/cli/src/runbook/mod.rs Enhanced runbook execution: added DEFAULT_ENVIRONMENT constant; incorporated logic to load execution snapshots from a state file, perform simulation and diff comparison, and updated error handling to write state instead of immediate process termination.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant R as Runbook Executor
    participant F as File System (State File)
    participant C as Snapshot Context

    U->>R: Initiate runbook execution
    R->>R: Use DEFAULT_ENVIRONMENT for configuration
    R->>F: Check for state_file_location
    alt State file exists
        F-->>R: Return execution snapshot
        R->>C: Create RunbookSnapshotContext with snapshot
        C-->>R: Simulate runbook flows and generate diff (ctx.diff)
        R->>R: Update plans based on diff
    else No state file found
        R->>R: Execute runbook without snapshot enhancements
    end
    R->>R: Start unsupervised runbook runloop
    alt Execution error occurs
        R->>F: Write runbook state to specified location
    end
Loading

Suggested reviewers

  • lgalabru

Poem

Oh, what a hop this code change brings,
In paths and snapshots our logic sings.
From version to path, the dependencies leap,
As runbooks awake from their slumber so deep.
With a twitch of my ears and a happy little bound,
This rabbit cheers the improvements that abound!
🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
crates/cli/src/runbook/mod.rs (1)

89-96: 🛠️ Refactor suggestion

Improve error handling for runloop.

The function returns Ok(()) even when there are errors in the runloop. Consider propagating the error or at least logging it.

     if let Err(diags) = res {
         println!("{} Execution aborted", red!("x"));
+        log::error!("Runloop execution failed");
         for diag in diags.iter() {
             println!("{}", format!("- {}", diag));
+            log::error!("- {}", diag);
         }
-        // write_runbook_transient_state(&mut runbook, runbook_state)?;
-        return Ok(());
+        return Err("Runloop execution failed".to_string());
     }
🧹 Nitpick comments (1)
crates/cli/src/runbook/mod.rs (1)

82-84: Improve error handling for snapshot loading.

Consider logging the error for better debugging and error tracking.

-            Err(e) => {
-                println!("{} {}", red!("x"), e);
-            }
+            Err(e) => {
+                log::error!("Failed to load execution snapshot: {}", e);
+                println!("{} {}", red!("x"), e);
+            }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 10523d6 and 4c573ce.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • crates/cli/Cargo.toml (2 hunks)
  • crates/cli/src/runbook/mod.rs (4 hunks)
🔇 Additional comments (2)
crates/cli/src/runbook/mod.rs (1)

25-25: LGTM!

Good refactoring to centralize the environment configuration by introducing a constant.

crates/cli/Cargo.toml (1)

51-51: Empty feature declaration.

The explorer feature is empty. Consider:

  1. Adding the required dependencies and functionality, or
  2. Removing the feature if it's not needed.

}
std::process::exit(1);
}
let _ = runbook.write_runbook_state(runbook_state_location)?;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle the state writing result.

The result of writing the runbook state is ignored with let _. Consider handling potential errors.

-    let _ = runbook.write_runbook_state(runbook_state_location)?;
+    runbook.write_runbook_state(runbook_state_location)?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let _ = runbook.write_runbook_state(runbook_state_location)?;
runbook.write_runbook_state(runbook_state_location)?;

Comment on lines +19 to +22
txtx-core = { path = "../../../txtx/crates/txtx-core" }
txtx-addon-network-svm = { package = "txtx-addon-network-svm", path = "../../../txtx/addons/svm" }
# txtx-core = { version = "0.2.2" }
# txtx-addon-network-svm = { version = "0.1.3" }
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify external dependencies.

The dependencies are using paths outside the repository (../../../txtx/), which could cause issues with reproducible builds. Consider:

  1. Moving these dependencies into the repository, or
  2. Publishing them to crates.io and using version specifications.

🏁 Script executed:

#!/bin/bash
# Description: Check if the external dependencies exist and are accessible.

# Test: Check if the txtx-core path exists
if [ -d "../../../txtx/crates/txtx-core" ]; then
    echo "txtx-core path exists"
else
    echo "txtx-core path does not exist"
fi

# Test: Check if the txtx-addon-network-svm path exists
if [ -d "../../../txtx/addons/svm" ]; then
    echo "txtx-addon-network-svm path exists"
else
    echo "txtx-addon-network-svm path does not exist"
fi

Length of output: 245


External Dependencies Missing – Action Required

The verification confirms that both dependency paths (../../../txtx/crates/txtx-core and ../../../txtx/addons/svm) do not exist. This outcome directly supports the concern that these external path dependencies could lead to reproducibility issues. It is advisable to either incorporate these dependencies into the repository or publish them to crates.io and use version specifications to avoid future build complications.

  • Location: crates/cli/Cargo.toml (lines 19-22)

@lgalabru
Copy link
Member

Superseded by #38

@lgalabru lgalabru closed this Feb 13, 2025
@lgalabru lgalabru deleted the poc/state branch February 13, 2025 04:43
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.

2 participants