Skip to content

Make deploy.sh safe against rewriting itself during git pull - #101

Merged
Maharsh17 merged 1 commit into
mainfrom
fix/deploy-self-update
Sep 25, 2026
Merged

Maharsh17 merged 1 commit into
mainfrom
fix/deploy-self-update

Conversation

@Maharsh17

Copy link
Copy Markdown
Member

Why

On 2026-09-25 the vex-agent API crash-looped in prod for about 8.5 hours. vex-agent-integration #87 added a git submodule update step to scripts/deploy.sh, but the deploy that shipped #87 was already running the old copy of the script. Bash reads a script as it executes, so when git pull rewrote the file mid-run, bash went on reading the new file at the old byte offset and skipped the inserted block. The image was built from the stale engine checkout and failed on ImportError: RunDistanceStream. The stale submodule also left the tree dirty, so every later deploy would have aborted at the uncommitted-changes check.

Both repos share this deploy script shape, so the same thing can happen to any commit that edits scripts/deploy.sh.

What

  • The script body is now one main function, called on the last line (main "$@"; exit). Bash parses a function completely before running it, so a mid-run rewrite of the file can't change what executes.
  • After git pull, if the pull changed scripts/deploy.sh, the script execs the new version. A new deploy step then ships on its first deploy, not the next one. The rerun pulls nothing, so it can't loop.

The body keeps its original indentation to keep the diff reviewable.

Verified

A local harness builds a throwaway origin plus a deploy checkout, pushes a commit that inserts a step before "Building" (the shape of #87), and runs the checkout's scripts/deploy.sh with docker and curl stubbed:

script inserted step on first deploy
current deploy.sh (lm-dashboard and vex-agent-integration) skipped
this PR ran; re-exec happened once, then "Already up to date"

The transition was also simulated with the exact bytes: the current script running while the pull brings in this version. Both repos finish the deploy normally, so this PR is safe to ship through the webhook.

🤖 Generated with Claude Code

@Maharsh17
Maharsh17 merged commit c189122 into main Sep 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant