Skip to content

feat(spider-grpc): Add gRPC for scheduler service; Add gRPC scheduler client in execution manager.#342

Open
sitaowang1998 wants to merge 16 commits into
y-scope:mainfrom
sitaowang1998:grpc-scheduler
Open

feat(spider-grpc): Add gRPC for scheduler service; Add gRPC scheduler client in execution manager.#342
sitaowang1998 wants to merge 16 commits into
y-scope:mainfrom
sitaowang1998:grpc-scheduler

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR:

  • Adds gRPC proto for scheduler service for execution manager.
  • Moves shared proto types to common proto file.
  • Adds gRPC scheduler client in execution manager.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • GitHub workflows pass.

Summary by CodeRabbit

  • Chores
    • Reorganized internal scheduler service architecture and consolidated shared data type definitions for improved code maintainability and modularity.

@sitaowang1998 sitaowang1998 requested a review from a team as a code owner June 14, 2026 03:53
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@sitaowang1998, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 2 minutes and 53 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 725168fe-587d-41ea-a08e-3b62e6eac8ae

📥 Commits

Reviewing files that changed from the base of the PR and between c370dea and ed27d77.

⛔ Files ignored due to path filters (1)
  • components/spider-proto-rust/src/generated/storage.rs is excluded by !**/generated/**
📒 Files selected for processing (1)
  • components/spider-proto/storage/storage.proto

Walkthrough

Introduces common.proto with shared TaskId and Void message types, migrates storage.proto to use them, and adds scheduler.proto defining SchedulerService. The spider-proto-rust crate is updated to expose common and scheduler modules and switch TaskId conversion impls to common::TaskId. A new GrpcSchedulerClient is added to the execution manager.

Changes

Scheduler gRPC client and common proto types

Layer / File(s) Summary
common.proto: shared TaskId and Void definitions
components/spider-proto/common/common.proto
Introduces common.proto defining the empty Void message and a TaskId oneof (index/commit/cleanup variants) consumed by both storage and scheduler protos.
scheduler.proto: SchedulerService and message definitions
components/spider-proto/scheduler/scheduler.proto
Adds scheduler.proto with SchedulerService, NextTask RPC, NextTaskRequest/NextTaskResponse messages, and SchedulerAssignment using common.TaskId.
storage.proto: migrate to common.TaskId and common.Void
components/spider-proto/storage/storage.proto
Imports common.proto, replaces local TaskId and Void with common.TaskId/common.Void across RPCs, ReadyTask, request messages, and operation response wrappers, then removes the now-redundant local declarations.
spider-proto-rust: expose common/scheduler modules and update TaskId conversions
components/spider-proto-rust/build.rs, components/spider-proto-rust/src/lib.rs, components/spider-proto-rust/src/id.rs, components/spider-proto-rust/src/error.rs
Expands the build script to compile common.proto and scheduler.proto, adds pub mod common and pub mod scheduler, migrates TaskId conversion impls from storage::TaskId to common::TaskId, updates the TaskIdKindMissing doc comment, and updates conversion tests.
Update storage and scheduler storage clients to use common::TaskId
components/spider-execution-manager/src/client/grpc/storage.rs, components/spider-scheduler/src/storage_client/grpc.rs
Restructures imports to include common from spider_proto_rust and constructs task_id fields using common::TaskId::from in three request builders; updates scheduler storage client test accordingly.
GrpcSchedulerClient implementation and wiring
components/spider-execution-manager/src/client/grpc/scheduler.rs, components/spider-execution-manager/src/client/grpc/mod.rs
Adds GrpcSchedulerClient with a connect constructor, a next_task polling loop, scheduler_response_to_result for protobuf-to-internal conversion with protocol validation, a to_transport_error helper, unit tests, and re-exports from the gRPC module.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • y-scope/spider#327: Introduced the SchedulerClient trait, SchedulerResponse, and SchedulerError types that GrpcSchedulerClient in this PR implements.
  • y-scope/spider#331: Refactored the core TaskId representation (Index/Commit/Cleanup), which is directly mapped into common::TaskId by the updated conversion impls in this PR.
  • y-scope/spider#329: Added the execution-manager runtime main loop that consumes SchedulerClient::next_task, which GrpcSchedulerClient from this PR implements.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding gRPC scheduler service proto definitions and implementing a gRPC scheduler client in the execution manager.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@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 (1)
components/spider-execution-manager/src/client/grpc/scheduler.rs (1)

121-184: ⚡ Quick win

Consider adding test coverage for the NoTask variant and malformed task ID conversion.

The existing tests cover assignment success, missing result, and missing task ID, but two code paths remain untested:

  1. The NoTask variant (line 105) that returns Ok(None)
  2. The error path when TaskId::try_from fails due to a malformed task ID (e.g., common::TaskId { kind: None })

Adding these tests would improve confidence in the protocol validation logic.

📋 Suggested additional tests
+    #[test]
+    fn scheduler_response_to_result_returns_none_for_no_task() {
+        let response = NextTaskResponse {
+            result: Some(next_task_response::Result::NoTask(common::Void {})),
+        };
+
+        let result = scheduler_response_to_result(response)
+            .expect("scheduler response conversion should succeed");
+
+        assert!(result.is_none());
+    }
+
+    #[test]
+    fn scheduler_response_to_result_rejects_malformed_task_id() {
+        let response = NextTaskResponse {
+            result: Some(next_task_response::Result::Assignment(
+                SchedulerAssignment {
+                    job_id: 11,
+                    task_id: Some(common::TaskId { kind: None }),
+                    resource_group_id: 13,
+                    session_id: 17,
+                },
+            )),
+        };
+
+        let result = scheduler_response_to_result(response);
+
+        assert!(result.is_err());
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/spider-execution-manager/src/client/grpc/scheduler.rs` around
lines 121 - 184, Add two new test cases to the tests module in scheduler.rs to
improve coverage of untested code paths. First, create a test that verifies
scheduler_response_to_result correctly returns Ok(None) when the NoTask variant
is provided in the response result. Second, create a test that verifies
scheduler_response_to_result returns an error when TaskId::try_from fails due to
a malformed task ID (such as a common::TaskId with kind set to None). Both tests
should follow the naming convention and assertion patterns of the existing test
functions like scheduler_response_to_result_rejects_missing_result and
scheduler_response_to_result_rejects_empty_assignment_task_id.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/spider-proto/common/common.proto`:
- Line 3: The proto compilation is failing because Buf cannot locate the module
root for the proto files in components/spider-proto/. To fix this, create a
buf.yaml configuration file in the components/spider-proto/ directory to declare
it as a Buf module, or alternatively create a buf.work.yaml at the repository
root to include components/spider-proto/ as a workspace module. This will allow
Buf to properly resolve proto imports and enable downstream files to
successfully import common.TaskId and common.Void from the common package
declaration.

---

Nitpick comments:
In `@components/spider-execution-manager/src/client/grpc/scheduler.rs`:
- Around line 121-184: Add two new test cases to the tests module in
scheduler.rs to improve coverage of untested code paths. First, create a test
that verifies scheduler_response_to_result correctly returns Ok(None) when the
NoTask variant is provided in the response result. Second, create a test that
verifies scheduler_response_to_result returns an error when TaskId::try_from
fails due to a malformed task ID (such as a common::TaskId with kind set to
None). Both tests should follow the naming convention and assertion patterns of
the existing test functions like
scheduler_response_to_result_rejects_missing_result and
scheduler_response_to_result_rejects_empty_assignment_task_id.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c217c818-67d2-4373-98f1-3da1177d00fb

📥 Commits

Reviewing files that changed from the base of the PR and between 42bbdb6 and c370dea.

⛔ Files ignored due to path filters (3)
  • components/spider-proto-rust/src/generated/common.rs is excluded by !**/generated/**
  • components/spider-proto-rust/src/generated/scheduler.rs is excluded by !**/generated/**
  • components/spider-proto-rust/src/generated/storage.rs is excluded by !**/generated/**
📒 Files selected for processing (11)
  • components/spider-execution-manager/src/client/grpc/mod.rs
  • components/spider-execution-manager/src/client/grpc/scheduler.rs
  • components/spider-execution-manager/src/client/grpc/storage.rs
  • components/spider-proto-rust/build.rs
  • components/spider-proto-rust/src/error.rs
  • components/spider-proto-rust/src/id.rs
  • components/spider-proto-rust/src/lib.rs
  • components/spider-proto/common/common.proto
  • components/spider-proto/scheduler/scheduler.proto
  • components/spider-proto/storage/storage.proto
  • components/spider-scheduler/src/storage_client/grpc.rs

Comment thread components/spider-proto/common/common.proto
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