Skip to content

Commit 302cf91

Browse files
author
Baudbot
committed
fix: unset PKG_EXECPATH and stale varlock-managed env vars in startup-cleanup
When startup-cleanup.sh runs mid-session (called by the control agent), inherited env vars cause bridge startup failures: 1. PKG_EXECPATH — leaked from the parent varlock-launched process, causes varlock's SEA binary to misinterpret subcommands as Node module paths. The varlock broker-key probes (lines 115-122) silently fail, resulting in 'No Slack transport configured' and the bridge never starting. 2. varlock run does not override env vars already present in the parent process. If any managed value (broker tokens, API keys, config) was rotated after session start, the supervisor passes the stale values instead of reading fresh ones from ~/.config/.env. Fix: - unset PKG_EXECPATH at the script top (before varlock probes) - In the supervisor subshell, dynamically unset ALL varlock-managed keys via 'varlock load --format env' before calling 'varlock run', so every restart gets fresh values regardless of which keys changed. Regression from #148.
1 parent 94790e3 commit 302cf91

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

pi/skills/control-agent/startup-cleanup.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
set -euo pipefail
1313

14+
# Prevent varlock SEA binary from misinterpreting argv when called from a
15+
# session that was itself launched via varlock (PKG_EXECPATH leaks into child
16+
# processes and causes `varlock run` to treat subcommands as Node module paths).
17+
unset PKG_EXECPATH 2>/dev/null || true
18+
1419
BRIDGE_POLICY_HELPER="$HOME/runtime/bin/lib/bridge-restart-policy.sh"
1520
if [ -r "$BRIDGE_POLICY_HELPER" ]; then
1621
# shellcheck source=bin/lib/bridge-restart-policy.sh
@@ -140,6 +145,16 @@ echo "Starting slack-bridge ($BRIDGE_SCRIPT) with PI_SESSION_ID=$MY_UUID..."
140145
mkdir -p "$BRIDGE_LOG_DIR"
141146
(
142147
unset PKG_EXECPATH
148+
# Clear ALL varlock-managed env vars inherited from the parent session.
149+
# varlock run does not override vars already set in the environment, so
150+
# stale values (e.g. expired broker tokens) would leak through. By unsetting
151+
# every key varlock manages, we guarantee varlock run injects fresh values
152+
# from ~/.config/.env on every bridge restart.
153+
if command -v varlock >/dev/null 2>&1; then
154+
while IFS='=' read -r key _; do
155+
[ -n "$key" ] && unset "$key"
156+
done < <(varlock load --path "$HOME/.config/" --format env --compact 2>/dev/null)
157+
fi
143158
export PATH="$HOME/.varlock/bin:$HOME/opt/node/bin:$PATH"
144159
export PI_SESSION_ID="$MY_UUID"
145160
cd /opt/baudbot/current/slack-bridge

0 commit comments

Comments
 (0)