Skip to content

Conversation

@NiveditJain
Copy link
Member

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 4, 2025

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Introduced an API endpoint for registering nodes within a namespace, allowing batch registration with input/output schemas.
    • Added support for structured node registration requests and responses, improving clarity and validation.
    • Enhanced node management by storing node details, schemas, and runtime information in the backend.
  • Bug Fixes
    • Improved error handling for node registration failures.
  • Chores
    • Updated backend models and database initialization to support node registration features.

Walkthrough

The changes refactor the node registration and startup flow in the Runtime class. The _connected flag and its logic are removed. Node registration is now handled asynchronously within the startup sequence through a new _register_nodes method, and method signatures are updated to pass nodes explicitly. Error logging is added for registration failures.

Changes

Cohort / File(s) Change Summary
Runtime Refactor
python-sdk/exospherehost/runtime.py
Removes _connected flag and related logic; introduces async node registration via _register_nodes; updates method signatures for start, _start, and connection flow; adds error logging for registration failures.
Node Registration Controller
state-manager/app/controller/register_nodes.py
Adds async function register_nodes to register or update nodes in the database, with detailed logging and error handling.
Database Model Addition
state-manager/app/models/db/registered_node.py
Introduces new RegisteredNode data model with fields for node identity, runtime info, and input/output schemas.
Request Models for Registration
state-manager/app/models/register_nodes_request.py
Adds Pydantic models NodeRegistrationModel and RegisterNodesRequestModel for structured node registration requests.
Response Models for Registration
state-manager/app/models/register_nodes_response.py
Adds Pydantic models RegisteredNodeModel and RegisterNodesResponseModel for structured registration responses.
API Route Addition
state-manager/app/routes.py
Adds new PUT API route /v0/namespace/{namespace_name}/nodes/ for node registration with API key validation and error handling.
Beanie ODM Initialization Update
state-manager/app/main.py
Updates Beanie initialization to include the new RegisteredNode model alongside existing models.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

🐇
The nodes now register with flair,
No more flags floating in the air.
Async flows begin the show,
With schemas sent where they must go.
Startup’s tidy, errors logged with care—
A rabbit’s hop to code that’s rare!

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dd4570d and 72baee6.

📒 Files selected for processing (3)
  • state-manager/app/controller/register_nodes.py (1 hunks)
  • state-manager/app/models/register_nodes_request.py (1 hunks)
  • state-manager/app/models/register_nodes_response.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
state-manager/app/models/register_nodes_request.py (4)
state-manager/app/models/create_models.py (2)
  • RequestStateModel (7-9)
  • ResponseStateModel (12-16)
state-manager/app/models/enqueue_response.py (1)
  • StateModel (6-10)
state-manager/app/models/enqueue_request.py (1)
  • EnqueueRequestModel (4-6)
state-manager/app/models/db/state.py (1)
  • State (7-14)
state-manager/app/models/register_nodes_response.py (5)
state-manager/app/models/create_models.py (2)
  • ResponseStateModel (12-16)
  • RequestStateModel (7-9)
state-manager/app/models/enqueue_response.py (2)
  • StateModel (6-10)
  • EnqueueResponseModel (13-18)
state-manager/app/models/db/state.py (1)
  • State (7-14)
state-manager/app/models/enqueue_request.py (1)
  • EnqueueRequestModel (4-6)
state-manager/app/models/errored_models.py (1)
  • ErroredResponseModel (9-10)
🔇 Additional comments (7)
state-manager/app/models/register_nodes_request.py (2)

5-8: LGTM! Well-structured node model.

The NodeRegistrationModel properly captures all necessary node attributes with appropriate types and descriptive field annotations.


11-13: LGTM! Appropriate batch registration model.

The RegisterNodesRequestModel correctly groups runtime identification with the list of nodes to register, providing a clean API contract.

state-manager/app/controller/register_nodes.py (3)

1-8: LGTM! Clean imports and logger setup.

The imports are well-organized and the logger initialization is appropriate for the controller functionality.


11-17: LGTM! Well-structured function with proper logging.

The function signature is appropriate and the overall structure with comprehensive logging provides good observability for the registration process.

Also applies to: 58-64


66-68: LGTM! Proper exception handling.

The exception handling correctly logs errors and re-raises them, maintaining the error context while providing observability.

state-manager/app/models/register_nodes_response.py (2)

5-8: LGTM! Well-designed response model.

The RegisteredNodeModel appropriately captures the essential node information for the response with clear field descriptions.


11-13: LGTM! Comprehensive response structure.

The RegisterNodesResponseModel provides good context by including both the runtime name and the list of registered nodes, making the response self-contained and informative.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

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: 2

🔭 Outside diff range comments (2)
python-sdk/exospherehost/runtime.py (2)

137-155: Update docstring to reflect the method's new purpose.

The docstring still refers to "connecting" nodes, but the method is now _register and handles registration.

 async def _register(self, nodes: List[BaseNode]):
     """
-    Connect nodes to the runtime.
+    Register nodes with the runtime.
     
-    This method validates and registers the provided nodes with the runtime.
-    The nodes will be available for execution when the runtime starts.
+    This method validates the provided nodes, updates internal mappings,
+    and registers them with the state manager service.
     
     Args:
         nodes (List[BaseNode]): List of BaseNode instances to connect
         
     Raises:
         ValueError: If any node does not inherit from BaseNode
+        RuntimeError: If node registration fails
     """

284-299: Update docstring to remove outdated RuntimeError description.

The docstring still mentions raising RuntimeError when "not connected", but this check has been removed.

 async def _start(self, nodes: List[BaseNode]):
     """
     Start the runtime execution.
     
     This method starts the enqueue polling task and spawns worker tasks
     to process states from the queue.
     
     Raises:
-        RuntimeError: If the runtime is not connected (no nodes registered)
+        ValueError: If any node does not inherit from BaseNode
+        RuntimeError: If node registration fails
     """
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0e894cc and 3f7c896.

