Skip to content

feat(webapp): extend admin workers endpoint and unify admin api auth#3390

Open
nicktrn wants to merge 2 commits intomainfrom
feat/admin-workers-endpoint
Open

feat(webapp): extend admin workers endpoint and unify admin api auth#3390
nicktrn wants to merge 2 commits intomainfrom
feat/admin-workers-endpoint

Conversation

@nicktrn
Copy link
Copy Markdown
Collaborator

@nicktrn nicktrn commented Apr 15, 2026

Extends the admin worker groups endpoint with a GET loader and more fields on POST (type, hidden, workloadType, cloudProvider, location, staticIPs, enableFastPath), and pulls the PAT + admin check that was inlined or locally duplicated across every admin.api route into a shared helper in personalAccessToken.server.ts. The generic authenticateAdminRequest returns a discriminated result; requireAdminApiRequest is the thin Remix loader/action wrapper that throws. The neverthrow-style route (platform-notifications.ts) now composes the generic helper instead of duplicating the check. Verified locally against GET (listing) and POST (new fields, invalid enum, minimal backwards-compat).

nicktrn added 2 commits April 15, 2026 18:09
Adds a GET loader to the admin worker groups endpoint, exposes type, hidden, workloadType, cloudProvider, location, staticIPs, and enableFastPath on creation, and introduces authenticateAdminRequest and requireAdminApiRequest helpers in personalAccessToken.server.ts. The generic authenticateAdminRequest returns a discriminated result so callers can shape failures to fit their context; requireAdminApiRequest is the Remix loader/action wrapper that throws a Response.
Replaces duplicated inline PAT + admin checks across 24 admin api routes with the shared requireAdminApiRequest helper. Refactors platform-notifications.ts to compose the generic authenticateAdminRequest with neverthrow instead of duplicating the PAT + admin check.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 15, 2026

⚠️ No Changeset found

Latest commit: d8d9835

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

Walkthrough

This pull request introduces a centralized authentication and authorization pattern for admin API endpoints. A new set of helper functions—authenticateAdminRequest and requireAdminApiRequest—are added to the personal access token service to consolidate the logic for validating API requests and enforcing admin-only access. These helpers replace inline authentication checks across 17+ admin API routes, eliminating duplicate code that previously validated tokens, looked up users, and returned specific 401/403 responses. Additionally, the workers API endpoint is enhanced with a new loader export to list worker groups and expanded action support for additional worker group configuration fields. The underlying WorkerGroupService.createWorkerGroup method is updated to accept and persist these new optional parameters.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~45 minutes

Additional notes

The changes follow a consistent and repetitive pattern across most routes (replacement of inline auth logic with a centralized helper call), which reduces review complexity for those files. However, the distributed scope across 20+ files, combined with the need to validate the new service functions and verify the expanded workers endpoint implementation, presents a moderate overall review burden. Pay particular attention to: (1) the new requireAdminApiRequest and authenticateAdminRequest helper implementations in personalAccessToken.server.ts to ensure they correctly replicate the previous behavior, (2) the workers endpoint to confirm all new fields are correctly parsed and forwarded, and (3) a sampling of the refactored routes to verify the auth pattern was applied uniformly and without unintended side effects.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is detailed and covers the key changes, but lacks compliance with the required template structure (missing checklist, testing details, and changelog sections). Add the required checklist items, describe testing steps in the Testing section, and provide a short changelog description in the Changelog section per the repository template.
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the two main changes: extending the admin workers endpoint and unifying admin API authentication across routes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/admin-workers-endpoint

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.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment thread apps/webapp/app/routes/admin.api.v1.workers.ts
Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
apps/webapp/app/routes/admin.api.v1.platform-notifications.ts (1)

9-10: Simplify authenticateAdmin return type to Result<void, AuthError>.

The success payload (id/admin) is unused in action, so returning ok(undefined) would reduce coupling and keep intent tighter.

♻️ Optional refactor
-type AdminUser = { id: string; admin: boolean };
 type AuthError = { status: number; message: string };

