Skip to content

Conversation

@mostlygeek
Copy link
Owner

@mostlygeek mostlygeek commented May 14, 2025

Ref:

Summary by CodeRabbit

  • New Features
    • Improved process management with a new stop and reset behavior, allowing processes to be stopped and reset to their original state.
  • Bug Fixes
    • Enhanced error logging for process start failures to improve visibility when issues occur.
  • Refactor
    • Improved thread safety during process replacement to ensure more reliable operation when managing multiple processes.
  • Documentation
    • Added and updated comments for better clarity on process management behaviors.

Fix issues with failed processes after /unload and processes that
need to be removed with SIGKILL. When a Process is SIGKILL'd it will
wind up in a StateFailed state due to complex interactions between
various contexts and channels for managing state.

The StopAndReset strategy will call Process.StopImmediately() to
terminate the process and then replace it with NewProcess().
@coderabbitai
Copy link

coderabbitai bot commented May 14, 2025

Walkthrough

A new stop strategy, StopAndReset, was added to the process management logic, allowing processes to be stopped and then reset to a pristine state. Thread safety was improved in process replacement by introducing a mutex. The unload-all-models handler now uses the new stop-and-reset strategy when stopping processes.

Changes

File(s) Change Summary
proxy/process.go Added StopAndReset to StopStrategy enum, documented types/functions, improved error logging in start().
proxy/processgroup.go Added processMutex to ProcessGroup, implemented thread-safe process replacement for StopAndReset strategy.
proxy/proxymanager.go Changed unloadAllModelsHandler to use StopAndReset strategy instead of StopImmediately.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ProxyManager
    participant ProcessGroup
    participant Process

    Client->>ProxyManager: HTTP request to unload all models
    ProxyManager->>ProcessGroup: StopProcesses(StopAndReset)
    loop For each process
        ProcessGroup->>Process: Stop immediately
        ProcessGroup->>ProcessGroup: Replace with new Process (thread-safe)
    end
    ProxyManager-->>Client: HTTP 200 OK ("OK")
Loading

Suggested labels

enhancement

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 466a678 and 5c60fb9.

📒 Files selected for processing (1)
  • proxy/processgroup.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • proxy/processgroup.go
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
proxy/processgroup.go (1)

81-112: 🛠️ Refactor suggestion

Holding pg.Lock while goroutines run risks blocking in-flight requests

StopProcesses keeps pg.Lock() held while the spawned goroutines execute.
If an in-flight request reaches ProxyRequest (which grabs pg.Lock() when pg.swap is true) it will block, while the goroutine running process.StopImmediately() proceeds.
Although StopImmediately no longer waits for requests, the blocked request could still delay its own completion and prolong the lock.

Consider:

  1. Copying the pg.processes slice under the lock.
  2. Releasing pg.Lock() before spawning goroutines.
  3. Using the new processMutex only for the actual map write.

That reduces the critical-section window and avoids lock contention with live traffic.

🧹 Nitpick comments (2)
proxy/process.go (1)

33-41: Spelling / comment polish

Nit: “pristine” is miss-spelled as “prestine” in several added comments (StopStrategy doc string here and in processgroup.go).

- // stop the process and reset its state to pristine
+ // stop the process and reset its state to pristine
proxy/processgroup.go (1)

98-99: Typo in comment

- // stop all processes and replace with a new prestine Process
+ // stop all processes and replace with a new pristine Process
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f37bcc and 466a678.

📒 Files selected for processing (3)
  • proxy/process.go (3 hunks)
  • proxy/processgroup.go (2 hunks)
  • proxy/proxymanager.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
proxy/proxymanager.go (1)
proxy/process.go (1)
  • StopAndReset (41-41)
proxy/processgroup.go (1)
proxy/process.go (4)
  • Process (44-77)
  • StopImmediately (37-37)
  • StopAndReset (41-41)
  • NewProcess (80-107)
🔇 Additional comments (2)
proxy/proxymanager.go (1)

507-508: Change aligns handler with new stop strategy – looks good

Switching to StopAndReset ensures the “/unload” endpoint both stops and refreshes all processes, matching the new behaviour added in ProcessGroup.StopProcesses. No further concerns here.

proxy/process.go (1)

205-217: Good addition of explicit start-error logging

The extra proxyLogger.Errorf gives immediate visibility when cmd.Start() fails – nice catch.

@mostlygeek
Copy link
Owner Author

going to abandon this after a bit more thought. Better to clean up start/stop in Process as that should work as expected with SIGKILL, not worked around like this.

@mostlygeek mostlygeek closed this May 14, 2025
@mostlygeek mostlygeek deleted the improve-unload-125 branch May 15, 2025 02:56
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