Skip to content

feat(spider-client): Add user-facing client library for job orchestration and resource group management. - #363

Merged
LinZhihao-723 merged 29 commits into
y-scope:mainfrom
sitaowang1998:client
Jul 2, 2026
Merged

feat(spider-client): Add user-facing client library for job orchestration and resource group management.#363
LinZhihao-723 merged 29 commits into
y-scope:mainfrom
sitaowang1998:client

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR adds client library as a standalone component that expose the job orchestration and resource group management directly.

Note

The resource group deletion is missing, pending fix in storage.

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

    • Added a new client library for connecting to Spider services.
    • Introduced user-facing APIs to submit, start, cancel, and check job status, outputs, and errors.
    • Added resource group management actions for adding and verifying resource groups.
  • Bug Fixes

    • Improved error reporting for connection, request, authentication, validation, and response handling issues.
    • Added clearer handling for unexpected job states and data conversion failures.

@sitaowang1998
sitaowang1998 requested a review from a team as a code owner June 29, 2026 01:08
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR adds a new spider-client Rust crate providing a user-facing SpiderClient facade over two pooled tonic gRPC clients: JobOrchestrationClient and ResourceGroupManagementClient. It introduces a unified ClientError enum with gRPC status-mapping helpers, and registers the crate in the Cargo workspace.

Changes

spider-client crate

Layer / File(s) Summary
ClientError type and helper
components/spider-client/src/error.rs
Adds ClientError enum covering transport, server, job, and serialization failures, plus to_transport_error helper.
Job orchestration gRPC client
components/spider-client/src/grpc/job.rs
Implements JobOrchestrationClient with connect, submit_job (zstd-compressed serialized task graph/inputs), start_job, cancel_job, get_job_state, get_job_outputs, get_job_error, and helpers mapping tonic Status and job state responses to ClientError/JobState.
Resource-group management gRPC client
components/spider-client/src/grpc/resource_group.rs
Implements ResourceGroupManagementClient with connect, add_resource_group, verify_resource_group, and a status-mapping helper.
SpiderClient facade, crate surface, and workspace wiring
components/spider-client/src/client.rs, components/spider-client/src/lib.rs, components/spider-client/src/grpc/mod.rs, components/spider-client/Cargo.toml, Cargo.toml
Defines SpiderClient connecting both inner clients concurrently via tokio::try_join! and delegating job/resource-group methods; declares the crate's public modules and re-export; adds the crate manifest; registers the crate in the workspace members/default-members.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant SpiderClient
  participant JobOrchestrationClient
  participant ResourceGroupManagementClient
  participant gRPCServer

  Caller->>SpiderClient: connect(endpoint, pool_size)
  SpiderClient->>JobOrchestrationClient: connect(endpoint, pool_size)
  SpiderClient->>ResourceGroupManagementClient: connect(endpoint, pool_size)
  JobOrchestrationClient-->>SpiderClient: Ok/Err
  ResourceGroupManagementClient-->>SpiderClient: Ok/Err
  SpiderClient-->>Caller: Ok(SpiderClient) / Err(ClientError)

  Caller->>SpiderClient: submit_job(resource_group_id, task_graph, inputs)
  SpiderClient->>JobOrchestrationClient: submit_job(...)
  JobOrchestrationClient->>gRPCServer: register_job(RegisterJobRequest)
  gRPCServer-->>JobOrchestrationClient: RegisterJobResponse / Status
  JobOrchestrationClient-->>SpiderClient: Ok(JobId) / Err(ClientError)
  SpiderClient-->>Caller: Ok(JobId) / Err(ClientError)
Loading

Possibly related PRs

  • y-scope/spider#323: Adds the add_resource_group/verify_resource_group resource-group lifecycle APIs that this PR's SpiderClient wraps.
  • y-scope/spider#353: Refactors the job-orchestration proto/error model that drives this PR's JobOrchestrationClient status mapping.
  • y-scope/spider#360: Introduces the ConnectionPool abstraction that SpiderClient, JobOrchestrationClient, and ResourceGroupManagementClient all use.

Suggested reviewers: LinZhihao-723

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Title check ✅ Passed The title accurately summarizes the main change: a new user-facing spider-client library for job orchestration and resource group management.
✨ 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: 5

