Skip to content

feat(huntsman): Replace gRPC protocol custom error code with gRPC status. - #359

Merged
LinZhihao-723 merged 11 commits into
y-scope:mainfrom
sitaowang1998:storage-grpc-migration
Jun 28, 2026
Merged

feat(huntsman): Replace gRPC protocol custom error code with gRPC status.#359
LinZhihao-723 merged 11 commits into
y-scope:mainfrom
sitaowang1998:storage-grpc-migration

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR:

  • Removes custom error code in gRPC protocol.
  • Adds gRPC status to error conversion.

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

  • New Features
    • None.
  • Bug Fixes
    • Improved gRPC error handling by mapping status codes to clearer client-friendly errors for liveness, registration/heartbeat, and scheduler inbound-queue polling.
    • Updated execution manager and scheduler response parsing to handle the new protobuf shapes and properly detect missing expected data.
  • Breaking Changes
    • Updated storage/proto RPC contracts for task completion, resource-group verification, and related scheduler/reporting calls to use success-only responses and simplified response structures.
  • Tests
    • Refreshed unit tests to match the new protobuf shapes and validate the updated status/response mappings.

# 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 June 26, 2026 22:16
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Storage protobuf contracts now use direct success fields, while the scheduler and execution-manager gRPC clients map tonic status codes into domain errors and decode the updated response shapes.

Changes

Storage gRPC contract updates

Layer / File(s) Summary
Task and resource-group contracts
components/spider-proto/storage/storage.proto, components/spider-storage/src/grpc.rs
Task-reporting and resource-group RPCs now return common.Void; resource-group requests drop session_id; and the related response wrappers and message types are removed.
Scheduler polling flow
components/spider-proto/storage/storage.proto, components/spider-scheduler/src/storage_client/grpc.rs
PollReadyTasksResponse now uses tasks directly, inbound polling maps tonic status codes into StorageClientError, and the tests cover the new response shape and status mapping.
Liveness and scheduler registration contracts
components/spider-proto/storage/storage.proto, components/spider-execution-manager/src/client/grpc/liveness.rs
Execution-manager and scheduler registration responses now expose direct payload fields, liveness errors come from tonic status codes, and the response conversion tests match the new shapes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • y-scope/spider#340: Updates the same execution-manager gRPC liveness client paths and error mapping that this PR changes for the new response shapes.
  • y-scope/spider#346: Changes the task-reporting gRPC surface that this PR also updates in storage.proto and spider-storage.
  • y-scope/spider#360: Modifies the same GrpcLivenessClient methods and overlaps with this PR’s register/heartbeat conversion changes.

Suggested reviewers

  • LinZhihao-723
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: replacing custom gRPC protocol errors with gRPC status handling.
✨ 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.

Actionable comments posted: 1

🤖 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-execution-manager/src/client/grpc/liveness.rs`:
- Around line 112-114: The registration response handling in liveness::register
currently accepts registration.execution_manager_id without validating it, so a
zero ID can slip through as a valid ExecutionManagerId. Add the same non-zero
guard used for session_id before constructing the RegistrationResponse in the
registration response path, and reject or return an error when
registration.execution_manager_id is 0 so only a valid ExecutionManagerId::from
value becomes active.
🪄 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: b8758783-8c76-42ba-8b45-389e8e841482

📥 Commits

Reviewing files that changed from the base of the PR and between 7af2859 and 429fdbb.

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

Comment on lines 112 to 114
Ok(RegistrationResponse {
em_id: ExecutionManagerId::from(registration.execution_manager_id),
session_id: registration.session_id,

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm whether ExecutionManagerId permits zero and whether other decoders reject zero IDs.
fd -e rs . components/spider-core components/spider-execution-manager components/spider-proto-rust \
  | xargs rg -n -C3 '\b(type|struct)\s+ExecutionManagerId\b|ExecutionManagerId::from\(|execution_manager_id == 0|NonZero'

Repository: y-scope/spider

Length of output: 2752


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the ID type and nearby conversions/validations.
sed -n '1,220p' components/spider-core/src/types/id.rs

printf '\n---\n'

sed -n '1,220p' components/spider-proto-rust/src/unpack/storage.rs

printf '\n---\n'

sed -n '1,230p' components/spider-execution-manager/src/client/grpc/liveness.rs

Repository: y-scope/spider

Length of output: 17533


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find where execution-manager IDs are allocated/returned on the server side.
rg -n -C3 'execution_manager_id|ExecutionManagerId::from\(|RegisterExecutionManagerResponse|ExecutionManagerRegistration|update_execution_manager_heartbeat|register_execution_manager' \
  components/spider-* --glob '!**/target/**'

Repository: y-scope/spider

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect how execution-manager IDs are allocated and returned in the storage service.
sed -n '470,530p' components/spider-storage/src/db/mariadb.rs

printf '\n---\n'

sed -n '616,660p' components/spider-storage/src/state/service.rs

printf '\n---\n'

sed -n '1,120p' components/spider-storage/src/grpc.rs

Repository: y-scope/spider

Length of output: 8046


Reject zero execution-manager IDs in registration responses. The response already treats session_id == 0 as invalid, and ExecutionManagerId is a plain u64 wrapper with no built-in non-zero guarantee. Add the same guard for registration.execution_manager_id so a malformed response cannot become the active ID.

🤖 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/liveness.rs` around lines
112 - 114, The registration response handling in liveness::register currently
accepts registration.execution_manager_id without validating it, so a zero ID
can slip through as a valid ExecutionManagerId. Add the same non-zero guard used
for session_id before constructing the RegistrationResponse in the registration
response path, and reject or return an error when
registration.execution_manager_id is 0 so only a valid ExecutionManagerId::from
value becomes active.