-async function authenticateAdmin(request: Request): Promise<Result<AdminUser, AuthError>> {
+async function authenticateAdmin(request: Request): Promise<Result<void, AuthError>> {
   const result = await authenticateAdminRequest(request);
-  return result.ok
-    ? ok({ id: result.user.id, admin: result.user.admin })
-    : err({ status: result.status, message: result.message });
+  return result.ok ? ok(undefined) : err({ status: result.status, message: result.message });
 }

Also applies to: 12-16

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/webapp/app/routes/admin.api.v1.platform-notifications.ts` around lines 9
- 10, Change the authenticateAdmin function to return Result<void, AuthError>
instead of Result<AdminUser, AuthError> and update its successful return to
ok(undefined); update the AdminUser/related return points (authenticateAdmin and
any callers like action) to stop relying on a returned { id, admin } payload and
instead use only the void success. Ensure the AuthError type remains unchanged
and adjust any code that destructures authenticateAdmin's result (e.g., places
that read result.value.id or result.value.admin) to use the existing
request/context or other sources for id/admin checks rather than the function
return.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/webapp/app/routes/admin.api.v1.platform-notifications.ts`:
- Around line 9-10: Change the authenticateAdmin function to return Result<void,
AuthError> instead of Result<AdminUser, AuthError> and update its successful
return to ok(undefined); update the AdminUser/related return points
(authenticateAdmin and any callers like action) to stop relying on a returned {
id, admin } payload and instead use only the void success. Ensure the AuthError
type remains unchanged and adjust any code that destructures authenticateAdmin's
result (e.g., places that read result.value.id or result.value.admin) to use the
existing request/context or other sources for id/admin checks rather than the
function return.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 95bb0786-e0f7-4eb4-9a5c-482823e98b9d

📥 Commits

Reviewing files that changed from the base of the PR and between 7c95207 and d8d9835.

📒 Files selected for processing (29)
  • .server-changes/admin-workers-endpoint.md
  • apps/webapp/app/routes/admin.api.v1.environments.$environmentId.engine.repair-queues.ts
  • apps/webapp/app/routes/admin.api.v1.environments.$environmentId.engine.report.ts
  • apps/webapp/app/routes/admin.api.v1.environments.$environmentId.schedules.recover.ts
  • apps/webapp/app/routes/admin.api.v1.environments.$environmentId.ts
  • apps/webapp/app/routes/admin.api.v1.feature-flags.ts
  • apps/webapp/app/routes/admin.api.v1.gc.ts
  • apps/webapp/app/routes/admin.api.v1.llm-models.$modelId.ts
  • apps/webapp/app/routes/admin.api.v1.llm-models.missing.ts
  • apps/webapp/app/routes/admin.api.v1.llm-models.reload.ts
  • apps/webapp/app/routes/admin.api.v1.llm-models.seed.ts
  • apps/webapp/app/routes/admin.api.v1.llm-models.ts
  • apps/webapp/app/routes/admin.api.v1.migrate-legacy-master-queues.ts
  • apps/webapp/app/routes/admin.api.v1.orgs.$organizationId.concurrency.ts
  • apps/webapp/app/routes/admin.api.v1.orgs.$organizationId.environments.staging.ts
  • apps/webapp/app/routes/admin.api.v1.orgs.$organizationId.feature-flags.ts
  • apps/webapp/app/routes/admin.api.v1.orgs.$organizationId.runs.enable.ts
  • apps/webapp/app/routes/admin.api.v1.platform-notifications.ts
  • apps/webapp/app/routes/admin.api.v1.runs-replication.$batchId.backfill.ts
  • apps/webapp/app/routes/admin.api.v1.runs-replication.$batchId.cancel.ts
  • apps/webapp/app/routes/admin.api.v1.runs-replication.backfill.ts
  • apps/webapp/app/routes/admin.api.v1.runs-replication.create.ts
  • apps/webapp/app/routes/admin.api.v1.runs-replication.start.ts
  • apps/webapp/app/routes/admin.api.v1.runs-replication.stop.ts
  • apps/webapp/app/routes/admin.api.v1.runs-replication.teardown.ts
  • apps/webapp/app/routes/admin.api.v1.snapshot.ts
  • apps/webapp/app/routes/admin.api.v1.workers.ts
  • apps/webapp/app/services/personalAccessToken.server.ts
  • apps/webapp/app/v3/services/worker/workerGroupService.server.ts

@nicktrn nicktrn added the ready label Apr 15, 2026
@nicktrn
Copy link
Copy Markdown
Collaborator Author

nicktrn commented Apr 15, 2026

ready

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.

1 participant