🤖 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-client/src/error.rs`:
- Around line 26-28: The precondition mapping in the client error handling is
using the job-only ClientError::InvalidJobState variant for
ResourceGroupManagementClient::add_resource_group, which leaks an unrelated
error across the public API. Add a generic/resource-group-specific precondition
error variant in error.rs and update the FAILED_PRECONDITION branch in the
shared RPC helper to return that new variant instead of InvalidJobState so
resource-group failures stay correctly scoped.

In `@components/spider-client/src/job.rs`:
- Around line 112-120: Update the error documentation for both start_job and
cancel_job in job.rs so it fully reflects the errors propagated from
job_state_response_to_result; add ClientError::UnspecifiedJobState and
ClientError::Transport for invalid response states alongside the existing listed
errors. Keep the wording consistent between the two methods and ensure the docs
mention that state conversion can fail independently of the RPC call itself.
- Around line 499-501: The negative-path test currently hardcodes
Endpoint::from_static("http://127.0.0.1:1"), which can be flaky if something is
listening on port 1. Update the test in job.rs to reserve an ephemeral local
port, close/release it before the eager connect, and then build the endpoint
from that freed port so the failure remains deterministic. Use the surrounding
test setup around Endpoint::from_static and the eager connect logic to keep the
change localized.

In `@components/spider-client/src/resource_group.rs`:
- Around line 56-62: Update the public error documentation for both
add_resource_group and verify_resource_group to mention the FAILED_PRECONDITION
mapping coming from resource_group_status_to_error, which currently resolves to
ClientError::InvalidJobState. Keep the docs aligned with the shared mapper
behavior by adding this case to the error list, or adjust the mapper if you
intend a resource-group-specific variant instead.
- Around line 232-234: The negative-path test in resource_group.rs assumes
127.0.0.1:1 is always closed, but that can be environment-dependent. Update the
test setup around Endpoint::from_static to use a closed ephemeral port instead
of hardcoding port 1, so the eager connect failure remains reliable regardless
of local services.
🪄 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: d26b36f1-4ee2-4001-b351-ca6cad66787e

📥 Commits

Reviewing files that changed from the base of the PR and between c0fe56f and add524c.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • Cargo.toml
  • components/spider-client/Cargo.toml
  • components/spider-client/src/client.rs
  • components/spider-client/src/error.rs
  • components/spider-client/src/job.rs
  • components/spider-client/src/lib.rs
  • components/spider-client/src/resource_group.rs
  • components/spider-client/src/test_utils.rs

Comment thread components/spider-client/src/error.rs
Comment thread components/spider-client/src/grpc/job.rs Outdated
Comment thread components/spider-client/src/job.rs Outdated
Comment thread components/spider-client/src/grpc/resource_group.rs Outdated
Comment thread components/spider-client/src/resource_group.rs Outdated
@sitaowang1998

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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-client/src/job.rs`:
- Around line 150-152: Update the `cancel_job` documentation to match its actual
error mapping via `job_status_to_error`, since it shares the same behavior as
`start_job`. Add `ClientError::Unauthenticated` to the public error list in the
`cancel_job` doc comment alongside the existing
`ClientError::UnspecifiedJobState` and `ClientError::Transport` entries so the
contract is accurate.
🪄 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: 0976d7a5-df85-470f-8a9a-4255c06a2d46

📥 Commits

Reviewing files that changed from the base of the PR and between add524c and ec89ff5.

📒 Files selected for processing (3)
  • components/spider-client/src/error.rs
  • components/spider-client/src/job.rs
  • components/spider-client/src/resource_group.rs
💤 Files with no reviewable changes (1)
  • components/spider-client/src/resource_group.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/spider-client/src/error.rs

Comment thread components/spider-client/src/grpc/job.rs Outdated
Comment on lines +76 to +79
///
/// A freshly registered job has no id yet, so the server-reported `NOT_FOUND` and
/// `FAILED_PRECONDITION` codes (which a job id would otherwise attach) cannot arise for
/// registration and are folded into [`ClientError::Server`].

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.

Is this over-explanation generated by the coding agent? It doesn't match our doc standard (neither it's format nor it's wording)

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.

  • Might be worth to group job.rs and resource_group.rs into a grpc mod.
  • All these types should probably be public only within the crate.

Comment on lines +17 to +21
///
/// Holds a round-robin pool of connections and exposes the resource-group operations (add, verify).
/// Build one with [`ResourceGroupManagementClient::connect`]. [`crate::client::SpiderClient`] wraps
/// one of these alongside a [`crate::job::JobOrchestrationClient`] for callers who need both
/// services behind a single handle.

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 is also over-explaining: we don't have any of this in the other client implementation.
If you see the agent is generating a wall of text, you should verify whether it's worth.

