fix(engine): emit SystemMemory cgroup notice to stderr, not stdout (#2520)

This commit is contained in:
James Russo
2026-07-16 00:36:25 -04:00
committed by GitHub
parent a10e462d02
commit b179c95362
2 changed files with 25 additions and 1 deletions
@@ -252,6 +252,27 @@ describe("getSystemTotalMb", () => {
);
});
it("logs the cgroup-limit notice to stderr, not stdout (keeps --json output clean)", async () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const info = vi.spyOn(console, "info").mockImplementation(() => {});
const log = vi.spyOn(console, "log").mockImplementation(() => {});
await withSystemMemoryMocks(
{
files: {
[CGROUP_V2_MEMORY_MAX_PATH]: `${4096 * BYTES_PER_MIB}`,
},
},
({ getSystemTotalMb }) => {
expect(getSystemTotalMb()).toBe(4096);
expect(warn).toHaveBeenCalledTimes(1);
expect(warn.mock.calls[0]?.[0]).toContain("[SystemMemory] cgroup memory limit detected");
// stdout must stay clean so `check --json` output is machine-parseable.
expect(info).not.toHaveBeenCalled();
expect(log).not.toHaveBeenCalled();
},
);
});
it("stays silent when cgroup files are absent", async () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
await withSystemMemoryMocks({}, ({ getSystemTotalMb }) => {
+4 -1
View File
@@ -93,7 +93,10 @@ function getCgroupLimitMb(): number | null {
_cachedCgroupLimitMb = parseCgroupLimitMb(v2Content, v1Content);
if (_cachedCgroupLimitMb !== null) {
console.info(
// stderr, not stdout: this is a diagnostic notice, and commands like `check --json`
// write their machine-readable payload to stdout. A banner on stdout corrupts that
// payload for any JSON consumer (it broke the Video Agent's hyperframes check parse).
console.warn(
`[SystemMemory] cgroup memory limit detected: ${_cachedCgroupLimitMb} MiB — ` +
`it governs memory-adaptive render behaviour instead of host RAM.`,
);