Skip to content

feat: implement worker supervisor for process management - #407

Merged
niteshpurohit merged 18 commits into
mainfrom
feat/worker-concurrency
Apr 2, 2026
Merged

niteshpurohit merged 18 commits into
mainfrom
feat/worker-concurrency

Conversation

@niteshpurohit

Copy link
Copy Markdown
Member
  • Introduced Karya::WorkerSupervisor to manage child worker processes.
  • Added configuration options for concurrency, lease duration, and signal handling.
  • Implemented graceful shutdown behavior for child workers on receiving termination signals.
  • Updated CLI to start the worker supervisor instead of individual workers.
  • Enhanced tests to cover new supervisor functionality and validate configurations.
  • Updated documentation to reflect the new supervisor model and its behavior during shutdown.

closes: #15

@niteshpurohit niteshpurohit self-assigned this Mar 30, 2026
Copilot AI review requested due to automatic review settings March 30, 2026 03:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a supervisor-based, multi-process worker runtime (Sidekiq-style) with CLI-configured concurrency, coordinated signal handling, and updated docs/tests to match the new model.

Changes:

  • Added Karya::WorkerSupervisor to fork/manage child worker processes and coordinate shutdown/drain/force-stop.
  • Updated karya worker CLI to start the supervisor (with --concurrency) and to own signal trapping/restoration.
  • Extended worker behavior and test coverage for shutdown/drain semantics and supervisor lifecycle.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/pages/runtime/workers.md Documents the new supervisor-owned process model and shutdown behavior.
core/karya/spec/karya/worker_supervisor_spec.rb Adds coverage for supervisor child management, drain/force-stop, and runtime hooks.
core/karya/spec/karya/worker_spec.rb Adds shutdown/drain behavior tests and validates signal_subscriber.
core/karya/spec/karya/cli_spec.rb Updates CLI expectations to construct/run WorkerSupervisor, adds concurrency and signal subscription tests.
core/karya/lib/karya/worker_supervisor.rb Implements the supervisor, runtime hooks, and configuration validation.
core/karya/lib/karya/worker.rb Adds signal-driven drain/force-stop behavior and reservation-release-on-shutdown semantics.
core/karya/lib/karya/cli.rb Wires CLI options to supervisor + adds signal subscription helper and header suppression.
core/karya/lib/karya.rb Requires the new supervisor implementation.
core/karya/README.md Updates documentation to describe supervisor-based concurrency and shutdown behavior.

Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated
Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated
Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated
@niteshpurohit
niteshpurohit requested a review from Copilot March 30, 2026 04:57
Comment thread core/karya/lib/karya/worker.rb Fixed
Comment thread core/karya/lib/karya/worker_supervisor.rb Fixed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated
Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated
Comment thread core/karya/lib/karya/cli.rb Outdated
Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread core/karya/spec/karya/worker_supervisor_spec.rb Outdated
Copilot AI review requested due to automatic review settings March 31, 2026 01:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated
Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread docs/pages/runtime/workers.md Outdated
Comment thread core/karya/README.md Outdated
Comment thread core/karya/lib/karya/worker.rb

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated
Comment thread core/karya/lib/karya/worker.rb Outdated
Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread core/karya/lib/karya/worker.rb
Comment thread core/karya/lib/karya/cli.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

core/karya/lib/karya/cli.rb:40

  • CLI#version currently relies on the header being printed (it immediately exit(0) without output), but CLI.start can now suppress the header via suppress_header. With suppress_header: true, karya version/--version will produce no output despite the command description saying it prints the version. Consider printing the version explicitly in version, or only suppressing the ASCII header while still emitting a minimal version line when this command is invoked.
    def self.start(given_args = ARGV, config = {})
      puts header unless config[:suppress_header]
      super
    end

    def self.header
      art = <<~'TEXT'
         _  __     _     ____   __   __    _
        | |/ /    / \   |  _ \  \ \ / /   / \
        | ' /    / _ \  | |_) |  \ V /   / _ \
        | . \   / ___ \ |  _ <    | |   / ___ \
        |_|\_\ /_/   \_\|_| \_\   |_|  /_/   \_\
      TEXT

      "#{art}\n#{Karya::TAGLINE} · v#{Karya::VERSION}\n"
    end

    map %w[--help -h] => :help
    map %w[--version -v] => :version

    desc 'version', 'Print the current version'
    def version
      # version is printed in the header, so we can just exit here
      exit(0)
    end