Comment thread components/spider-client/src/client.rs Outdated
Comment on lines +22 to +26
///
/// Wraps a [`JobOrchestrationClient`] and a [`ResourceGroupManagementClient`] against the same
/// storage endpoint, so callers who need both job-lifecycle and resource-group operations get a
/// single handle and one [`SpiderClient::connect`] call. Callers who need only one service may
/// construct the inner client directly.

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 is the actual user-facing type. I don't think user needs to know about the underlying client types, right?

Comment thread components/spider-client/src/client.rs Outdated
///
/// # Errors
///
/// Returns [`ClientError::Transport`] if tonic cannot establish a connection to `endpoint`.

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.

Read this again and tell me if this matches the docstring format, lol
fyi this is also sth already in our codebase and the coding agent just missed it:

Comment thread components/spider-client/src/client.rs Outdated
///
/// # Errors
///
/// See [`JobOrchestrationClient::submit_job`].

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.

  • Shall we use Forward xxx?? I believe this format was invented by the coding agent.
  • And in fact, I'm not sure if this is the best way to document the user-facing client.

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.

I will probably rewrite the docstring in this mod myself since it's user-facing.
But you should really review the docstrings carefully. I don't want to waste more time on catching these types of errors.

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

I've done my editing but please make sure you read what I've changed.

@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-client/src/grpc/job.rs (1)

291-300: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider unit tests for the status-mapping function.

job_status_to_error is a pure function, and this exact code shape has already had a real mismapping bug in the sibling resource_group_status_to_error (FAILED_PRECONDITION incorrectly mapped to a job-only variant, caught in a prior review round). A small table-driven test asserting each Code maps to the expected ClientError variant would cheaply guard against regressions here and in resource_group.rs.

🤖 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-client/src/grpc/job.rs` around lines 291 - 300, Add unit
tests for the pure status-mapping helper job_status_to_error to prevent
regressions in gRPC code-to-ClientError conversion. Create a small table-driven
test that exercises each relevant Code branch and asserts the expected
ClientError variant, including FailedPrecondition, InvalidArgument,
Unauthenticated, Unavailable, NotFound, and the default fallback. Use
job_status_to_error as the primary target, and mirror the same approach for
resource_group_status_to_error to catch the sibling mapping bug pattern noted in
review.
🤖 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-client/src/grpc/job.rs`:
- Around line 41-43: The doc comment on the `connect` method still references
the wrong error type in its “Returns an error if” section. Update the intra-doc
link from `StorageResponseError::Transport` to `ClientError::Transport`,
matching the other `connect` docs like `SpiderClient::connect` and
`ResourceGroupManagementClient::connect`, so rustdoc can resolve the link
correctly.

---

Nitpick comments:
In `@components/spider-client/src/grpc/job.rs`:
- Around line 291-300: Add unit tests for the pure status-mapping helper
job_status_to_error to prevent regressions in gRPC code-to-ClientError
conversion. Create a small table-driven test that exercises each relevant Code
branch and asserts the expected ClientError variant, including
FailedPrecondition, InvalidArgument, Unauthenticated, Unavailable, NotFound, and
the default fallback. Use job_status_to_error as the primary target, and mirror
the same approach for resource_group_status_to_error to catch the sibling
mapping bug pattern noted in review.
🪄 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: a1f036b5-3ad0-4388-86d9-06e181b7c6dc

📥 Commits

Reviewing files that changed from the base of the PR and between a342b49 and e3cc8d8.

📒 Files selected for processing (6)
  • components/spider-client/src/client.rs
  • components/spider-client/src/error.rs
  • components/spider-client/src/grpc/job.rs
  • components/spider-client/src/grpc/mod.rs
  • components/spider-client/src/grpc/resource_group.rs
  • components/spider-client/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/spider-client/src/client.rs

Comment thread components/spider-client/src/grpc/job.rs Outdated
@LinZhihao-723 LinZhihao-723 changed the title feat(spider-client): Add client library. feat(spider-client): Add user-facing client library for job orchestration and resource group management. Jul 2, 2026
LinZhihao-723
LinZhihao-723 previously approved these changes Jul 2, 2026

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

Directly modified the PR title.

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