Skip to content

spawn EBADF when gateway file descriptor count is high #77750

Description

@loyur

Problem

The gateway process accumulates thousands of open file descriptors (observed 14,039, of which 13,982 are .md files likely from plugins like claude-mem/lossless-claw). When child_process.spawn is called via exec tool, it fails with Error: spawn EBADF because posix_spawn cannot handle the massive fd table.

Error logs

[process/supervisor] spawn failed: runId=neat-atlas reason=Error: spawn EBADF
[tools] exec failed: spawn EBADF raw_params={"command":"bash /Users/loyu/.../healthcheck.sh","timeout":15}

This affects ALL exec tool calls — MCP server startup, shell scripts, Python scripts, simple ls commands.

Root cause

The default stdinMode in createChildAdapter is "inherit" when no input is provided. When combined with the fd leak, the inherit + detached: true spawn fails with EBADF. The existing no-detach fallback doesn't help because it still uses "inherit" stdin and the same fd table is inherited.

Additionally, the fd leak itself indicates that some plugin is opening markdown files without closing them.

Fix approach

  1. src/process/supervisor/adapters/child.ts: Default stdinMode to "pipe" when process.stdin.isTTY is false (i.e., service-managed gateway). In service mode, stdin is /dev/null so "inherit" provides no benefit but exposes the child to fd table issues.

  2. src/process/supervisor/adapters/child.ts: Always add a pipe-stdin fallback that retries with ["pipe", "pipe", "pipe"] + detached: false, so even if the first spawn fails with EBADF, it retries with a safe configuration.

Environment

  • openclaw: 2026.5.3
  • OS: macOS 26.1 (Darwin 25.4.0)
  • Node: 25.9.0
  • Running via launchd as a gateway service

Related

Will open a PR with the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions