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

Only one instance on GCP deployment and small tweaks #18

Merged
merged 6 commits into from
Feb 20, 2024

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Feb 19, 2024

Summary by CodeRabbit

  • New Features
    • Updated the GCP deployment script to dynamically select agents for deployment based on input parameters like agent name and cron schedule.
    • Added a new DeployableAlwaysRaiseAgent class that raises a RuntimeError with a specific message for binary market scenarios.
  • Enhancements
    • Improved the DeployableCoinFlipAgent to consistently return a random sample of markets.
    • Enhanced the GCP deployment utility with timeout and retry_on_failure parameters for more reliable deployments.

@kongzii kongzii marked this pull request as ready for review February 19, 2024 11:31
Copy link

coderabbitai bot commented Feb 19, 2024

Walkthrough

The recent updates introduce a more flexible deployment strategy for agents on Google Cloud Platform (GCP), enhancing the deployment script to support dynamic agent selection, scheduling, and branch configuration. Additionally, the prediction market agent tooling has been improved with new agent behaviors, including a random market selection and a deliberate error-raising agent. Furthermore, deployment utility enhancements include timeout settings and automatic retry on failure, improving reliability and control over deployment processes.

Changes

File Path Change Summary
.../cloud_deployment/gcp/deploy.py
.../deploy/agent_example.py
.../deploy/gcp/utils.py
Added a main function in deploy.py for dynamic agent deployment with configurable parameters. Updated agent_example.py to change market selection behavior and added a new error-raising agent. Enhanced utils.py with timeout and retry functionality for deployment handling.
.../deploy/agent.py
.../markets/data_models.py
In agent.py, added a new parameter gcp_fname with default value and adjusted its assignment in the main function. In data_models.py, made the lastBetTime attribute optional.

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b04007c and d0615e2.
Files selected for processing (3)
  • examples/cloud_deployment/gcp/deploy.py (2 hunks)
  • prediction_market_agent_tooling/deploy/agent_example.py (1 hunks)
  • prediction_market_agent_tooling/deploy/gcp/utils.py (2 hunks)
Additional comments: 4
prediction_market_agent_tooling/deploy/agent_example.py (2)
  • 9-9: The change to DeployableCoinFlipAgent simplifies the market selection process by always returning a random sample of markets. This approach assumes there is at least one market available. Ensure that the list of markets passed to pick_markets is never empty to avoid potential runtime errors.
  • 15-17: The introduction of DeployableAlwaysRaiseAgent with a method that unconditionally raises a RuntimeError is a clear way to test error handling mechanisms. However, ensure that this behavior aligns with the testing strategy and that there are mechanisms in place to catch and properly handle this exception during deployment tests.
examples/cloud_deployment/gcp/deploy.py (1)
  • 36-37: The use of typer.run(main) to execute the script provides a simple and effective CLI interface. Ensure that the documentation is updated to reflect the new parameters and usage instructions for deploying agents.
prediction_market_agent_tooling/deploy/gcp/utils.py (1)
  • 18-19: Adding timeout and retry_on_failure parameters to the gcloud_deploy_cmd function improves the configurability of deployment operations. Ensure that the default values chosen for these parameters are sensible for the majority of deployment scenarios. Additionally, document these parameters to inform users about how to use them effectively.

Comment on lines 12 to 18
def main(
agent_name: str, cron_schedule: str = "0 */2 * * *", branch: str = "main"
) -> None:
agent: DeployableAgent = {
"coin_flip": DeployableCoinFlipAgent,
"always_raise": DeployableAlwaysRaiseAgent,
}[agent_name]()
Copy link

Choose a reason for hiding this comment

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

The dynamic selection of agents based on the agent_name parameter is a significant improvement for deployment flexibility. However, consider validating the agent_name input against the available agent classes to prevent runtime errors from invalid inputs.

+ if agent_name not in ["coin_flip", "always_raise"]:
+     raise ValueError(f"Invalid agent_name: {agent_name}. Available options: 'coin_flip', 'always_raise'")

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.

Suggested change
def main(
agent_name: str, cron_schedule: str = "0 */2 * * *", branch: str = "main"
) -> None:
agent: DeployableAgent = {
"coin_flip": DeployableCoinFlipAgent,
"always_raise": DeployableAlwaysRaiseAgent,
}[agent_name]()
def main(
agent_name: str, cron_schedule: str = "0 */2 * * *", branch: str = "main"
) -> None:
if agent_name not in ["coin_flip", "always_raise"]:
raise ValueError(f"Invalid agent_name: {agent_name}. Available options: 'coin_flip', 'always_raise'")
agent: DeployableAgent = {
"coin_flip": DeployableCoinFlipAgent,
"always_raise": DeployableAlwaysRaiseAgent,
}[agent_name]()

examples/cloud_deployment/gcp/deploy.py Outdated Show resolved Hide resolved
Comment on lines +31 to +38
f"--timeout {timeout}s "
# Explicitly set no concurrency, min instances to 0 (agent is executed only once in a while) and max instances to 1 (parallel agents aren't allowed).
"--concurrency 1 "
"--min-instances 0 "
"--max-instances 1 "
)
if retry_on_failure:
cmd += "--retry "
Copy link

