Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions electron/bridges/systemManagerBridge.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const CAPABILITY_SCRIPT_POSIX = [
const PROCESS_LIST_SCRIPT_POSIX = [
"exec sh -c ",
"'",
// Safety cap: head -n 2000 prevents maxBuffer/timeout on process-dense hosts.
// This is NOT a functional limit — monitored processes still show accurate metrics.
"ps -eo pid= -o ppid= -o user= -o stat= -o pcpu= -o pmem= -o rss= -o vsz= -o etime= -o args= 2>/dev/null | head -n 2000",
"ps -eo pid= -o ppid= -o user= -o stat= -o pcpu= -o pmem= -o rss= -o vsz= -o etime= -o args= 2>/dev/null",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stream process output instead of relying on maxBuffer

When this runs for a local Linux/macOS session with enough processes or long command lines, removing the row cap lets ps output exceed execOnLocalMachine's 10 MiB execFile maxBuffer in electron/bridges/systemManager/execOnSession.cjs; that path resolves as success if any stdout was captured, so parseProcessLines can silently show only the truncated prefix rather than all processes. ET sessions have an even smaller default execFile buffer, so this change can also turn large process lists into load failures. The cap removal should be paired with streaming/parsing or an explicit truncation/error path so dense hosts are not still capped by the transport buffer.

Useful? React with 👍 / 👎.

"'",
].join("");

Expand Down Expand Up @@ -166,10 +164,8 @@ function createSystemManagerBridge(deps) {
if (!sessionId) return { success: false, error: "Missing sessionId" };

if (isLocalSession(sessionId) && process.platform === "win32") {
// Safety cap: -First 2000 prevents maxBuffer/timeout on process-dense hosts.
// This is NOT a functional limit — monitored processes still show accurate metrics.
const result = await execOnLocalMachine(
"Get-CimInstance Win32_Process | Sort-Object KernelModeTime -Descending | Select-Object -First 2000 ProcessId,ParentProcessId,Name,WorkingSetSize | ConvertTo-Json -Compress",
"Get-CimInstance Win32_Process | Sort-Object KernelModeTime -Descending | Select-Object ProcessId,ParentProcessId,Name,WorkingSetSize | ConvertTo-Json -Compress",
10000,
);
Comment on lines 168 to 172

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pass the larger buffer to Windows process listing

On local Windows sessions this command now removes the -First 2000 cap, but the execOnLocalMachine call still omits maxBuffer, so it falls back to the 10 MiB default in execOnSession.cjs. On process-dense Windows hosts where the full JSON exceeds that default, listProcesses will now fail with a maxBuffer error instead of showing the uncapped list; this path should use the same larger process-list buffer as the POSIX path.

Useful? React with 👍 / 👎.

if (!result.success) return { success: false, error: result.error };
Expand Down
12 changes: 12 additions & 0 deletions electron/bridges/systemManagerBridge.processes.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { EventEmitter } = require("node:events");
const fs = require("node:fs");
const path = require("node:path");
const { createSystemManagerBridge } = require("./systemManagerBridge.cjs");

function createFakeExecStream(stdout, options = {}) {
Expand All @@ -26,8 +28,10 @@ test("listProcesses uses a ps format that works on CentOS 7 procps", async () =>
" 1 0 root Ss 0.0 0.0 4060 191024 2-19:23:42 /usr/lib/systemd/systemd --switched-root --system --deserialize 21",
].join("\n");

let seenCommand = "";
const conn = {
exec(command, callback) {
seenCommand = command;
const stdout = command.includes(compatiblePsFormat)
? compatibleOutput
: badCentos7Output;
Expand All @@ -46,6 +50,14 @@ test("listProcesses uses a ps format that works on CentOS 7 procps", async () =>
assert.equal(result.processes.length, 1);
assert.equal(result.processes[0].pid, 1);
assert.equal(result.processes[0].command, "/usr/lib/systemd/systemd --switched-root --system --deserialize 21");
assert.doesNotMatch(seenCommand, /head\s+-n\s+2000/);
});

test("process listing commands do not hard-cap the visible list at 2000 entries", () => {
const source = fs.readFileSync(path.join(__dirname, "systemManagerBridge.cjs"), "utf8");

assert.doesNotMatch(source, /head\s+-n\s+2000/);
assert.doesNotMatch(source, /Select-Object\s+-First\s+2000/);
});

test("probeCapabilities reports Docker when docker is installed even if plain docker access is denied", async () => {
Expand Down
Loading