Skip to content

feat: implement sim call rpc endpoint#1195

Closed
danieljrc888 wants to merge 4 commits intomainfrom
drojas/dxp-372-add-provider-and-model-to-gen_call
Closed

feat: implement sim call rpc endpoint#1195
danieljrc888 wants to merge 4 commits intomainfrom
drojas/dxp-372-add-provider-and-model-to-gen_call

Conversation

@danieljrc888
Copy link
Copy Markdown
Contributor

@danieljrc888 danieljrc888 commented Jun 12, 2025

What

  • Added provider and model to gen_call params

Why

  • To enable select provider and model when using gen_call endpoint

Testing done

  • Tested with studio calls

Decisions made

Checks

  • I have tested this code
  • I have reviewed my own PR
  • I have created an issue for this PR
  • I have set a descriptive PR title compliant with conventional commits

Reviewing tips

User facing release notes

Summary by CodeRabbit

  • New Features
    • Enhanced snapshot creation to support custom validator selection when both provider and model are specified, allowing for more flexible validation scenarios.
  • Refactor
    • Improved internal handling of validator snapshots for better maintainability and future extensibility.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 12, 2025

"""

Walkthrough

The changes introduce conditional logic in gen_call to create a custom validator snapshot when both "provider" and "model" parameters are provided. This uses new async methods in the validators manager to generate and apply temporary snapshots from specified validators, reverting to the default snapshot otherwise.

Changes

File(s) Change Summary
backend/protocol_rpc/endpoints.py Updated gen_call to require both "provider" and "model" in params; create custom validator snapshot with a zero-stake Validator; raise JSONRPCError if incomplete or invalid.
backend/validators/init.py Refactored snapshot creation by adding _get_snap_from_validators helper; added async context manager temporal_snapshot to apply and revert temporary snapshots from custom validator lists.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Endpoint (gen_call)
    participant ValidatorsManager

    Client->>Endpoint (gen_call): Call with params (may include provider/model)
    alt provider and model specified
        Endpoint->>ValidatorsManager: temporal_snapshot([custom validator])
        ValidatorsManager-->>Endpoint: Custom Snapshot
    else
        Endpoint->>ValidatorsManager: snapshot()
        ValidatorsManager-->>Endpoint: Default Snapshot
    end
    Endpoint->>ValidatorsManager: Check snapshot.validators
    Endpoint->>Endpoint: _gen_call_with_validator(...)
    Endpoint-->>Client: Return result
Loading

Poem

In the warren of code, a new path appears,
Custom validators hop in—let's give them cheers!
Snapshots now tailored, not just from the crowd,
Provider and model? The rabbit feels proud.
With each async leap, the logic refines,
Hopping forward, through protocol lines! 🐇✨
"""


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3585868 and 69fa467.

📒 Files selected for processing (2)
  • backend/protocol_rpc/endpoints.py (1 hunks)
  • backend/validators/__init__.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/validators/init.py
  • backend/protocol_rpc/endpoints.py
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Load Tests / load-test
  • GitHub Check: hardhat-test
  • GitHub Check: test
  • GitHub Check: backend-unit-tests
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@danieljrc888 danieljrc888 force-pushed the drojas/dxp-372-add-provider-and-model-to-gen_call branch from 2444dc2 to 6c204c5 Compare June 12, 2025 16:22
@danieljrc888 danieljrc888 self-assigned this Jun 12, 2025
@danieljrc888 danieljrc888 marked this pull request as ready for review June 12, 2025 16:22
Copy link
Copy Markdown
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: 2

🔭 Outside diff range comments (1)
backend/validators/__init__.py (1)

142-151: 🛠️ Refactor suggestion

Guard against missing plugin_config fields to avoid KeyError

_get_snap_from_validators indexes straight into val.llmprovider.plugin_config[...].
If plugin_config is None or simply lacks "mock_response", this blows up the whole snapshot creation path.

-            if "mock_response" in val.llmprovider.plugin_config:
-                host_data["mock_response"] = val.llmprovider.plugin_config[
-                    "mock_response"
-                ]
+            plugin_cfg = val.llmprovider.plugin_config or {}
+            if "mock_response" in plugin_cfg:
+                host_data["mock_response"] = plugin_cfg["mock_response"]
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e778f96 and 6c204c5.

