Skip to content

feat(spider-storage): Add storage service runtime; Replace ExecutionManagerLivenessStore with ExecutionManagerLivenessManagement DB protocol in TaskInstancePool. - #324

Merged
sitaowang1998 merged 12 commits into
y-scope:storage-service-devfrom
sitaowang1998:graceful-shutdown
Jun 8, 2026

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR:

  • Adds a new ServerRuntime type that keeps a CancellationToken and JoinHandle to gracefully shutdown the service.
  • Merges ExecutionManagerLivenessStore in task instance pool into ExecutionManagerLivenessManagement in db.
  • Adds graceful shutdown in task instance pool that drains all messages.
  • Refactors task instance pool handle creation into a factory method.

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

  • New tests added for the graceful shutdown and task instance pool factory method.
  • GitHub workflows pass.

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated Tokio dependencies to latest compatible versions for improved stability
  • Refactor

    • Restructured task instance pool API with new configuration options
    • Introduced server runtime abstraction for better background task coordination
    • Enhanced error handling for database operations in cache layer

Review Change Stack

@sitaowang1998
sitaowang1998 requested a review from a team as a code owner May 14, 2026 19:58
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1a22ebd1-628b-48d7-bfe7-9098ebb69c31

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
🚥 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 describes the two main changes: adding ServerRuntime for storage service and replacing ExecutionManagerLivenessStore with ExecutionManagerLivenessManagement in TaskInstancePool.

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

🤖 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-storage/src/state/server.rs`:
- Around line 102-109: The timeout currently moves
self.task_instance_pool_join_handle into tokio::time::timeout so if the timeout
fires the handle is dropped and the background task keeps running; change the
logic to detect timeout without consuming the handle (e.g., use tokio::select!
between the join handle future and tokio::time::sleep) so you can call abort()
on the JoinHandle (self.task_instance_pool_join_handle.abort()) when the timeout
branch wins, then return the StorageServerError::Stopping error; reference the
existing stop_timeout_sec and task_instance_pool_join_handle symbols and ensure
you await or ignore the aborted handle appropriately after aborting.

In `@components/spider-storage/src/task_instance_pool.rs`:
- Around line 169-170: Clamp the public config fields channel_size and
gc_interval to at least 1 before creating Tokio primitives to avoid panics: when
calling mpsc::channel(...) use config.channel_size.max(1) and when creating the
interval with tokio::time::interval(...) use config.gc_interval.max(1) (or
assign clamped values to locals first). Update the TaskInstancePool
construction/initialization sites (references: TaskInstancePoolConfig,
mpsc::channel, tokio::time::interval, variables sender/receiver and the GC
interval setup) to pass the clamped values so zero cannot be forwarded into
Tokio APIs.
🪄 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: 71fa0b19-7bcb-4d56-96c9-4681b1e1b273

📥 Commits

Reviewing files that changed from the base of the PR and between dfb2170 and 5b8eccf.

📒 Files selected for processing (5)
  • components/spider-storage/Cargo.toml
  • components/spider-storage/src/cache/error.rs
  • components/spider-storage/src/state.rs
  • components/spider-storage/src/state/server.rs
  • components/spider-storage/src/task_instance_pool.rs

Comment thread components/spider-storage/src/state/server.rs Outdated
Comment thread components/spider-storage/src/task_instance_pool.rs Outdated

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.

Reviewed and made the following changes:

  1. server.rs -> runtime.rs. This is a runtime, not an actual server.
  2. stop_timeout stored as a Duration instance.
  3. stop_background_tasks_cancels_and_joins_task -> stop for simplicity.
  4. Change create_server_runtime to accept all configs needed, and make sure it returns the cancellation token as well so that the main loop can monitor its changes.

task_instance_pool_config,
);

// TODO: Recover jobs from the database.

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 might be a high-priority task: we need to complete this stage to make the storage fully serviceable.

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.

Reviewed and polished with the following changes:

  • Fix symbol ordering.
  • Field renames:
    • execution_manager_stale_after_secexecution_manager_stale_cutoff_sec
    • gc_intervalgc_interval_sec
    • channel_sizemessage_channel_capacity
  • Validation moved out of new, and enforced inside create_task_instance_pool.
  • Deleted drain_received_messages: there's no need to drain the message queue. If there are any blocked service tasks, they will be aborted anyway by tokio runtime. We only need to make sure there can't be new requests being served.

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.

Should we have a dedicated type for validated config?

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 think the current pattern should be fine: in the final deliverable, task instance pool creation must go through creat_task_instance_pool, which enforces the config validation. We probably need a dedicated type if it's been used in multiple places.

@LinZhihao-723 LinZhihao-723 changed the title feat(spider-storage): Add ServerRuntime to gracefully shutdown storage service. feat(spider-storage): Add storage service runtime; Replace ExecutionManagerLivenessStore with ExecutionManagerLivenessManagement DB protocol in TaskInstancePool. Jun 7, 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.

@sitaowang1998
sitaowang1998 merged commit 2cbdff6 into y-scope:storage-service-dev Jun 8, 2026
11 checks passed
@sitaowang1998
sitaowang1998 deleted the graceful-shutdown branch June 8, 2026 00:22
LinZhihao-723 added a commit that referenced this pull request Jun 15, 2026
…343)

Related PRs: #319, #321, #322, #323, #324, #338, #339, #341.
Co-authored-by: sitaowang1998 <sitaowang1998@outlook.com>
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