[eric] apps: restart.sh lets the agent bounce its own runtime (sentinel watched by the harness)

This commit is contained in:
ciregenz
2026-07-02 02:48:21 -07:00
parent df603a0b75
commit 01e70fdd40
7 changed files with 188 additions and 17 deletions
+44 -5
View File
@@ -141,9 +141,8 @@ cat > "$DEST/backend_init.sh" <<'EOF'
# code — it copies the master template's backend/ into the workspace
# and flips BACKEND_PORT in both .env files to a free port.
#
# After running this, hard-reload the preview (right-click the reload
# button in the App Builder) so the runtime restarts with the new
# BACKEND_PORT and `bash run.sh` brings the backend up.
# After running this, run `bash restart.sh` so the runtime restarts
# with the new BACKEND_PORT and `bash run.sh` brings the backend up.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -212,11 +211,51 @@ fi
echo ""
echo "Backend enabled on port $PORT."
echo "Hard-reload the preview (right-click the reload button in"
echo "the App Builder) to bring it up."
echo "Run 'bash restart.sh' to bring it up (restarts the app runtime)."
EOF
chmod +x "$DEST/backend_init.sh"
# Patch 4: restart.sh — the agent-facing runtime restart. The runtime is
# owned by the OpenSwarm harness, so agents can't bounce it from Bash;
# this writes the sentinel the AppRuntimeManager watcher consumes
# (runtime.py RESTART_SENTINEL_NAME) and waits for pickup.
cat > "$DEST/restart.sh" <<'EOF'
#!/usr/bin/env bash
# Restart this app's runtime (backend + vite), managed by the OpenSwarm harness.
#
# The runtime is spawned and owned by OpenSwarm, so you can't just kill/rerun
# run.sh from here. This script writes a sentinel the harness watches; the
# harness consumes it and restarts the whole runtime. No API token needed.
# Use after `bash backend_init.sh`, after editing `.env`, or whenever the
# backend must reload code/schema (uvicorn runs WITHOUT --reload on purpose).
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
mkdir -p "$HERE/.openswarm"
SENTINEL="$HERE/.openswarm/restart-requested"
touch "$SENTINEL"
echo "Restart requested; waiting for the OpenSwarm harness to pick it up..."
for _ in $(seq 1 30); do
if [[ ! -f "$SENTINEL" ]]; then
echo "Restart under way. The runtime takes a few seconds to come back;"
echo "then check .openswarm/terminal.log for boot output:"
sleep 6
tail -n 20 "$HERE/.openswarm/terminal.log" 2>/dev/null || true
exit 0
fi
sleep 1
done
rm -f "$SENTINEL"
echo "ERROR: the harness didn't pick up the restart within 30s." >&2
echo "The runtime only runs while the app is open in OpenSwarm (preview card or" >&2
echo "App Builder). If you're running this app standalone via 'bash run.sh'," >&2
echo "just Ctrl-C that process and rerun it instead." >&2
exit 1
EOF
chmod +x "$DEST/restart.sh"
echo ""
echo "[fetch-webapp-template] vendored snapshot at $DEST"
echo "[fetch-webapp-template] pinned ref: $REF"