Skip to content

fix(huntsman): Add ResendReadyTasks protocol, implmentation and usage. - #372

Closed
sitaowang1998 wants to merge 36 commits into
y-scope:mainfrom
sitaowang1998:resend-ready-tasks
Closed

fix(huntsman): Add ResendReadyTasks protocol, implmentation and usage.#372
sitaowang1998 wants to merge 36 commits into
y-scope:mainfrom
sitaowang1998:resend-ready-tasks

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Note

This PR depends on #364.

Description

This PR resolves #352 by:

  • Adding ResendReadyTasks gRPC protocol.
  • Adding its gRPC service implementation in storage cache layer by calling existing inbound queue function.
  • Adding its use in scheduler, including the function in gRPC client and call to it on runtime creation.

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

Summary by CodeRabbit

  • New Features

    • Added a storage RPC to resend ready tasks, enabling queued work to be reprocessed.
    • Scheduler now triggers a resend of ready tasks immediately after successful registration.
  • Bug Fixes

    • Implemented previously-missing inbound queue, scheduler, and session gRPC handlers in storage.
    • Improved request validation and error responses (including more accurate handling of invalid input and authentication failures).

sitaowang1998 and others added 30 commits June 26, 2026 16:31
# Conflicts:
#	components/spider-proto-rust/src/generated/storage.rs
#	components/spider-proto/storage/storage.proto
#	components/spider-scheduler/src/storage_client/grpc.rs
@sitaowang1998
sitaowang1998 requested a review from a team as a code owner July 3, 2026 16:28
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e1832bfa-7d4d-4e51-ac80-6f0ede5f281d

📥 Commits

Reviewing files that changed from the base of the PR and between ac5e5d6 and dfc918d.

📒 Files selected for processing (2)
  • components/spider-scheduler/src/storage_client/mod.rs
  • components/spider-storage/src/grpc.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/spider-scheduler/src/storage_client/mod.rs
  • components/spider-storage/src/grpc.rs

Walkthrough

Adds a storage RPC for resending ready tasks, wires it through the scheduler client and runtime, implements storage gRPC endpoints, centralizes error handling, adds scheduler registration conversion, and extends request unpacking.

Changes

Resend ready tasks and scheduler wiring

Layer / File(s) Summary
Resend-ready-tasks wiring
components/spider-proto/storage/storage.proto, components/spider-scheduler/src/storage_client/mod.rs, components/spider-scheduler/src/storage_client/grpc.rs, components/spider-scheduler/src/runtime.rs, components/spider-scheduler/src/core_impl/round_robin/tests.rs
Adds the ResendReadyTasks RPC, exposes it on SchedulerStorageClient, implements the gRPC call, invokes it after scheduler registration, and updates test doubles.
Scheduler error variant removal
components/spider-scheduler/src/error.rs
Removes StorageClientError::StaleSession.
Scheduler registration conversion
components/spider-proto-rust/src/lib.rs, components/spider-proto-rust/src/scheduler_registration.rs
Exports a new conversion module that maps RegisteredScheduler into storage::Scheduler and verifies it in a unit test.
Storage request unpacking
components/spider-proto-rust/src/unpack/storage.rs
Adds unpackers for resource group, execution manager, scheduler registration, and poll-ready-tasks requests, plus a shared invalid-argument helper.
Storage gRPC error handling
components/spider-storage/src/grpc.rs
Refactors storage gRPC error mapping around centralized internal-status helpers and updated service-specific handlers.
Storage gRPC implementations
components/spider-storage/src/grpc.rs, components/spider-storage/src/state.rs
Implements inbound queue, resource group, execution manager, scheduler registration, and session gRPC methods, and widens test_utils visibility.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Runtime as create_runtime
  participant Client as GrpcSchedulerStorageClient
  participant Storage as InboundQueueService

  Runtime->>Client: register_scheduler()
  Client->>Storage: gRPC RegisterScheduler
  Storage-->>Client: RegisterSchedulerResponse
  Runtime->>Client: resend_ready_tasks()
  Client->>Storage: gRPC ResendReadyTasks(Void)
  Storage-->>Client: Void response
  Client-->>Runtime: Ok(())
Loading

Possibly related PRs

  • y-scope/spider#323: Adds storage ServiceState APIs that the new gRPC implementations call.
  • y-scope/spider#343: Also wires resend_ready_tasks through storage runtime and gRPC paths.
  • y-scope/spider#347: Also covers scheduler registration types and related protobuf wiring.

Suggested reviewers: LinZhihao-723

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds ResendReadyTasks to InboundQueueService, but the issue required moving it out of JobOrchestrationService with its request message. Move the RPC and its request message into a dedicated scheduler-facing service, then update the server trait implementation and scheduler client calls to match.
Out of Scope Changes check ⚠️ Warning The PR also implements several unrelated storage gRPC methods and refactors error handling, which go beyond the ResendReadyTasks scope. Split the extra storage gRPC implementations and error-handling refactor into separate work, leaving this PR focused on the new ResendReadyTasks endpoint.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the change set by naming the new ResendReadyTasks protocol and its usage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

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

🧹 Nitpick comments (2)
components/spider-scheduler/src/runtime.rs (1)

128-129: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider logging on successful resend, matching the registration log above.

