From 390690dd0abe672ac8436d4d9598ae0d883e7bc9 Mon Sep 17 00:00:00 2001 From: benzntech Date: Sat, 8 Aug 2026 08:19:41 +0530 Subject: [PATCH] fix(logging): make stream-chunk capture and request-shape logging opt-in Flip two heavy/noisy defaults to reduce resource load and log volume: - CALL_LOG_PIPELINE_CAPTURE_STREAM_CHUNKS now defaults to false. Stream chunks are the largest call-log artifact; capturing them on every request by default is what grows ~/.omniroute/call_logs by hundreds of MB in days. Operators can re-enable with =true. - OMNIROUTE_LOG_REQUEST_SHAPE now logs only when explicitly set to "1" (was: enabled unless set to "0"). Large-body diagnostics are debug tooling, not default behavior. Docs (.env.example + ENVIRONMENT.md) updated to match the new defaults. --- .env.example | 4 ++-- docs/reference/ENVIRONMENT.md | 4 ++-- src/app/api/v1/chat/completions/route.ts | 8 +++++--- src/lib/logEnv.ts | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 2ba4099968..f389dc7fb2 100644 --- a/.env.example +++ b/.env.example @@ -1345,7 +1345,7 @@ APP_LOG_TO_FILE=true # Whether call log pipeline capture stores stream chunks when enabled in settings. # Only applies when call_log_pipeline_enabled=true. -# Default: true +# Default: false (opt-in — saves disk: stream chunks are the biggest call-log artifact) # CALL_LOG_PIPELINE_CAPTURE_STREAM_CHUNKS=true # Maximum call log artifact size for pipeline captures, in KB. @@ -1784,7 +1784,7 @@ APP_LOG_TO_FILE=true # Log request shape (content-type + content-length) for large chat payloads. # Used by: src/app/api/v1/chat/completions/route.ts. Set to "0" to silence. -# Default: enabled. +# Default: disabled (opt-in). # OMNIROUTE_LOG_REQUEST_SHAPE=1 # Write raw (untruncated) request/response JSON in call log artifacts. diff --git a/docs/reference/ENVIRONMENT.md b/docs/reference/ENVIRONMENT.md index f1099872bd..925a1aede7 100644 --- a/docs/reference/ENVIRONMENT.md +++ b/docs/reference/ENVIRONMENT.md @@ -716,7 +716,7 @@ The logging system writes to both stdout and rotated log files. All configuratio | `CALL_LOG_MAX_ENTRIES` | `10000` | Max call log entries in the in-memory buffer. | | `CALL_LOGS_TABLE_MAX_ROWS` | `100000` | Max rows in the `call_logs` SQLite table before pruning. | | `MAX_PENDING_REQUEST_AGE_MS` | `3600000` (1 hour) | Max age for orphaned active request log entries before in-memory cleanup. | -| `CALL_LOG_PIPELINE_CAPTURE_STREAM_CHUNKS` | `true` | Store stream chunks in pipeline artifacts when `call_log_pipeline_enabled=true`. | +| `CALL_LOG_PIPELINE_CAPTURE_STREAM_CHUNKS` | `false` | Store stream chunks in pipeline artifacts when `call_log_pipeline_enabled=true`. Opt-in (`true`) — off by default to save disk. | | `CALL_LOG_PIPELINE_MAX_SIZE_KB` | `512` | Max pipeline call log artifact size in KB when `call_log_pipeline_enabled=true`. | | `PROXY_LOGS_TABLE_MAX_ROWS` | `100000` | Max rows in the `proxy_logs` SQLite table before pruning. | | `APP_LOG_ROTATION_CHECK_INTERVAL_MS` | `60000` (1 min) | How often `src/lib/logRotation.ts` re-checks the active log file size. | @@ -946,7 +946,7 @@ changing them requires a code edit, not an env var: | `CURSOR_AGENT_CLI_VERSION` | _(detect / pin)_ | `open-sse/utils/cursorAgentCliVersion.ts` | Agent CLI build id (`YYYY.MM.DD-`) for `x-cursor-client-version: cli-…` on Agent Run. | | `CURSOR_DATA_DIR` | _(probed)_ | `open-sse/utils/cursorAgentCliVersion.ts` | Override Cursor Agent CLI data dir (`…/versions/`); same var the official agent uses. | | `CURSOR_TOKEN` | _(unset)_ | `scripts/ad-hoc/cursor-tap.cjs` | Direct Cursor bearer token used by developer tooling. | -| `OMNIROUTE_LOG_REQUEST_SHAPE` | enabled (`!== "0"`) | `src/app/api/v1/chat/completions/route.ts` | Log content-type/length markers for large chat payloads. Set `"0"` to silence. | +| `OMNIROUTE_LOG_REQUEST_SHAPE` | disabled (opt-in via `"1"`) | `src/app/api/v1/chat/completions/route.ts` | Log content-type/length markers for large chat payloads when `"1"` is set. Off by default to reduce log noise. | | `DEBUG_RESPONSES_SSE_TO_JSON` | _(unset)_ | `open-sse/handlers/responseTranslator.ts` | Set `true` to log Responses API SSE→JSON translation details. | | `NEXT_PUBLIC_OMNIROUTE_E2E_MODE` | _(unset)_ | E2E test harness | Set `true` to enable E2E test mode (relaxed auth, test hooks). | diff --git a/src/app/api/v1/chat/completions/route.ts b/src/app/api/v1/chat/completions/route.ts index 77eed06416..84ae14522f 100644 --- a/src/app/api/v1/chat/completions/route.ts +++ b/src/app/api/v1/chat/completions/route.ts @@ -108,8 +108,8 @@ export async function POST(request) { try { // One-line marker for diagnosing 413 / Server-Action interceptions. // Logs only when Content-Length is present so debug noise stays low for - // typical chat payloads. Toggle off via OMNIROUTE_LOG_REQUEST_SHAPE=0. - if (process.env.OMNIROUTE_LOG_REQUEST_SHAPE !== "0") { + // typical chat payloads. Opt-in via OMNIROUTE_LOG_REQUEST_SHAPE=1. + if (process.env.OMNIROUTE_LOG_REQUEST_SHAPE === "1") { const ct = request.headers.get("content-type") ?? ""; const cl = request.headers.get("content-length"); if (cl && Number(cl) > 256 * 1024) { @@ -135,7 +135,9 @@ export async function POST(request) { if (!shapeCheck.success) { const issue = shapeCheck.error.issues[0]; const field = issue?.path?.length ? issue.path.join(".") : "body"; - return finishAdmission(errorResponse(400, `${field}: ${issue?.message ?? "Invalid request"}`)); + return finishAdmission( + errorResponse(400, `${field}: ${issue?.message ?? "Invalid request"}`) + ); } } diff --git a/src/lib/logEnv.ts b/src/lib/logEnv.ts index 8486628b4e..eb40bda66a 100644 --- a/src/lib/logEnv.ts +++ b/src/lib/logEnv.ts @@ -116,7 +116,7 @@ export function getCallLogsTableMaxRows(): number { } export function getCallLogPipelineCaptureStreamChunks(): boolean { - return parseBoolean(process.env.CALL_LOG_PIPELINE_CAPTURE_STREAM_CHUNKS, true); + return parseBoolean(process.env.CALL_LOG_PIPELINE_CAPTURE_STREAM_CHUNKS, false); } export function getCallLogPipelineMaxSizeBytes(): number {