diff --git a/.changeset/httpserver-skip-body-parsing.md b/.changeset/httpserver-skip-body-parsing.md new file mode 100644 index 00000000000..094faecc461 --- /dev/null +++ b/.changeset/httpserver-skip-body-parsing.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/core": patch +--- + +Add an optional `skipBodyParsing` flag to the internal HTTP server route definition, letting a route respond without reading or parsing the request body. diff --git a/apps/supervisor/src/workloadServer/index.ts b/apps/supervisor/src/workloadServer/index.ts index bf4b38012d5..5dd1a79cc9a 100644 --- a/apps/supervisor/src/workloadServer/index.ts +++ b/apps/supervisor/src/workloadServer/index.ts @@ -596,19 +596,16 @@ export class WorkloadServer extends EventEmitter { ), }); } else { - // Lightweight mock route without schemas + // Disabled: drop immediately without reading/parsing the body and without + // any log we can't switch off. Older runners still POST per log line; the + // route stays registered (an unregistered route would log "No route match" + // per request) but sheds the request at minimal cost. Request metrics still + // count it. 204 is non-retryable on the runner client, so no retry storm. httpServer.route("/api/v1/workload-actions/runs/:runFriendlyId/logs/debug", "POST", { - handler: async (ctx) => - this.wideRoute( - ctx, - "logs.debug", - "/api/v1/workload-actions/runs/:runFriendlyId/logs/debug", - "POST", - async () => { - ctx.reply.empty(204); - }, - { highFrequency: true } - ), + skipBodyParsing: true, + handler: async (ctx) => { + ctx.reply.empty(204); + }, }); } diff --git a/packages/core/src/v3/serverOnly/httpServer.ts b/packages/core/src/v3/serverOnly/httpServer.ts index 4c4fa4eeb1e..1dcddf8f15a 100644 --- a/packages/core/src/v3/serverOnly/httpServer.ts +++ b/packages/core/src/v3/serverOnly/httpServer.ts @@ -29,6 +29,9 @@ interface RouteDefinition< querySchema?: TQuery; bodySchema?: TBody; keepConnectionAlive?: boolean; + /** Skip reading + parsing the request body. The handler receives `body: undefined`. + * Node drains any unconsumed body before the next keep-alive request. */ + skipBodyParsing?: boolean; handler: RouteHandler; } @@ -157,7 +160,7 @@ export class HttpServer { return reply.empty(405); } - const { handler, paramsSchema, querySchema, bodySchema, keepConnectionAlive } = + const { handler, paramsSchema, querySchema, bodySchema, keepConnectionAlive, skipBodyParsing } = routeDefinition; const params = this.parseRouteParams(route, url); @@ -176,7 +179,7 @@ export class HttpServer { return reply.text("Invalid query params", 400); } - const body = await getJsonBody(req); + const body = skipBodyParsing ? undefined : await getJsonBody(req); const parsedBody = this.optionalSchema(bodySchema, body); if (!parsedBody.success) {