Line 126 logs after a successful register, but the new resend_ready_tasks call is silent on success, making it harder to confirm in logs that ready-task recovery ran after a scheduler restart.

♻️ Suggested tweak
     storage_client.resend_ready_tasks().await?;
+    tracing::info!("Resent ready tasks to storage.");
🤖 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-scheduler/src/runtime.rs` around lines 128 - 129, The
resend_ready_tasks recovery path in runtime::run is currently silent on success,
unlike the nearby register success log. After
storage_client.resend_ready_tasks().await succeeds, add an info-level log that
clearly states ready-task recovery/resend completed so scheduler restarts can be
confirmed in logs. Use the existing logging pattern around register and the
runtime::run flow to keep the message consistent.
components/spider-proto-rust/src/unpack/storage.rs (1)

209-225: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Unbounded wait_ms could allow arbitrarily long blocking polls.

max_items is checked to fit usize, but wait_ms/Duration::from_millis(self.wait_ms) has no upper bound. A client can request an effectively unbounded wait (e.g., u64::MAX ms), tying up a server-side poll for the whole duration unless it's independently capped downstream in ServiceState::poll_ready_tasks. Consider clamping wait_ms (and possibly max_items) to a sane maximum here so misbehaving/malicious clients can't hold connections open indefinitely.

💡 Illustrative fix
+const MAX_POLL_WAIT: Duration = Duration::from_secs(60);
+
 impl RequestUnpack for PollReadyTasksRequest {
     type Unpacked = (usize, Duration);
 
     fn unpack(self) -> Result<Self::Unpacked, UnpackError> {
         let max_items = usize::try_from(self.max_items).map_err(|_| {
             invalid_argument(format!(
                 "max_items does not fit in `usize`: {}",
                 self.max_items
             ))
         })?;
-        Ok((max_items, Duration::from_millis(self.wait_ms)))
+        let wait = Duration::from_millis(self.wait_ms).min(MAX_POLL_WAIT);
+        Ok((max_items, wait))
     }
 }

Please confirm whether ServiceState::poll_ready_tasks already bounds the wait time internally (e.g., against a shutdown/cancellation signal); if so this can be deprioritized.

🤖 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-proto-rust/src/unpack/storage.rs` around lines 209 - 225,
In RequestUnpack for PollReadyTasksRequest, wait_ms is converted directly into
Duration::from_millis without any upper bound, so clamp or reject overly large
values alongside the existing max_items usize check. Update the unpack logic to
enforce a sane maximum for wait_ms before returning the tuple, and verify
whether ServiceState::poll_ready_tasks already caps blocking time; if not, add
the limit here so PollReadyTasksRequest cannot request an unbounded poll.
🤖 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.

Nitpick comments:
In `@components/spider-proto-rust/src/unpack/storage.rs`:
- Around line 209-225: In RequestUnpack for PollReadyTasksRequest, wait_ms is
converted directly into Duration::from_millis without any upper bound, so clamp
or reject overly large values alongside the existing max_items usize check.
Update the unpack logic to enforce a sane maximum for wait_ms before returning
the tuple, and verify whether ServiceState::poll_ready_tasks already caps
blocking time; if not, add the limit here so PollReadyTasksRequest cannot
request an unbounded poll.

In `@components/spider-scheduler/src/runtime.rs`:
- Around line 128-129: The resend_ready_tasks recovery path in runtime::run is
currently silent on success, unlike the nearby register success log. After
storage_client.resend_ready_tasks().await succeeds, add an info-level log that
clearly states ready-task recovery/resend completed so scheduler restarts can be
confirmed in logs. Use the existing logging pattern around register and the
runtime::run flow to keep the message consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1796357e-c9e7-4a08-a7f7-646d466cd54a

📥 Commits

Reviewing files that changed from the base of the PR and between 4ace626 and ac5e5d6.

⛔ Files ignored due to path filters (1)
  • components/spider-proto-rust/src/generated/storage.rs is excluded by !**/generated/**
📒 Files selected for processing (11)
  • components/spider-proto-rust/src/lib.rs
  • components/spider-proto-rust/src/scheduler_registration.rs
  • components/spider-proto-rust/src/unpack/storage.rs
  • components/spider-proto/storage/storage.proto
  • components/spider-scheduler/src/core_impl/round_robin/tests.rs
  • components/spider-scheduler/src/error.rs
  • components/spider-scheduler/src/runtime.rs
  • components/spider-scheduler/src/storage_client/grpc.rs
  • components/spider-scheduler/src/storage_client/mod.rs
  • components/spider-storage/src/grpc.rs
  • components/spider-storage/src/state.rs
💤 Files with no reviewable changes (1)
  • components/spider-scheduler/src/error.rs

@LinZhihao-723 LinZhihao-723 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.

Did you miss what we've discussed offline? This implementation is fundamentally wrong: resend_ready_tasks shouldn't be a gRPC call. Instead, it should be executed internally as a part of scheduler registration, not explicitly called by the scheduler.

@LinZhihao-723

Copy link
Copy Markdown
Member

Close this PR for the reason pointed in #372 (review).

@sitaowang1998
sitaowang1998 deleted the resend-ready-tasks branch July 5, 2026 20:43
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.

Move ResendReadyTasks RPC to a dedicated scheduler-facing service

2 participants