Skip to content

Fix LaunchAgent missing TMPDIR causing SQLITE_CANTOPEN on macOS#20512

Merged
gumadeiras merged 4 commits intoopenclaw:mainfrom
Clawborn:fix/launchd-tmpdir-env
Feb 19, 2026
Merged

Fix LaunchAgent missing TMPDIR causing SQLITE_CANTOPEN on macOS#20512
gumadeiras merged 4 commits intoopenclaw:mainfrom
Clawborn:fix/launchd-tmpdir-env

Conversation

@Clawborn
Copy link
Copy Markdown
Contributor

@Clawborn Clawborn commented Feb 19, 2026

Problem

When the gateway runs as a macOS LaunchAgent (installed via openclaw gateway install), SQLite fails with SQLITE_CANTOPEN: unable to open database file on every startup.

macOS launchd does not inherit shell environment variables. The generated plist includes HOME and PATH but omits TMPDIR. Without TMPDIR, SQLite cannot locate the per-user temp directory (/var/folders/…) needed for journal and WAL files.

Running the gateway from an interactive shell works because TMPDIR is set by the shell.

Fix

Forward TMPDIR and LANG from the host environment into the service environment for both gateway and node LaunchAgents.

  • TMPDIR: required by SQLite for temp file creation on macOS
  • LANG: ensures consistent locale for string collation and file encoding

Both are omitted from the plist when unset in the host environment (the existing renderEnvDict filter handles this).

Tests

4 new test cases covering TMPDIR/LANG forwarding for both gateway and node service environments.

Fixes #20489

Greptile Summary

Forwards TMPDIR and LANG environment variables from the host environment to both gateway and node LaunchAgent services on macOS. This fixes SQLite's SQLITE_CANTOPEN error that occurs when the gateway runs as a LaunchAgent, where TMPDIR is needed for SQLite journal and WAL files. The renderEnvDict filter ensures these variables are omitted from the plist when unset in the host environment.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is minimal, well-tested, and directly addresses the root cause. The implementation correctly forwards environment variables through existing infrastructure that already handles undefined values appropriately. The changes are limited to two straightforward additions per function with comprehensive test coverage.
  • No files require special attention

Last reviewed commit: 296d5ed

Forward TMPDIR and LANG from the host environment into the generated
LaunchAgent and systemd service environment. macOS launchd does not
inherit shell environment variables, so TMPDIR is unset when the
gateway runs as a LaunchAgent. This causes SQLite to fail with
SQLITE_CANTOPEN because it cannot create journal/WAL temp files in
the per-user temp directory (/var/folders/...).

LANG is also forwarded to ensure consistent locale behavior for
string collation and file I/O encoding.

Fixes openclaw#20489

Co-authored-by: Clawborn <tianrun.yang103@gmail.com>
@gumadeiras gumadeiras merged commit 2bb8ead into openclaw:main Feb 19, 2026
22 checks passed
@gumadeiras
Copy link
Copy Markdown
Member

Merged via squash.

Thanks @Clawborn!

mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
…claw#20512)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 25ba597
Co-authored-by: Clawborn <261310391+Clawborn@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…claw#20512)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 25ba597
Co-authored-by: Clawborn <261310391+Clawborn@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…claw#20512)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 25ba597
Co-authored-by: Clawborn <261310391+Clawborn@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…claw#20512)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 25ba597
Co-authored-by: Clawborn <261310391+Clawborn@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…claw#20512)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 25ba597
Co-authored-by: Clawborn <261310391+Clawborn@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LaunchAgent plist missing TMPDIR causes SQLITE_CANTOPEN on macOS

2 participants