Skip to content

LaunchAgent plist missing TMPDIR causes SQLITE_CANTOPEN on macOS #20489

@nasacontrol-hq

Description

@nasacontrol-hq

Bug

The gateway fails with SQLITE_CANTOPEN: unable to open database file on every startup when run via the macOS LaunchAgent generated by openclaw gateway install.

The gateway works perfectly when run from an interactive shell (nohup or direct).

Root Cause

The LaunchAgent plist generated by openclaw gateway install does not include TMPDIR in its EnvironmentVariables dict. macOS launchd does not inherit shell environment variables, so TMPDIR is unset when the gateway starts via launchd.

SQLite (specifically the experimental node:sqlite used by OpenClaw) requires TMPDIR to create journal/WAL temp files. Without it, SQLite cannot open or create its database file, resulting in:

Uncaught exception: Error: SQLITE_CANTOPEN: unable to open database file
    at subsystem-oVAQxyhr.js:271

The error is thrown very early in startup (before plugins register) but is non-fatal — the gateway recovers and runs, but the error fires on every restart.

Evidence

Interactive shell provides:

TMPDIR=/var/folders/xw/f9h9x3qs3vn38c8xqsd2flb80000gn/T/

The LaunchAgent plist does NOT set TMPDIR. OpenClaw creates a temp directory at $TMPDIR/openclaw-$UID/ which SQLite needs access to.

Expected Behavior

openclaw gateway install should auto-populate TMPDIR (and other essential env vars like LANG, USER, LOGNAME) in the generated LaunchAgent plist, since launchd does not inherit the user shell environment.

Suggested Fix

In the plist generation code, capture and include at minimum:

  • TMPDIR (critical for SQLite)
  • LANG (locale)
  • HOME (already included)
  • USER / LOGNAME

Or alternatively, have the gateway set TMPDIR to a sensible default (e.g., /tmp or $HOME/.openclaw/tmp/) if it detects TMPDIR is unset at startup.

Environment

  • OpenClaw version: 2026.2.17
  • macOS: Darwin 25.2.0 (arm64, Apple Silicon)
  • Node.js: v24.13.1
  • Install method: npm global (npm install -g openclaw)
  • LaunchAgent label: ai.openclaw.gateway

Workaround

Manually add TMPDIR to the plist EnvironmentVariables:

<key>TMPDIR</key>
<string>/var/folders/xw/.../T/</string>

Or run the gateway via nohup from an interactive shell instead of using the LaunchAgent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions