From 497b397e873f96d6fde3d8a44b3318e1ee1cbef4 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Fri, 29 May 2026 23:14:55 +0900 Subject: fix(claude): eliminate /home mount race that blanks Claude credentials at boot On hosts where /home is a separate filesystem, the dispatch-api service could start before /home was mounted. The API's first DB access then failed (EACCES: mkdir '/home/tradam'), Claude account discovery silently caught the error and left claudeAccounts empty, and -- because discovery only ran in the constructor -- it stayed empty for the whole process lifetime. Every Claude message then fell back to the deepseek-v4-flash / empty-key defaults, producing a 401 'Missing API key' from OpenCode Zen. Fixes: - s6 run script waits (capped ~30s) for /home/tradam before exec'ing bun; passes instantly where /home is on the root filesystem. - systemd unit gains RequiresMountsFor=/home and After=...home.mount. - agent-manager re-runs _refreshClaudeAccounts() on config hot-reload and lazily on an empty cache in the Anthropic path, so a process that lost the boot race self-heals on the next request instead of staying broken. --- packaging/dispatch-api@.service | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'packaging/dispatch-api@.service') diff --git a/packaging/dispatch-api@.service b/packaging/dispatch-api@.service index 3449fcb..e1946dd 100644 --- a/packaging/dispatch-api@.service +++ b/packaging/dispatch-api@.service @@ -1,19 +1,19 @@ -# Dispatch API — system service template. -# Runs under the system manager (PID 1) but drops privileges to the user named -# in the instance: `dispatch-api@tradam` runs as the `tradam` user. -# -# Enable/start: -# sudo systemctl enable --now dispatch-api@ [Unit] -Description=Dispatch API Backend (running as %i) -After=network.target +Description=Dispatch API server (user %i) +After=network.target local-fs.target home.mount +# The API stores its SQLite DB and reads Claude credentials under the user's +# home (~/.local/share/dispatch). If /home is a separate filesystem, starting +# before it is mounted makes credential discovery fail (EACCES) and Claude +# tabs fall back to an empty API key (401). Ensure /home is mounted first. +RequiresMountsFor=/home [Service] Type=simple User=%i +Environment=NODE_ENV=production +Environment=PORT=18390 WorkingDirectory=/opt/dispatch ExecStart=/usr/bin/bun packages/api/src/index.ts -EnvironmentFile=-/etc/dispatch/dispatch-api.conf Restart=on-failure RestartSec=5 -- cgit v1.2.3