Skip to content

feat: new strict nondet and nondet_unsafe#274

Merged
epsjunior merged 1 commit into
mainfrom
dxp-556-explain-different-eq-principle-methods-and-formats
Aug 7, 2025
Merged

feat: new strict nondet and nondet_unsafe#274
epsjunior merged 1 commit into
mainfrom
dxp-556-explain-different-eq-principle-methods-and-formats

Conversation

@epsjunior

@epsjunior epsjunior commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

Comprehensive Equivalence Principles Documentation

Added complete coverage of all GenLayer equivalence principle methods with practical examples and clear guidance.

New Content Added:

  • Strict Equivalence Principle - Complete documentation with use cases and examples
  • Custom Leader/Validator Patterns - Both gl.vm.run_nondet (safe) and gl.vm.run_nondet_unsafe (performance-focused) variants
  • Advanced Error Handling - Custom error comparison functions with working examples
  • Real-world Examples - Article scoring contract demonstrating custom validation logic

Improvements:

  • Used generic naming conventions (assignments, article_text) instead of project-specific terms
  • Added clear warnings and notes about error handling differences
  • Included practical code examples that developers can use as templates
  • Maintained consistent, direct documentation style without promotional language

The documentation now provides developers with complete guidance on choosing and implementing the right equivalence principle for their specific use case, from simple boolean operations to complex custom scoring systems.

Summary by CodeRabbit

  • Documentation
    • Added detailed explanations and examples for the "Strict Equivalence Principle," illustrating exact matching validation scenarios.
    • Introduced comprehensive guidance on implementing custom leader/validator patterns, including safe and fast variants, with code samples and advanced error handling strategies.
    • Enhanced documentation with practical Python examples for various validation approaches.

@netlify

netlify Bot commented Aug 6, 2025

Copy link
Copy Markdown

Deploy Preview for genlayer-docs ready!

Name Link
🔨 Latest commit e11cdd3
🔍 Latest deploy log https://app.netlify.com/projects/genlayer-docs/deploys/6893e2435162af0007eaccdd
😎 Deploy Preview https://deploy-preview-274--genlayer-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new section on the "Strict Equivalence Principle" has been added to the documentation, along with detailed explanations and Python code samples for implementing custom leader/validator patterns. The update covers both safe (sandboxed) and fast (unsafe) custom validation flows, including advanced error handling strategies.

Changes

Cohort / File(s) Change Summary
Documentation: Equivalence and Custom Validation
pages/developers/intelligent-contracts/equivalence-principle.mdx
Added sections on Strict Equivalence Principle, safe/unsafe custom leader/validator patterns, and advanced error handling examples.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Leader
    participant Validator
    participant GL as gl.vm

    User->>Leader: Submit input data
    Leader->>GL: Run leader function
    GL->>Validator: Run validator function (sandboxed or unsafe)
    Validator-->>GL: Return result or error
    GL->>User: Compare outputs (strict or custom logic)\nReturn validation result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested reviewers

  • MuncleUscles

Poem

In the warren, docs grow neat and thick,
With strict equivalence—no clever trick!
Leaders and validators, custom and bold,
Hop through examples, their stories retold.
Sandboxes safe or speedy and quick,
This rabbit approves—what a clever pick! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dxp-556-explain-different-eq-principle-methods-and-formats

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
pages/developers/intelligent-contracts/equivalence-principle.mdx (5)

98-105: Add import json to keep the snippet copy-pasteable

Readers will get a NameError: name 'json' is not defined if they copy this example verbatim. A one-line import keeps the snippet self-contained.

 def fetch_content():
+    import json
     response = gl.nondet.web.get("https://example.com")
     body = json.loads(response.body)
     return body["valid"]

108-114: Clarify the exact return type for strict equality

check_condition() currently returns a raw string ("true" / "false"), but downstream code may expect a boolean. To avoid confusion, either cast to bool or explicitly state that the strict-equality contract compares strings.


135-146: Example missing json import

Same issue as above: the snippet won’t run standalone.

 def leader_fn():
+    import json
     response = gl.nondet.exec_prompt(prompt)
     return json.loads(response)

148-160: Avoid re-executing the leader logic inside the validator to cut cost & latency

validator_fn calls leader_fn() again, duplicating the non-deterministic operation (extra prompt, LLM cost, latency). Prefer executing validator-specific logic instead:

-    def validator_fn(leader_res: gl.vm.Result) -> bool:
-        if not isinstance(leader_res, gl.vm.Return):
-            return False
-
-        validator_res = leader_fn()
-        leader_score = leader_res.calldata["score"]
-        validator_score = validator_res["score"]
+    def validator_fn(leader_res: gl.vm.Result) -> bool:
+        if not isinstance(leader_res, gl.vm.Return):
+            return False
+
+        # Independently re-compute *only* the score
+        validator_score = gl.nondet.exec_prompt(prompt)
+        validator_score = json.loads(validator_score)["score"]
+        leader_score = leader_res.calldata["score"]