Choose a reason for hiding this comment

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

The implementation of the timeout and retry_on_failure parameters in the deployment command is correct. However, consider adding error handling or logging to provide feedback when a deployment fails despite retries. This can help in diagnosing deployment issues more efficiently.

+ if retry_on_failure:
+     cmd += "--retry "
+     print("Note: Deployment will retry on failure.")

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.

Suggested change
f"--timeout {timeout}s "
# Explicitly set no concurrency, min instances to 0 (agent is executed only once in a while) and max instances to 1 (parallel agents aren't allowed).
"--concurrency 1 "
"--min-instances 0 "
"--max-instances 1 "
)
if retry_on_failure:
cmd += "--retry "
f"--timeout {timeout}s "
# Explicitly set no concurrency, min instances to 0 (agent is executed only once in a while) and max instances to 1 (parallel agents aren't allowed).
"--concurrency 1 "
"--min-instances 0 "
"--max-instances 1 "
)
if retry_on_failure:
cmd += "--retry "
print("Note: Deployment will retry on failure.")

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d0615e2 and dc0de77.
Files selected for processing (1)
  • examples/cloud_deployment/gcp/deploy.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • examples/cloud_deployment/gcp/deploy.py

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dc0de77 and 6cf89e4.
Files selected for processing (2)
  • examples/cloud_deployment/gcp/deploy.py (2 hunks)
  • prediction_market_agent_tooling/markets/data_models.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • examples/cloud_deployment/gcp/deploy.py
Additional comments: 1
prediction_market_agent_tooling/markets/data_models.py (1)
  • 159-159: The change to make lastBetTime optional in the ManifoldMarket class by using t.Optional[datetime] is appropriate for scenarios where the last bet time might not be available. This enhances the flexibility of the data model to represent various states of a market.

Ensure that all parts of the codebase that interact with ManifoldMarket instances are updated to handle None values for lastBetTime gracefully. This might involve adding checks or default values where lastBetTime is used to prevent any runtime errors or unexpected behavior.

@kongzii kongzii marked this pull request as draft February 19, 2024 12:38
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6cf89e4 and 53b9c19.
Files selected for processing (2)
  • examples/cloud_deployment/gcp/deploy.py (2 hunks)
  • prediction_market_agent_tooling/deploy/agent.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • examples/cloud_deployment/gcp/deploy.py
Additional comments: 3
prediction_market_agent_tooling/deploy/agent.py (3)
  • 74-74: The addition of the gcp_fname parameter with a default value of None to the deploy_gcp method is a good practice for enhancing flexibility. This allows for dynamic naming of GCP functions based on the deployment context, which aligns with the PR's objectives of improving the deployment process's configurability and reliability.
  • 89-89: The logic to assign gcp_fname using a conditional expression is correctly implemented. It ensures that if gcp_fname is provided, it will be used; otherwise, it falls back to generating a name using the get_gcloud_fname method. This approach maintains backward compatibility while introducing new functionality, which is a positive aspect of these changes.
  • 71-77: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-104]

Overall, the DeployableAgent class and the changes made in the deploy_gcp method align well with the PR's objectives of enhancing the deployment process to GCP. The code is well-structured, follows Python best practices, and introduces meaningful improvements to the deployment process's flexibility and reliability. It's recommended to continue monitoring the deployment process for any edge cases or errors that may arise from the new changes and to consider adding unit tests for the new functionality to ensure its correctness and stability.

Comment on lines 86 to 92
return "Success"
"""

gcp_fname = self.get_gcloud_fname(market_type)
gcp_fname = gcp_fname or self.get_gcloud_fname(market_type)

with tempfile.NamedTemporaryFile(mode="w", suffix=".py") as f:
f.write(entrypoint_template)
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [74-104]

The deploy_gcp method demonstrates a comprehensive approach to deploying agents to GCP, including dynamic entrypoint generation, deployment parameter handling, and error checking. However, it's important to ensure that the deploy_to_gcp and related functions are robustly implemented to handle the dynamic nature of the entrypoint generation and deployment parameters. Additionally, consider adding more detailed error messages to help diagnose deployment failures more effectively.

Consider enhancing error messages in the deployment process to provide more context on failures, which could aid in troubleshooting.

)
if retry_on_failure:
cmd += "--retry "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what happened before with OpenAI-powered agents, this retry is disabled by default. I tried to deploy agents that always fail with changes from this PR and without, and both are executed just once per 10 min (as scheduled).

I think this PR introduces changes that are worth merging, but it doesn't solve the retries problem. I'll deploy the openai-powered agents tomorrow and monitor it...

Screenshot by Dropbox Capture

@kongzii kongzii changed the title Fix retries on GCP deployment Only one instance on GCP deployment and small tweaks Feb 19, 2024
@kongzii kongzii marked this pull request as ready for review February 19, 2024 16:19
Copy link
Contributor

@evangriffiths evangriffiths left a comment

Choose a reason for hiding this comment

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

LGTM

@kongzii kongzii merged commit 850f073 into main Feb 20, 2024
6 checks passed
@kongzii kongzii deleted the peter/fix-gcp-retries branch February 20, 2024 07:41
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