Comment thread core/karya/lib/karya/worker.rb

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 188 out of 190 changed files in this pull request and generated 2 comments.

Comment thread core/karya/lib/karya/job_lifecycle/state_manager.rb
Comment thread core/karya/lib/karya/job_lifecycle/state_manager.rb Outdated
- Changed direct method calls to use `send` for state manager methods to enhance encapsulation.
- Added a new StateQueries module for internal state query and value helpers.
- Updated state manager specs to reflect changes in method access.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 190 out of 192 changed files in this pull request and generated 3 comments.

Comment thread core/karya/lib/karya/worker_supervisor.rb
Comment thread core/karya/lib/karya/worker.rb
Comment thread core/karya/lib/karya/worker_supervisor/runtime.rb Outdated
- Changed error messages to use "unknown keyword options" for clarity.
- Updated method signatures to accept keyword arguments using double splat (**).
- Enhanced tests to reflect the updated error messages and keyword argument handling.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 190 out of 192 changed files in this pull request and generated 8 comments.

Comment thread core/karya/lib/karya/worker_supervisor/runtime.rb
Comment thread core/karya/lib/karya/worker/runtime.rb
Comment thread core/karya/lib/karya/worker_supervisor/child_process_runner.rb
Comment thread core/karya/sig/karya/job_lifecycle.rbs
Comment thread core/karya/sig/karya/worker_supervisor/pid.rbs Outdated
Comment thread core/karya/sig/karya/primitives/callable.rbs
Comment thread core/karya/sig/karya/primitives/positive_integer.rbs
Comment thread core/karya/sig/karya/primitives/optional_callable.rbs
- Updated signal subscriber handling in runtime and child process runner to ensure that false values are rejected.
- Enhanced error messages for clarity when invalid signal subscribers are provided.
- Added tests to validate behavior for false signal subscriber restorers.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 190 out of 192 changed files in this pull request and generated 2 comments.

Comment thread core/karya/lib/karya/worker/runtime.rb Outdated
Comment thread core/karya/lib/karya/worker_supervisor/runtime.rb Outdated
- Introduced UNSET constant to manage default values for options.
- Updated Worker and WorkerSupervisor classes to use UNSET for instrumenter, logger, and sleeper options.
- Added validation methods for logger and ensured they respond to required methods.
- Enhanced tests to reject false values for instrumenter, logger, and forker in both Worker and WorkerSupervisor runtimes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 190 out of 192 changed files in this pull request and generated 1 comment.

Comment thread core/karya/spec/spec_helper.rb
- Updated the minimum coverage configuration for SimpleCov
  to explicitly define line and branch coverage as zero
  for forked processes.
- This change enhances clarity and ensures consistent
  coverage reporting across different process executions.
Copilot AI review requested due to automatic review settings April 2, 2026 04:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 189 out of 191 changed files in this pull request and generated 1 comment.

Comment thread core/karya/lib/karya/worker_supervisor.rb Outdated
- Added a test to ensure blocking helper reaping continues
  after encountering unknown waited child PIDs.
- Validates that the child PIDs are emptied correctly
  and that the process alive check is performed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 189 out of 191 changed files in this pull request and generated no new comments.

@niteshpurohit
niteshpurohit merged commit 8e19fbd into main Apr 2, 2026
26 checks passed
@niteshpurohit
niteshpurohit deleted the feat/worker-concurrency branch April 2, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement hybrid worker processes and thread pools

3 participants