This keeps validator work independent while avoiding double JSON parsing & prompt cost.


207-214: Nit: tighten the custom-error comparison example

Minor phrasing—in error1.message checks for substrings; consider .lower() or regex to make the comparison case-insensitive and future-proof.

-    return "timeout" in error1.message and "timeout" in error2.message
+    return "timeout" in error1.message.lower() and "timeout" in error2.message.lower()
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6041956 and e11cdd3.

📒 Files selected for processing (1)
  • pages/developers/intelligent-contracts/equivalence-principle.mdx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
pages/**/*.mdx

📄 CodeRabbit Inference Engine (CLAUDE.md)

pages/**/*.mdx: All content is in MDX format supporting React components
Import and use custom components within MDX files
Create .mdx file in appropriate pages/ subdirectory when adding new pages
All content should support React components in MDX files

Files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
🧠 Learnings (11)
📓 Common learnings
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Setup Guide Updates (pages/validators/setup-guide.mdx): Update version references in download examples and version lists, update configuration examples with new contract addresses when applicable, enhance command documentation when new features are added to existing commands, update genesis block configuration in consensus section when network upgrades occur
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : GenVM diagnostics integration affects the doctor command behavior and should be documented in the validator setup guide
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update genesis block configuration in consensus section of setup-guide.mdx when network upgrades occur
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Consensus contract addresses change with network upgrades and must be updated in configuration examples
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update configuration examples with new contract addresses in setup-guide.mdx when applicable
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update version references in download examples and version lists in setup-guide.mdx when new validator releases occur
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update version list in curl command output example (line ~88), download command version variable (line ~113), consensus contract addresses and genesis block number (lines ~143-146), and command documentation (line ~347) in setup-guide.mdx for new validator releases
📚 Learning: applies to pages/validators/setup-guide.mdx : setup guide updates (pages/validators/setup-guide.mdx)...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Setup Guide Updates (pages/validators/setup-guide.mdx): Update version references in download examples and version lists, update configuration examples with new contract addresses when applicable, enhance command documentation when new features are added to existing commands, update genesis block configuration in consensus section when network upgrades occur

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/setup-guide.mdx : update configuration examples with new contract addres...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update configuration examples with new contract addresses in setup-guide.mdx when applicable

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/setup-guide.mdx : update genesis block configuration in consensus sectio...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update genesis block configuration in consensus section of setup-guide.mdx when network upgrades occur

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/setup-guide.mdx : update version list in curl command output example (li...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update version list in curl command output example (line ~88), download command version variable (line ~113), consensus contract addresses and genesis block number (lines ~143-146), and command documentation (line ~347) in setup-guide.mdx for new validator releases

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/setup-guide.mdx : update version references in download examples and ver...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update version references in download examples and version lists in setup-guide.mdx when new validator releases occur

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/setup-guide.mdx : update consensus contract addresses and genesis block ...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Update consensus contract addresses and genesis block number in setup-guide.mdx when network upgrades occur

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/setup-guide.mdx : consensus contract addresses change with network upgra...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Consensus contract addresses change with network upgrades and must be updated in configuration examples

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/setup-guide.mdx : genvm diagnostics integration affects the doctor comma...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : GenVM diagnostics integration affects the doctor command behavior and should be documented in the validator setup guide

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/changelog.mdx : changelog updates (pages/validators/changelog.mdx): add ...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/changelog.mdx : Changelog Updates (pages/validators/changelog.mdx): Add new version entries at the top in reverse chronological order, use consistent format: # v0.x.x, ## New features, ## Bug fixes, ## Misc, and include missing intermediate versions if needed

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx
📚 Learning: applies to pages/validators/setup-guide.mdx : enhance command documentation in setup-guide.mdx when ...
Learnt from: CR
PR: genlayerlabs/genlayer-docs#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-24T07:56:58.272Z
Learning: Applies to pages/validators/setup-guide.mdx : Enhance command documentation in setup-guide.mdx when new features are added to existing commands

Applied to files:

  • pages/developers/intelligent-contracts/equivalence-principle.mdx

Comment thread pages/developers/intelligent-contracts/equivalence-principle.mdx
@epsjunior epsjunior requested a review from kp2pml30 August 6, 2025 23:44

@kp2pml30 kp2pml30 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work, thanks!

@epsjunior epsjunior merged commit 5b1b16f into main Aug 7, 2025
5 of 6 checks passed
@epsjunior epsjunior deleted the dxp-556-explain-different-eq-principle-methods-and-formats branch August 7, 2025 11:39
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