Comment thread components/spider-scheduler/src/storage_client/grpc.rs Outdated
Comment thread components/spider-execution-manager/src/client/grpc/liveness.rs Outdated
Comment on lines 18 to +30
@@ -27,7 +27,7 @@ service InboundQueueService {

service ResourceGroupManagementService {
rpc AddResourceGroup(AddResourceGroupRequest) returns (ResourceGroupIdResponse);
rpc VerifyResourceGroup(VerifyResourceGroupRequest) returns (ResourceGroupOperationResponse);
rpc VerifyResourceGroup(VerifyResourceGroupRequest) returns (common.Void);

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.

Since we're using common.Void in scheduler protobuf definitions for void returns already, we should be consistent and avoid defining more void types.

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

Please confirm you have read the following comments.

/// The [`StorageClientError`] for `status`'s code:
///
/// * [`StorageClientError::Transport`] for `UNAVAILABLE` (a network-level failure).
/// * [`StorageClientError::Transport`] for `UNAVAILABLE` (a lost or unestablished connection).

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.

If similar wording already exists in the code base, we'd prefer to be consistent:

/// * [`StorageResponseError::Transport`] for `UNAVAILABLE` (a lost or unestablished connection).

Ask your coding agent to follow this rule.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have added the instruction. However, I am only sure it will trigger and look for existing convention when I pose a direct question. When running a long task, it seem to skip checking on convention. Maybe I can add to review instruction as well.

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.

  • Yes, adding to the review instruction would be good.
  • You should also have a sense for checking existing ones manually.

/// * [`StorageClientError::InvalidInput`] for `INVALID_ARGUMENT`.
/// * [`StorageClientError::Server`] for any other code (including `INTERNAL`, which the storage
/// server sends when the inbound queue is closed).
/// * [`StorageClientError::Server`] for any other code.

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.

This really sounds like the conventional comments claude would add if you explicitly ask for a behavior change, but do you think this from-no-where explanation makes sense in general?
You are expected to check and remove these comments.

Comment on lines -42 to -43
/// * [`StorageClientError::Server`] if the regular-task lane is closed and can no longer yield
/// entries, or the storage server returns another error.

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.

Similar to 79bcb04#r3488578792 but even worse: what is "another error" referring to?
If you want to be general, then just be general. The same file has an example of how to describe a general case:

/// * [`StorageClientError::Server`] if the storage server returns an error.
.

@LinZhihao-723 LinZhihao-723 changed the title feat(spider-huntsman): Replace gRPC protocol custom error code with gRPC status. feat(huntsman): Replace gRPC protocol custom error code with gRPC status. Jun 28, 2026
@LinZhihao-723
LinZhihao-723 merged commit dd9f295 into y-scope:main Jun 28, 2026
14 checks passed
@sitaowang1998
sitaowang1998 deleted the storage-grpc-migration branch June 28, 2026 22:33
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