Repository navigation
fix(proxy): make "Test All" read-only + add bulk enable/disable (#6246) #6299
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
diegosouzapw
merged 3 commits into
release/v3.8.45
from
fix/escalated-6246-testall-readonly-bulk
Jul 5, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
482a77c
fix(proxy): make "Test All" read-only + add bulk enable/disable (#6246)
diegosouzapw 552684e
Merge remote-tracking branch 'origin/release/v3.8.45' into pr6299
diegosouzapw 6d98f84
chore(changelog): restore #6296 núcleo bullet eaten by release-merge …
diegosouzapw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { z } from "zod"; | ||
| import { updateProxy } from "@/lib/localDb"; | ||
| import { createErrorResponse, createErrorResponseFromUnknown } from "@/lib/api/errorResponse"; | ||
| import { requireManagementAuth } from "@/lib/api/requireManagementAuth"; | ||
| import { clearDispatcherCache } from "@omniroute/open-sse/utils/proxyDispatcher"; | ||
| import { isValidationFailure, validateBody } from "@/shared/validation/helpers"; | ||
|
|
||
| const batchActivateSchema = z.object({ | ||
| ids: z.array(z.string()).min(1).max(500), | ||
| // "active" (bulk enable) or "inactive" (bulk disable). Defaults to enable — | ||
| // the #6246 ask was a way to re-enable proxies an operator had disabled. | ||
| status: z.enum(["active", "inactive"]).optional().default("active"), | ||
| }); | ||
|
|
||
| /** | ||
| * POST /api/settings/proxies/batch-activate | ||
| * | ||
| * Bulk-set the status of multiple proxies in one request (#6246). This is the | ||
| * ONLY automated path allowed to change proxy status — it is an explicit | ||
| * operator action, unlike the reachability probes which are read-only by | ||
| * default (see src/lib/proxyHealth/statusPolicy.ts). | ||
| */ | ||
| export async function POST(request: Request) { | ||
| const authError = await requireManagementAuth(request); | ||
| if (authError) return authError; | ||
|
|
||
| let rawBody: unknown; | ||
| try { | ||
| rawBody = await request.json(); | ||
| } catch { | ||
| return createErrorResponse({ status: 400, message: "Invalid JSON body", type: "invalid_request" }); | ||
| } | ||
|
|
||
| const validation = validateBody(batchActivateSchema, rawBody); | ||
| if (isValidationFailure(validation)) { | ||
| return createErrorResponse({ status: 400, message: validation.error.message, type: "invalid_request" }); | ||
| } | ||
|
|
||
| const { ids, status } = validation.data; | ||
|
|
||
| try { | ||
| const results: Array<{ id: string; success: boolean; error?: string }> = []; | ||
| let updatedCount = 0; | ||
|
|
||
| for (const id of ids) { | ||
| try { | ||
| if (await updateProxy(id, { status })) { | ||
| results.push({ id, success: true }); | ||
| updatedCount++; | ||
| } else { | ||
| results.push({ id, success: false, error: "Proxy not found" }); | ||
| } | ||
| } catch (err) { | ||
| results.push({ id, success: false, error: err instanceof Error ? err.message : "Unknown error" }); | ||
| } | ||
| } | ||
|
|
||
| if (updatedCount > 0) { | ||
| try { clearDispatcherCache(); } catch { /* non-critical */ } | ||
| } | ||
|
|
||
| return Response.json({ | ||
| success: updatedCount > 0, | ||
| status, | ||
| updated: updatedCount, | ||
| failed: ids.length - updatedCount, | ||
| results, | ||
| }); | ||
| } catch (error) { | ||
| return createErrorResponseFromUnknown(error, "Failed to batch update proxy status"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * Proxy health-check status-write policy (#6246). | ||
| * | ||
| * The manual "Test All" reachability probe (`/api/settings/proxies/auto-test`) | ||
| * used to flip a proxy's `status` to `inactive` on a single failed probe. Because | ||
| * the egress selector excludes `inactive` proxies (PROXY_ALIVE_PREDICATE), a flaky | ||
| * external probe (an unreachable httpbin.org, a proxy that blocks HEAD, or a slow | ||
| * paid proxy) silently disabled every proxy that failed — "Test All" is a test, | ||
| * not test-and-set. | ||
| * | ||
| * Policy: automated reachability probes are **read-only by default** — they never | ||
| * write a proxy's status. Only the operator sets a proxy active/inactive (same | ||
| * contract as provider accounts, which are auto-disabled only when the operator | ||
| * opts in). Set `PROXY_HEALTH_AUTO_DEACTIVATE=true` to restore the legacy | ||
| * test-and-set behavior (probe result writes `active`/`inactive`). | ||
| */ | ||
|
|
||
| /** | ||
| * Resolve the status an automated health probe should WRITE for a proxy, or | ||
| * `null` to leave the status untouched (the default). Pure + unit-testable. | ||
| * | ||
| * @param alive whether the reachability probe succeeded | ||
| * @param env environment source (defaults to process.env) | ||
| */ | ||
| export function resolveHealthCheckStatusWrite( | ||
| alive: boolean, | ||
| env: { PROXY_HEALTH_AUTO_DEACTIVATE?: string } = process.env | ||
| ): "active" | "inactive" | null { | ||
| if ((env.PROXY_HEALTH_AUTO_DEACTIVATE ?? "").trim().toLowerCase() !== "true") { | ||
| // Default: never let an automated probe change a proxy's status. | ||
| return null; | ||
| } | ||
| return alive ? "active" : "inactive"; | ||
| } | ||
|
|
||
| /** True when automated probes are allowed to write proxy status (opt-in). */ | ||
| export function isProxyHealthAutoDeactivateEnabled( | ||
| env: { PROXY_HEALTH_AUTO_DEACTIVATE?: string } = process.env | ||
| ): boolean { | ||
| return (env.PROXY_HEALTH_AUTO_DEACTIVATE ?? "").trim().toLowerCase() === "true"; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Rule 8 of the Repository Style Guide ('Always validate inputs with Zod schemas from
src/shared/validation/schemas.ts'), all Zod schemas used for input validation must be defined insrc/shared/validation/schemas.tsrather than locally within the route file. Please movebatchActivateSchematosrc/shared/validation/schemas.tsand import it here.References