fix(desktop): skip the local gateway restart on update when the Desktop is remote-served

A Desktop whose active connection is remote (SSH/remote/cloud, including the
registry primary) owns no local messaging gateway, yet the update hand-off
always ran `hermes update --gateway`. On hosts where launchd/service recovery
fails, the updater falls back to a detached local `gateway run --replace`;
with the same Telegram bot token as the remote VPS gateway, the two processes
compete for getUpdates and Telegram rejects one consumer, taking the
production bot offline (#117529).

Pass the ownership down the hand-off: globalRemoteActive() now adds
--no-gateway (posix) / -NoGateway (windows) when the Desktop is remote-served,
and both orchestrators drop --gateway from every update invocation (initial +
retry). The local-ownership default keeps --gateway exactly as before.
This commit is contained in:
liuhao1024
2026-09-21 05:04:42 +08:00
committed by Teknium
parent 338b31226d
commit 04845f5f3e
5 changed files with 210 additions and 6 deletions

View File

@@ -38,6 +38,7 @@ set -u
ORIGINAL_ARGS=("$@")
INSTALL_ROOT="" BRANCH="main" DESKTOP_PID=0 RELAUNCH_TARGET=""
RELAUNCH_CWD="" SANDBOX_FALLBACK=0 RELAUNCH_ARGS=()
NO_GATEWAY=0
NO_UI=0 NO_MARKER_CLEANUP=0 SELF_TEST_UI=0 SELF_TEST_GATE=0 SELF_TEST_MARKER=0
SELF_TEST_TCC_HEAL=0
HANDOFF_DAEMONIZED=0
@@ -49,6 +50,7 @@ while [ $# -gt 0 ]; do
--relaunch-target) RELAUNCH_TARGET="$2"; shift 2 ;;
--relaunch-cwd) RELAUNCH_CWD="$2"; shift 2 ;;
--sandbox-fallback) SANDBOX_FALLBACK=1; shift ;;
--no-gateway) NO_GATEWAY=1; shift ;;
--no-ui) NO_UI=1; shift ;;
--no-marker-cleanup) NO_MARKER_CLEANUP=1; shift ;;
--self-test-ui) SELF_TEST_UI=1; shift ;;
@@ -771,9 +773,19 @@ if "${UPDATE_INVOKE[@]}" update --help 2>/dev/null | grep -q -- '--keep-stash';
else
log "installed hermes predates --keep-stash; running without it"
fi
log "running: ${UPDATE_INVOKE[*]} update --yes --gateway $KEEP_STASH --branch $BRANCH"
# --gateway restarts the local messaging gateway after the update. The
# Desktop omits it (--no-gateway) when it is served by a remote gateway
# (#117529): restarting a local one there is never wanted, and with the same
# channel credentials as the remote host it becomes a competing long-poll
# consumer (e.g. Telegram rejects one of the two getUpdates callers).
GATEWAY_FLAG="--gateway"
if [ "$NO_GATEWAY" -eq 1 ]; then
GATEWAY_FLAG=""
log "update requested without --gateway (remote-served Desktop)"
fi
log "running: ${UPDATE_INVOKE[*]} update --yes $GATEWAY_FLAG $KEEP_STASH --branch $BRANCH"
publish_stage "Updating code and dependencies"
OUT="$("${UPDATE_INVOKE[@]}" update --yes --gateway $KEEP_STASH --branch "$BRANCH" 2>&1)"; CODE=$?
OUT="$("${UPDATE_INVOKE[@]}" update --yes $GATEWAY_FLAG $KEEP_STASH --branch "$BRANCH" 2>&1)"; CODE=$?
printf '%s\n' "$OUT" >> "$LOG" 2>/dev/null
log "hermes update exit code: $CODE"
@@ -795,7 +807,7 @@ if [ "$CODE" -ne 0 ] && [ "$CODE" -ne 2 ]; then
fi
log "retrying once (freshly pulled fix loads on the second run)"
publish_stage "Retrying update"
OUT="$("${UPDATE_INVOKE[@]}" update --yes --gateway $KEEP_STASH --branch "$BRANCH" 2>&1)"; CODE=$?
OUT="$("${UPDATE_INVOKE[@]}" update --yes $GATEWAY_FLAG $KEEP_STASH --branch "$BRANCH" 2>&1)"; CODE=$?
printf '%s\n' "$OUT" >> "$LOG" 2>/dev/null
log "retry exit code: $CODE"
fi

View File

@@ -48,6 +48,7 @@ param(
[string]$RelaunchExe = "",
[switch]$NoUi,
[switch]$NoMarkerCleanup,
[switch]$NoGateway,
[switch]$SelfTestUi,
[switch]$SelfTestPipeDrain,
[switch]$SelfTestMarker,
@@ -1597,7 +1598,18 @@ try {
Write-HandoffLog $finalMsg
exit $finalCode
}
$updateArgs = @("-m", "hermes_cli.main", "update", "--yes", "--gateway", "--force", "--branch", $Branch)
# --gateway restarts the local messaging gateway after the update. The
# Desktop passes -NoGateway when it is served by a remote gateway
# (#117529): restarting a local one there is never wanted, and with the
# same channel credentials as the remote host it becomes a competing
# long-poll consumer (e.g. Telegram rejects one of the two getUpdates
# callers).
$gatewayArg = @("--gateway")
if ($NoGateway) {
$gatewayArg = @()
Write-HandoffLog "update requested without --gateway (remote-served Desktop)"
}
$updateArgs = @("-m", "hermes_cli.main", "update", "--yes") + $gatewayArg + @("--force", "--branch", $Branch)
# --keep-stash: never re-apply local source edits after the update (they
# stay parked in git stash). Probe --help first: the flag ships with newer
# backends and an unknown flag would abort argparse with exit 2, which