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

Fix challenging agents (replicator, challenger) #510

Merged
merged 4 commits into from
Oct 11, 2024
Merged

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Oct 10, 2024

No description provided.

+ timedelta(minutes=30),
) + get_omen_binary_markets_common_filters(
# And also markets without any answer at all yet.
question_with_answers=False,
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 didn't realise before that if I use question_finalized_after, it won't include questions without any answer at all (where it's null)

Copy link
Contributor

@gabrielfior gabrielfior Oct 10, 2024

Choose a reason for hiding this comment

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

Effectivelly what you are doing with the partial is an OR filter, since you want (in this code snippet) the questions that finalize after now() + 30min OR questions without answers.
For this, I find querying the subgraph using OR a lot cleaner - see code snippet below (example query).

{
  questions(first: 5,
  where: {
    or: [{
    id: "0x001dd5a9194948a903c0e3b624eb0d458cd23d828f29a57f517c858d7cf71f76"  
    },
    {id : "0x0005ef01269fbb37aba4cc16f518138d7d8bf5f4937a5572c294c2e62f0cf670"}
    ],    
  }) {
    id
    templateId
    data
    title
  }
}

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using OR a lot cleaner

It is clean in the simple example query you provided, but how do you suggest integrating or functionality into OmenSubgraphHandler? With any integration that I can imagine, it's in the end easier to just do it like I do it here.

  • finalized_after shouldn't be finalized_after OR without_answers, because sometimes we might need to really query only finalized_after markets
  • I didn't want to introduce finalize_after_or_null filter, because that we would have to have or_null variant of many other arguments as well

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree partial here is simple and works, but what I was thinking is something along these lines (inside the subgraph handler) if the use case becomes more complicated:

where_stm1 = -> build with params 1
where_stm2 -> build with params2
where_final = {"or": [where_stms1, where_stms2]}

The added benefit here is to execute just 1 query, whereas in yours we execute 2 queries.

Copy link
Contributor

Choose a reason for hiding this comment

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

But happy here with partial :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will need some fancy refactoring of OmenSubgraphHandler, but I agree it could be nice!

I'm not sure how it would end up in the end, but if you are up to exploring it, it sounds good to me.

to execute just 1 query, whereas in yours we execute 2 queries.

That's a good benefit out of it.

Copy link
Contributor

coderabbitai bot commented Oct 11, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve updates to several deploy.py files across different agents within the prediction market module. Key modifications include the introduction of partial functions to streamline market retrieval processes, renaming parameters for clarity, and enhancing method logic to focus on specific market states. These adjustments aim to improve the handling of binary markets and their associated parameters, ensuring more precise market processing without altering method signatures.

Changes

File Change Summary
prediction_market_agent/agents/ofvchallenger_agent/deploy.py Added import for partial. Updated challenge method to use partial for market retrieval. Updated parameters for markets_open_for_answers.
prediction_market_agent/agents/omen_cleaner_agent/deploy.py Renamed finalized_before to question_finalized_before in resolve_finalized_markets. Updated comment in generate_missing_images.
prediction_market_agent/agents/replicate_to_omen_agent/omen_replicate.py Renamed opened_before to question_opened_before in omen_unfund_replicated_known_markets_tx.
prediction_market_agent/agents/replicate_to_omen_agent/omen_resolve_replicated.py Added get_omen_binary_markets_common_filters partial function. Updated parameters in omen_finalize_and_resolve_and_claim_back_all_markets_based_on_others_tx. Updated comments for clarity.

Possibly related PRs

  • OFVChallenger #440: The changes in the OFVChallengerAgent class, particularly the modifications to the challenge method and the introduction of a new challenge_market method, are directly related to the updates made in the main PR, which also involves changes to the challenge method and the use of a partial function for market retrieval.
  • OFVChallenger updates #455: This PR also modifies the challenge_market function in the OFVChallengerAgent, aligning with the changes in the main PR that involve logic modifications within the same function.
  • No waiting in resolving finalized markets #493: The changes in the OmenCleanerAgent, specifically in the resolve_finalized_markets method, relate to the overall market resolution logic that is also a focus in the main PR, which updates how markets are retrieved and processed.

Suggested reviewers

  • evangriffiths

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 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
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (1)
prediction_market_agent/agents/replicate_to_omen_agent/omen_resolve_replicated.py (1)

56-71: Excellent refactoring for improved clarity and coverage

The changes in this section significantly improve the code:

  1. The introduction of get_omen_binary_markets_common_filters as a partial function is an excellent way to reduce code duplication and improve maintainability.
  2. Updating parameter names (e.g., opened_before to question_opened_before) enhances clarity.
  3. Adding an additional query for markets without any answers ensures more comprehensive coverage.

These changes make the code more readable and flexible. Great job!

Consider renaming created_opened_markets to something like markets_to_process or candidate_markets to better reflect its expanded content (now including markets without answers).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9354244 and 2ae9642.

⛔ Files ignored due to path filters (2)
  • poetry.lock is excluded by !**/*.lock, !**/*.lock
  • pyproject.toml is excluded by !**/*.toml
📒 Files selected for processing (4)
  • prediction_market_agent/agents/ofvchallenger_agent/deploy.py (2 hunks)
  • prediction_market_agent/agents/omen_cleaner_agent/deploy.py (1 hunks)
  • prediction_market_agent/agents/replicate_to_omen_agent/omen_replicate.py (1 hunks)
  • prediction_market_agent/agents/replicate_to_omen_agent/omen_resolve_replicated.py (2 hunks)
🧰 Additional context used
🔇 Additional comments (7)
prediction_market_agent/agents/replicate_to_omen_agent/omen_resolve_replicated.py (4)

2-2: LGTM: Good use of functools.partial

The addition of from functools import partial is a good choice. It suggests that you're planning to use partial functions to create reusable function objects with pre-filled arguments, which can lead to cleaner and more maintainable code.


56-56: Improved type safety with return type annotation

The addition of the -> FinalizeAndResolveResult return type annotation is a great improvement. It enhances type safety and makes the function's contract more explicit, which aids in code understanding and maintenance.


Line range hint 180-180: Enhanced type safety with ClaimResult return type

The addition of the -> ClaimResult return type annotation is a positive change. It improves type safety and makes the function's output more explicit, which is beneficial for code clarity and maintenance.


Line range hint 1-224: Overall excellent improvements to the codebase

The changes in this file demonstrate a thoughtful approach to improving the code:

  1. The introduction of partial functions reduces code duplication.
  2. Enhanced type annotations improve type safety and code clarity.
  3. Expanded market retrieval logic ensures more comprehensive coverage.
  4. Improved parameter naming enhances code readability.

These changes align well with the PR objectives of fixing challenging agents (replicator, challenger). They should lead to more robust and maintainable code.

Great work on these improvements!

prediction_market_agent/agents/ofvchallenger_agent/deploy.py (2)

2-2: LGTM: Import of partial function.

The addition of from functools import partial is appropriate given the upcoming changes in the code that utilize this function.


72-86: Excellent refactoring using partial function.

The changes in the challenge method significantly improve code readability and efficiency:

  1. The use of partial to create get_omen_binary_markets_common_filters reduces code duplication and simplifies parameter passing.
  2. The updated logic now correctly handles both markets that will be finalized after a 30-minute buffer and markets without any answers, addressing the issue mentioned in previous review comments.

These changes make the code more maintainable and aligned with the intended functionality.

prediction_market_agent/agents/replicate_to_omen_agent/omen_replicate.py (1)

208-208: LGTM! Verify consistency across the codebase.

The parameter name change from opened_before to question_opened_before in the get_omen_binary_markets method call improves clarity. It better specifies that the filter is applied to the question's opening time.

To ensure consistency, please run the following script to check if this change has been applied uniformly across the codebase:

This will help identify any places where the parameter name might need to be updated for consistency.

✅ Verification successful

Verified consistency across the codebase.

All instances of opened_before have been successfully renamed to question_opened_before in get_omen_binary_markets method calls.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of 'opened_before' in get_omen_binary_markets calls

# Search for any remaining instances of 'opened_before' in get_omen_binary_markets calls
rg --type python 'get_omen_binary_markets.*opened_before'

# Search for all instances of 'get_omen_binary_markets' to compare
rg --type python 'get_omen_binary_markets'

Length of output: 164


Script:

#!/bin/bash
# Description: Check for any remaining instances of 'opened_before' in get_omen_binary_markets calls

# Search for any remaining instances of 'opened_before' in get_omen_binary_markets calls
rg -g '*.py' 'get_omen_binary_markets.*opened_before'

# Search for all instances of 'get_omen_binary_markets' to compare
rg -g '*.py' 'get_omen_binary_markets'

Length of output: 2310

@@ -59,7 +59,7 @@ def resolve_finalized_markets(self, api_keys: APIKeys) -> list[HexAddress]:
market
for market in OmenSubgraphHandler().get_omen_binary_markets(
limit=None,
finalized_before=utcnow(),
question_finalized_before=utcnow(),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistent parameter naming in get_omen_binary_markets calls.

The question_finalized_before parameter was updated in deploy.py, but other calls to get_omen_binary_markets still use the old parameter name finalized_before. Please update these method calls to ensure consistent parameter naming across the codebase.

🔗 Analysis chain

Approve the parameter name change and verify consistency.

The change from finalized_before to question_finalized_before improves clarity by specifying that we're filtering based on the question's finalization time. This aligns well with the method's purpose of resolving finalized markets.

To ensure consistency across the codebase, please run the following script:

This will help confirm that the OmenSubgraphHandler class and its usage are consistent with this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of 'question_finalized_before' parameter in OmenSubgraphHandler

# Test: Search for OmenSubgraphHandler class definition and its method calls
rg --type python -A 10 'class OmenSubgraphHandler'
rg --type python 'OmenSubgraphHandler\(\)\.get_omen_binary_markets'

Length of output: 184


Script:

#!/bin/bash
# Description: Verify the usage of 'question_finalized_before' parameter in OmenSubgraphHandler

# Test: Search for OmenSubgraphHandler class definition and its method calls
rg --type py -A 10 'class OmenSubgraphHandler'
rg --type py 'OmenSubgraphHandler\(\)\.get_omen_binary_markets'

Length of output: 1431


Script:

#!/bin/bash
# Description: Verify the usage of 'question_finalized_before' parameter in all calls to 'get_omen_binary_markets'

# Search for 'get_omen_binary_markets' method calls with 'question_finalized_before' parameter
rg --type py 'get_omen_binary_markets\([^)]*question_finalized_before='

Length of output: 73

@kongzii kongzii merged commit 00f4f47 into main Oct 11, 2024
8 of 9 checks passed
@kongzii kongzii deleted the peter/fixesreal branch October 11, 2024 07:29
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