diff --git a/packages/mosaic/framework/tools/fleet/start-agent-session.sh b/packages/mosaic/framework/tools/fleet/start-agent-session.sh index 1d70409..7aacb67 100755 --- a/packages/mosaic/framework/tools/fleet/start-agent-session.sh +++ b/packages/mosaic/framework/tools/fleet/start-agent-session.sh @@ -90,11 +90,18 @@ MOSAIC_RUNTIME_BIN_PREFIX=$(_build_runtime_bin_prefix) # # We build the snippet as a double-quoted here-string embedded in a printf call # to avoid nested quoting problems. +# +# MOSAIC_AGENT_NAME must also be exported INTO the pane: panes inherit the tmux +# server environment (not this script's, and not the systemd unit's), so the +# name would otherwise be empty in-pane and the runtime's native heartbeat +# (which gates on MOSAIC_AGENT_NAME) would never fire. %q-quote it so it is a +# safe single bash token regardless of the name's characters. +AGENT_NAME_Q=$(printf '%q' "$AGENT_NAME") if [ -n "$MOSAIC_RUNTIME_BIN_PREFIX" ]; then - PANE_SHELL_SNIPPET="export PATH=\"${MOSAIC_RUNTIME_BIN_PREFIX}:\${PATH}\"; exec ${MOSAIC_AGENT_COMMAND}" + PANE_SHELL_SNIPPET="export MOSAIC_AGENT_NAME=${AGENT_NAME_Q}; export PATH=\"${MOSAIC_RUNTIME_BIN_PREFIX}:\${PATH}\"; exec ${MOSAIC_AGENT_COMMAND}" else - PANE_SHELL_SNIPPET="exec ${MOSAIC_AGENT_COMMAND}" + PANE_SHELL_SNIPPET="export MOSAIC_AGENT_NAME=${AGENT_NAME_Q}; exec ${MOSAIC_AGENT_COMMAND}" fi mkdir -p "$MOSAIC_AGENT_WORKDIR"