Skip to content

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

Merged
jrusso1020 merged 1 commit into
mainfrom
fix/systemmemory-banner-stderr
Jul 16, 2026
Merged

fix(engine): emit SystemMemory cgroup notice to stderr, not stdout#2520
jrusso1020 merged 1 commit into
mainfrom
fix/systemmemory-banner-stderr

Conversation

@jrusso1020

Copy link
Copy Markdown
Collaborator

What

Emit the [SystemMemory] cgroup memory limit detected: ... notice with console.warn (stderr) instead of console.info (stdout) in packages/engine/src/services/systemMemory.ts.

Why

The check --json command writes its machine-readable envelope to stdout via console.log. This SystemMemory notice was also going to stdout (console.info), so on any host with a cgroup memory limit it prepended a non-JSON line ahead of the --json payload and broke consumers that parse stdout as JSON. Standard CLI practice: stdout carries the data payload, diagnostics go to stderr. The sibling "unable to read cgroup" warning already uses console.warn (stderr); this aligns the detected-limit notice with it.

How

One-line change: console.info(...)console.warn(...) for the detected-limit notice. Message text and all memory-adaptive behaviour are unchanged — only the stream moves from stdout to stderr. dist/ is gitignored, so there is no built artifact to update.

Test plan

Added a regression test in packages/engine/src/services/systemMemory.test.ts asserting the detected-limit notice is emitted on console.warn and NOT on console.info/console.log, so check --json stdout stays machine-parseable.

  • bunx vitest run src/services/systemMemory.test.ts → 27 passed (vitest labels the notice output as stderr)

  • oxfmt + oxlint on both changed files → clean

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

RIGHT direction — approve. Root fix at the right layer: flip the SystemMemory cgroup diagnostic from stdout (console.info) to stderr (console.warn), aligning it with the sibling warnCgroupReadFailure in the same file. Every --json-emitting CLI benefits without further wiring.

Strengths

  • packages/engine/src/services/systemMemory.ts:96-100 — inline comment on why (check --json payload, Video Agent parse breakage) means the invariant lives with the log site, not just in this PR body. Future edits are unlikely to reintroduce the drift.
  • packages/engine/src/services/systemMemory.test.ts:255-272 — positive-and-negative pin (asserts warn called once with the notice, AND info/log NOT called). Guards against a re-drift to stdout even if someone re-adds console.info or console.log on the detected-limit branch.
  • Ground-truth alignment: packages/cli/src/commands/check.ts:118-136 confirms --json writes the machine-readable envelope via console.log (stdout) and the non-JSON banner is already gated by !asJson. The bug was exactly the described stream collision.
  • Ground-truth cleanliness: rg -n "console\.info" packages/engine packages/cli at head returns only the site this PR flips — no sibling console.info was left behind for a future rework cycle.

Verified premises

  • Sibling warnCgroupReadFailure at systemMemory.ts:140-148 already uses console.warn. Convention exists; this PR aligns the outlier.
  • No other tests depend on the notice text; no console.info spies in packages/engine. Change is fully isolated.
  • CI: all required checks green at 87327381c56c31c298fe53c76cd025bb6b05cb3f (CLI smoke required, Test, Windows, Fallow, Format, Lint, Typecheck, Build). regression-shards pending — a stdout-vs-stderr stream flip on a diagnostic log doesn't touch rendering, so those shards are non-shape-related to the merge decision.

Nits (non-blocking, optional)

  • nit — packages/engine/AGENTS.md (or the closest package convention doc) could carry a one-line rule: "engine diagnostics use console.warn; stdout is reserved for CLI data payloads." The inline comment gets us most of the way; a docs echo makes the convention discoverable via grep instead of by finding this file. Would prevent the next contributor from adding console.info somewhere new.
  • nit — the comment mentions the Video Agent parse specifically; if the incident has a ticket / Datadog link, threading it inline would help the next debugger who greps for the failure signature. Not blocking.

Verdict: APPROVE
Reasoning: One-line stream flip at the right layer, positive+negative test pin, no sibling drift, sibling function already established the stderr convention, and the merge-gate blocker is REVIEW_REQUIRED only.

— Via

@jrusso1020
jrusso1020 merged commit b179c95 into main Jul 16, 2026
47 checks passed
@jrusso1020
jrusso1020 deleted the fix/systemmemory-banner-stderr branch July 16, 2026 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants