Skip to content

Improve worker management admin route #2032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2025

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented May 9, 2025

It's now more easily possible to do the following:

  • create worker groups
  • set worker groups as default for projects
  • remove default for projects, so they use the global default again

Existing worker groups are handled gracefully, but no tokens will be returned for those as we only store hashes.

Summary by CodeRabbit

  • New Features

    • Enhanced worker group management, allowing users to set or remove default worker groups for specific projects through the API.
    • Users can now create worker groups, assign them as project defaults, or revert projects to the global default worker group.
  • Documentation

    • Updated and reorganized the supervisor app documentation for clearer instructions on managing worker groups, including detailed API usage examples and explanations of expected behaviors.

Copy link

changeset-bot bot commented May 9, 2025

⚠️ No Changeset found

Latest commit: d2f8636

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented May 9, 2025

Walkthrough

The changes update documentation for worker group management in the supervisor app and significantly extend the API endpoint logic for managing worker groups. The API now supports explicit creation, assignment, and removal of default worker groups for projects, with more granular request parameters, improved error handling, and clearer control flow.

Changes

File(s) Change Summary
apps/supervisor/README.md Expanded and reorganized documentation for worker group management, clarifying token return behavior, splitting sections into subsections, standardizing curl command examples, and explaining effects of each operation on tokens and default assignments.
apps/webapp/app/routes/admin.api.v1.workers.ts Extended API endpoint logic to support new request body schema with projectId, makeDefaultForProject, and removeDefaultFromProject flags. Added helper functions for creating worker groups, setting/removing default worker groups for projects. Updated error handling, response structures, and control flow for these operations. Exported new helper functions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant DB

    Client->>API: POST /admin.api.v1.workers (create group)
    API->>DB: Check if worker group exists
    alt Group does not exist
        API->>DB: Create new worker group
        alt makeDefaultForProject is true
            API->>DB: Set new group as default for project
            API-->>Client: Success (group, no token)
        else makeDefaultForProject is false
            API-->>Client: Success (group, token)
        end
    else Group exists
        alt makeDefaultForProject is true
            API->>DB: Set existing group as default for project
            API-->>Client: Success (group, no token)
        else
            API-->>Client: Error (group already exists)
        end
    end

    Client->>API: POST /admin.api.v1.workers (removeDefaultFromProject)
    API->>DB: Remove default worker group from project
    API-->>Client: Success or Error
Loading

Poem

In the warren of code, with a hop and a leap,
Worker groups gather—no secrets to keep.
Now tokens are clear, and defaults set right,
With flags and with helpers, all flows are in sight.
The docs are much brighter, the API’s neat—
A carrot for teamwork, a change hard to beat!
🥕

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.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
Contributor

@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: 5

🧹 Nitpick comments (5)
apps/supervisor/README.md (1)

48-106: Consider collapsing the duplicate cURL snippets & emphasise required flags

Great to see explicit examples, but the three nearly-identical cURL blocks differ only in JSON payload. Collapsing them into a single block with inline comments (# create, # set default, # remove default) reduces duplication and makes future edits less error-prone.

apps/webapp/app/routes/admin.api.v1.workers.ts (4)

41-43: rawBody ?? {} is redundant

request.json() already returns an object; ?? {} is never triggered.
Very minor, but removing it keeps parsing intent clearer.


108-116: Error message could leak existence of worker group

Returning workerGroup details in the 400 response (worker group already exists) may inadvertently expose internal IDs to callers.
Consider omitting the full object or guarding behind an additional admin-only flag.


143-149: Top-level catch swallows non-JSON parsing errors

A malformed Content-Type (text/plain) throws before rawBody assignment and lands here, returning 400 “unknown error”.
Explicitly validate request.headers.get("content-type")?.includes("application/json") first, returning 415 Unsupported Media Type.


196-244: Use a single DB transaction for default-update path

setWorkerGroupAsDefaultForProject() reads, then updates in two separate queries.
Wrap both in a single prisma.$transaction to prevent a race where the project is deleted between calls.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37aadfc and d2f8636.

📒 Files selected for processing (2)
  • apps/supervisor/README.md (2 hunks)
  • apps/webapp/app/routes/admin.api.v1.workers.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
apps/supervisor/README.md (1)

22-23: Mismatch between documentation and implementation regarding token emission

The README specifies that no token will be returned when an existing worker group is attached as a project-default, yet the updated endpoint (apps/webapp/app/routes/admin.api.v1.workers.ts, lines 100-105) still includes token in the JSON response when makeDefaultForProject is true and the group is newly created.
Please either

  1. update the endpoint to omit token in that control-flow branch, or
  2. amend the README to reflect the current behaviour.

Keeping docs and code in sync avoids confusion for operators automating their deployments.

@nicktrn nicktrn merged commit 1b1ad16 into main May 9, 2025
12 checks passed
@nicktrn nicktrn deleted the feat/project-default-worker-group branch May 9, 2025 09:43
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.

3 participants