Skip to content

Commit b179c95

Browse files
authored
fix(engine): emit SystemMemory cgroup notice to stderr, not stdout (#2520)
1 parent a10e462 commit b179c95

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎packages/engine/src/services/systemMemory.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,27 @@ describe("getSystemTotalMb", () => {
252252
);
253253
});
254254

255+
it("logs the cgroup-limit notice to stderr, not stdout (keeps --json output clean)", async () => {
256+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
257+
const info = vi.spyOn(console, "info").mockImplementation(() => {});
258+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
259+
await withSystemMemoryMocks(
260+
{
261+
files: {
262+
[CGROUP_V2_MEMORY_MAX_PATH]: `${4096 * BYTES_PER_MIB}`,
263+
},
264+
},
265+
({ getSystemTotalMb }) => {
266+
expect(getSystemTotalMb()).toBe(4096);
267+
expect(warn).toHaveBeenCalledTimes(1);
268+
expect(warn.mock.calls[0]?.[0]).toContain("[SystemMemory] cgroup memory limit detected");
269+
// stdout must stay clean so `check --json` output is machine-parseable.
270+
expect(info).not.toHaveBeenCalled();
271+
expect(log).not.toHaveBeenCalled();
272+
},
273+
);
274+
});
275+
255276
it("stays silent when cgroup files are absent", async () => {
256277
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
257278
await withSystemMemoryMocks({}, ({ getSystemTotalMb }) => {

‎packages/engine/src/services/systemMemory.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ function getCgroupLimitMb(): number | null {
9393

9494
_cachedCgroupLimitMb = parseCgroupLimitMb(v2Content, v1Content);
9595
if (_cachedCgroupLimitMb !== null) {
96-
console.info(
96+
// stderr, not stdout: this is a diagnostic notice, and commands like `check --json`
97+
// write their machine-readable payload to stdout. A banner on stdout corrupts that
98+
// payload for any JSON consumer (it broke the Video Agent's hyperframes check parse).
99+
console.warn(
97100
`[SystemMemory] cgroup memory limit detected: ${_cachedCgroupLimitMb} MiB — ` +
98101
`it governs memory-adaptive render behaviour instead of host RAM.`,
99102
);

0 commit comments

Comments
 (0)