📒 Files selected for processing (2)
  • backend/protocol_rpc/endpoints.py (1 hunks)
  • backend/validators/__init__.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
backend/protocol_rpc/endpoints.py (4)
backend/node/create_nodes/providers.py (1)
  • get_default_provider_for (88-99)
backend/database_handler/accounts_manager.py (1)
  • create_new_account (24-31)
backend/domain/types.py (1)
  • Validator (37-77)
backend/validators/__init__.py (2)
  • snapshot_with_custom_validators (168-177)
  • snapshot (154-165)
backend/validators/__init__.py (3)
backend/domain/types.py (3)
  • Validator (37-77)
  • from_dict (45-60)
  • from_dict (150-181)
backend/validators/web.py (1)
  • verify_for_read (67-71)
backend/validators/llm.py (1)
  • verify_for_read (88-92)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Load Tests / load-test
  • GitHub Check: hardhat-test
  • GitHub Check: test
  • GitHub Check: backend-unit-tests

Comment thread backend/validators/__init__.py
Comment thread backend/protocol_rpc/endpoints.py Outdated
Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (1)
backend/protocol_rpc/endpoints.py (1)

441-446: Chain the original ValueError & surface it with an Invalid params code

Catching the ValueError is good, but two tiny issues remain:

  1. Ruff’s B904 hint – re-raise the wrapped error with from e to preserve the traceback.
  2. Spec‐wise, a bad provider/model pair is an “Invalid params” condition → -32602, not a generic “Server error” (-32000).
-        except ValueError as e:
-            raise JSONRPCError(code=-32000, message=str(e))
+        except ValueError as e:
+            # Propagate root cause and use the standard invalid-params code
+            raise JSONRPCError(code=-32602, message=str(e), data={}) from e
🧰 Tools
🪛 Ruff (0.11.9)

445-445: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c204c5 and 259f02f.

📒 Files selected for processing (2)
  • backend/protocol_rpc/endpoints.py (1 hunks)
  • backend/validators/__init__.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/validators/init.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
backend/protocol_rpc/endpoints.py (4)
backend/node/create_nodes/providers.py (1)
  • get_default_provider_for (88-99)
backend/database_handler/accounts_manager.py (1)
  • create_new_account (24-31)
backend/domain/types.py (1)
  • Validator (37-77)
backend/validators/__init__.py (2)
  • temporal_snapshot (168-185)
  • snapshot (154-165)
🪛 Ruff (0.11.9)
backend/protocol_rpc/endpoints.py

445-445: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Load Tests / load-test
  • GitHub Check: hardhat-test
  • GitHub Check: test
  • GitHub Check: backend-unit-tests
🔇 Additional comments (1)
backend/protocol_rpc/endpoints.py (1)

450-455: Confirm that a zero-stake validator is acceptable to downstream logic

stake=0 makes the ad-hoc validator completely weightless.
If any later path (e.g. consensus weighting, rewards, slashing) assumes strictly-positive stake, this may blow up in less-obvious places.

Please double-check invariants or add an explicit comment / validation guard.

@danieljrc888 danieljrc888 force-pushed the drojas/dxp-372-add-provider-and-model-to-gen_call branch from 259f02f to b514044 Compare June 12, 2025 17:14
@danieljrc888 danieljrc888 requested a review from cristiam86 June 12, 2025 17:20
@danieljrc888 danieljrc888 force-pushed the drojas/dxp-372-add-provider-and-model-to-gen_call branch from 6e59ab1 to 4b2252a Compare June 13, 2025 13:56
@danieljrc888 danieljrc888 force-pushed the drojas/dxp-372-add-provider-and-model-to-gen_call branch from 3585868 to 69fa467 Compare June 18, 2025 16:04
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
5.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@danieljrc888 danieljrc888 marked this pull request as draft June 25, 2025 17:48
@danieljrc888 danieljrc888 changed the title feat: add provider and model to gen call feat: implement sim call rpc endpoint Jun 25, 2025
@cristiam86 cristiam86 closed this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants