From 12ac5200143e67d483359b987596cd08e035f429 Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com> Date: Wed, 1 Jul 2026 21:49:48 -0300 Subject: [PATCH] fix(cli): rename process title to omniroute (#5791) Integrated into release/v3.8.43 --- CHANGELOG.md | 2 ++ src/instrumentation-node.ts | 19 ++++++++++++ .../instrumentation-process-title.test.ts | 30 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/unit/instrumentation-process-title.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c94c8ed7f..1aa0af29aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,8 @@ - **Security hardening follow-ups (v3.8.15):** the `auth_token` cookie now sets an explicit 30-day `maxAge` so sessions persist as intended (Seg3); the management bootstrap warns at boot when `INITIAL_PASSWORD` is left at the insecure `CHANGEME` default (Seg2); VS Code path-token endpoints (`/api/v1/vscode/raw/[token]`) emit a once-per-process security warning since the API key travels in the URL and can leak via logs/proxies (Seg4); the system version route resolves the real global install path via `npm root -g` instead of a hardcoded `/app` (Bug3); and auto-update mode detection segment-matches `node_modules` instead of substring-matching, eliminating false "global install" positives (Bug1). +- **fix(cli):** rename the Node process title to `omniroute` so it shows correctly in ps/htop. (thanks @waguriagentic) + ### 📝 Maintenance --- diff --git a/src/instrumentation-node.ts b/src/instrumentation-node.ts index f97ff72e60..bdc202e9e2 100755 --- a/src/instrumentation-node.ts +++ b/src/instrumentation-node.ts @@ -20,6 +20,21 @@ function toHex(bytes: Uint8Array): string { return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(""); } +/** + * Rename a Node process title so OmniRoute is identifiable in `ps`/`htop` + * instead of the generic Next.js standalone server name. + * + * Only rewrites titles that start with "next-server", preserving any + * trailing suffix (e.g. " (v16.2.9)"). Every other title — including one + * that has already been renamed, or one that merely contains + * "next-server" elsewhere — passes through unchanged. Empty/undefined-safe. + */ +export function renameProcessTitle(currentTitle: string): string { + if (!currentTitle) return currentTitle; + if (!currentTitle.startsWith("next-server")) return currentTitle; + return `omniroute${currentTitle.slice("next-server".length)}`; +} + function isBackgroundServicesDisabled(): boolean { const raw = process.env.OMNIROUTE_DISABLE_BACKGROUND_SERVICES; if (!raw) return false; @@ -69,6 +84,10 @@ async function ensureSecrets(): Promise { } export async function registerNodejs(): Promise { + // Rename the process title so OmniRoute is identifiable in ps/htop instead + // of the generic "next-server" standalone server name. + process.title = renameProcessTitle(process.title); + // Initialize proxy fetch patch FIRST (before any HTTP requests) await import("@omniroute/open-sse/index.ts"); console.log("[STARTUP] Global fetch proxy patch initialized"); diff --git a/tests/unit/instrumentation-process-title.test.ts b/tests/unit/instrumentation-process-title.test.ts new file mode 100644 index 0000000000..70e3414292 --- /dev/null +++ b/tests/unit/instrumentation-process-title.test.ts @@ -0,0 +1,30 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { renameProcessTitle } from "../../src/instrumentation-node"; + +test("renameProcessTitle renames a bare 'next-server' title to 'omniroute'", () => { + assert.equal(renameProcessTitle("next-server"), "omniroute"); +}); + +test("renameProcessTitle preserves a version suffix after 'next-server'", () => { + assert.equal(renameProcessTitle("next-server (v16.2.9)"), "omniroute (v16.2.9)"); +}); + +test("renameProcessTitle passes through titles that do not start with 'next-server' unchanged", () => { + assert.equal(renameProcessTitle("node"), "node"); + assert.equal(renameProcessTitle("some-other-process"), "some-other-process"); + assert.equal(renameProcessTitle("my-next-server-thing"), "my-next-server-thing"); +}); + +test("renameProcessTitle is idempotent when called again on an already-renamed title", () => { + const once = renameProcessTitle("next-server (v16.2.9)"); + const twice = renameProcessTitle(once); + assert.equal(once, "omniroute (v16.2.9)"); + assert.equal(twice, "omniroute (v16.2.9)"); +}); + +test("renameProcessTitle is empty/undefined safe", () => { + assert.equal(renameProcessTitle(""), ""); + // @ts-expect-error - exercising runtime safety for a possibly-undefined process.title + assert.equal(renameProcessTitle(undefined), undefined); +});