📒 Files selected for processing (1)
  • python-sdk/exospherehost/runtime.py (5 hunks)
🔇 Additional comments (3)
python-sdk/exospherehost/runtime.py (3)

107-109: LGTM!

The new endpoint getter follows the established pattern for other endpoint methods in the class.


301-316: Good API simplification!

The consolidated approach of passing nodes directly to start() eliminates the need for a separate connection step, making the API more intuitive.


137-155: Breaking API change requires user migration.

This refactoring changes the public API by requiring nodes to be passed to start() instead of calling connect() first. Ensure that:

  1. This breaking change is documented in release notes
  2. Migration guide is provided for existing users
  3. Examples and documentation are updated

Also applies to: 284-299, 301-316

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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a5244b4 and 35bba89.

📒 Files selected for processing (6)
  • state-manager/app/controller/register_nodes.py (1 hunks)
  • state-manager/app/main.py (2 hunks)
  • state-manager/app/models/db/registered_node.py (1 hunks)
  • state-manager/app/models/register_nodes_request.py (1 hunks)
  • state-manager/app/models/register_nodes_response.py (1 hunks)
  • state-manager/app/routes.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
state-manager/app/models/register_nodes_response.py (6)
state-manager/app/models/create_models.py (3)
  • ResponseStateModel (12-16)
  • RequestStateModel (7-9)
  • CreateResponseModel (23-25)
state-manager/app/models/enqueue_response.py (2)
  • StateModel (6-10)
  • EnqueueResponseModel (13-18)
state-manager/app/models/db/state.py (1)
  • State (7-14)
state-manager/app/models/enqueue_request.py (1)
  • EnqueueRequestModel (4-6)
state-manager/app/models/errored_models.py (1)
  • ErroredResponseModel (9-10)
state-manager/app/models/executed_models.py (1)
  • ExecutedResponseModel (9-10)
state-manager/app/routes.py (4)
state-manager/app/models/register_nodes_request.py (1)
  • RegisterNodesRequestModel (12-15)
state-manager/app/models/register_nodes_response.py (1)
  • RegisterNodesResponseModel (10-13)
state-manager/app/controller/register_nodes.py (1)
  • register_nodes (11-67)
state-manager/app/utils/check_secret.py (1)
  • check_api_key (15-19)
🔇 Additional comments (10)
state-manager/app/models/register_nodes_request.py (1)

5-9: LGTM! Well-structured node registration model.

The NodeRegistrationModel follows consistent patterns with other Pydantic models in the codebase and appropriately uses dict[str, Any] for JSON schema fields. Field descriptions are clear and all required fields are properly annotated.

state-manager/app/main.py (2)

24-24: LGTM! Proper model import.

The import of RegisteredNode is correctly added alongside other database models.


40-40: LGTM! Correct Beanie ODM integration.

Adding RegisteredNode to the document models list properly integrates the new model with the database initialization process.

state-manager/app/models/db/registered_node.py (1)

6-12: LGTM! Well-designed database model.

The RegisteredNode model is properly structured with appropriate field types and comprehensive metadata. The use of dict[str, Any] for schema fields is correct for storing JSON schemas, and the runtime tracking fields enable proper node ownership management.

state-manager/app/controller/register_nodes.py (2)

11-18: LGTM! Well-structured function signature and initialization.

The function signature properly accepts all necessary parameters with correct type annotations. The initial logging with request ID tracking is a good practice.


56-67: LGTM! Proper response construction and error handling.

The response model construction correctly maps the processed data, and the error handling appropriately logs errors with request ID context while preserving the original exception for upstream handling.

state-manager/app/models/register_nodes_response.py (1)

5-7: LGTM! Appropriate response model structure.

The RegisteredNodeModel correctly provides essential node identification without unnecessarily echoing back the full schema data, which is a good practice for response models.

state-manager/app/routes.py (3)

24-26: LGTM!

The imports are correctly structured and follow the established pattern in the file for bringing in the necessary components for the new node registration route.


131-132: Good formatting improvement.

The additional newlines provide better visual separation between route handlers, improving code readability.


134-150: Excellent implementation following established patterns.

The new route handler correctly follows all the established patterns in the file:

  • Proper FastAPI decorator configuration with appropriate status code for upsert operations
  • Consistent parameter structure and API key validation
  • Same request ID extraction and logging patterns
  • Proper error handling structure

The use of HTTP 200 OK is appropriate since the controller performs upsert operations (update existing or create new nodes).

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

♻️ Duplicate comments (1)
state-manager/app/controller/register_nodes.py (1)

32-33: Remove unused inserted_node and clean up schema type ignores

The # type: ignore comments suggest potential type mismatches with the Beanie Set operator usage. This could indicate issues with the schema field definitions.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 35bba89 and dd4570d.

📒 Files selected for processing (1)
  • state-manager/app/controller/register_nodes.py (1 hunks)
🔇 Additional comments (3)
state-manager/app/controller/register_nodes.py (3)

1-8: LGTM!

The imports are well-organized and appropriate for the node registration functionality. The separation of request/response models, database models, and utilities follows good architectural practices.


11-17: LGTM!

The function signature is well-designed with proper typing, clear parameter separation, and good observability through the request ID parameter. The try-catch structure and initial logging provide good error handling foundation.


57-68: LGTM!

The response construction is clean and well-structured. The error handling appropriately logs errors while preserving the original exception for upstream handling. The success logging provides good observability.

@NiveditJain NiveditJain merged commit 7564ba6 into exospherehost:main Aug 4, 2025
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 23, 2025
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.

1 participant