Skip to content

macOS: 'MallocStackLogging: can't turn off malloc stack logging' spams stderr on every tool call #4375

Description

@yehsuf

Summary

On macOS, the copilot binary prints the following message to stderr once per subprocess spawned — meaning it appears on every tool call during a session:

copilot(20899) MallocStackLogging: can't turn off malloc stack logging because it was not enabled.

During an active session this message streams constantly, making it very noisy.

Steps to reproduce

  1. macOS (Apple Silicon or Intel)
  2. Run copilot chat and use any tool (file read, bash, etc.)
  3. Observe stderr output — the message appears for each subprocess spawned

Root cause

The copilot binary (v1.0.77, Node.js v24.16.0 bundled) includes a native addon that calls turn_off_stack_logging() unconditionally at process startup. On macOS, this function is part of the malloc subsystem and prints the warning when called if stack logging was never enabled (i.e. MallocStackLogging env var was absent).

Because Copilot CLI spawns a fresh subprocess for every tool invocation, the message appears once per tool call rather than once per session.

The call site is in a bundled native addon — turn_off_stack_logging() is not present in Node.js core source itself.

Fix

Guard the call with a check before invoking turn_off_stack_logging():

// Before
turn_off_stack_logging();

// After  
if (malloc_logger) {
    turn_off_stack_logging();
}

malloc_logger is the macOS malloc global that is non-NULL only when stack logging is actually enabled. This is the standard guard used in system code.

Alternatively, check whether MallocStackLogging is set in the environment before making the call.

Workaround (for users)

Wrap the copilot call in a shell function that filters the specific stderr pattern:

function _copilot() {
  copilot "$@" 2> >(grep -Fv 'MallocStackLogging:' >&2)
}

Environment

  • macOS 15 (Sequoia), Apple Silicon
  • copilot v1.0.77 (bundled Node.js v24.16.0)
  • Installed via brew cask

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions