Repository navigation
fix(ci): stash local changes before git pull on dev deploy - #943
Conversation
Every deploy to dev since 2026-05-13 (#826) failed. Sequence of failures: 1. PR #826 moved DEV_HOST/DEV_USER hardcoded refs to repo secrets. Secrets weren't set → 7 weeks of "missing server host" failures (resolved 2026-05-26 — secrets configured). 2. Once secrets worked, SSH connection succeeded but `git pull` aborted at "Your local changes to the following files would be overwritten by merge: docker-compose.prod.yml". The dev VM has a persistent checkout that accumulated hand-applied tweaks (or leftover state from a prior failed deploy). Root cause is the pull-style deploy model itself: dev VM owns a long-lived source checkout that the SSH script `git pull`s on every deploy. Build happens on the VM, not on CI. Local edits to tracked files block the pull. This patch: - Stashes dirty changes under a deploy-run-keyed message before pulling, so the deploy proceeds without losing the hand-applied edits. They survive in `git stash list` + the reflog (~90 days) on the VM. - Switches `git pull` to `--ff-only` so a divergent history fails fast instead of producing a silent merge commit. - Comments the long-term fix (move build to CI + image registry => stateless dev VM; tracked as a follow-up — file an issue). After merge, the next push to dev triggers a deploy that: - Stashes the existing docker-compose.prod.yml modification under `auto-stash-deploy-<run_id>` - Pulls cleanly (fast-forward) - Resumes normal build/restart The hand-applied change is recoverable with `git stash list` + `git stash show` + `git stash apply` on the VM. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
/code-review (extra-high recall, medium-confidence gate)Reviewed the 14-line workflow change end-to-end. Two findings posted as inline comments:
Verified (no findings)
Not introduced by this PR but worth flagging
VerdictOnce finding #1 is fixed, this PR is mergeable. The 🤖 /code-review at extra-high recall effort. False-positive rate biased toward over-reporting per skill spec. |
…n id
Review feedback on the previous commit: `$GITHUB_RUN_ID` lives on the
GH Actions runner, not on the dev VM where the SSH script runs.
`${GITHUB_RUN_ID:-manual}` silently fell back to "manual" every time,
defeating the deploy-run-keyed audit trail intent.
`${{ github.run_id }}` is interpolated at YAML render time, so the
literal run id is baked into the script before drone-ssh delivers it
to the remote.
Added an inline comment explaining the trap so the next person to
touch the script doesn't re-introduce it.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
/code-review (re-review after fix commit
|
| # | Status | Notes |
|---|---|---|
| 1 | ✅ RESOLVED | ${{ github.run_id }} interpolation correctly applied at line 47. Workflow-syntax expansion happens at YAML render time; the literal run id is baked into the script before drone-ssh ships it. Added an inline comment block warning future contributors about the $GITHUB_RUN_ID trap. |
| 2 | 🟡 UNCHANGED | #942 reference still points at the wrong issue. Author opted to defer — acceptable, but worth a one-line fix before merge (rephrase to (separate followup) or file the real issue + update the number). |
Fresh pass on the updated diff (5 angles, extra-high recall)
Line-by-line: STASH_MSG="auto-stash-deploy-${{ github.run_id }}" — workflow expression yields a numeric string; double-quoted bash assignment of a digit-only string is unambiguous. Clean.
Removed-behavior: The previous version had a :-manual fallback. The new version doesn't. If github.run_id were ever empty, the script would assign STASH_MSG="auto-stash-deploy-". In practice GH always populates run_id for workflow-triggered runs (this workflow is on: push only — never manual workflow_dispatch without a run), so this is theoretical. Not a finding.
Cross-file: Nothing in the codebase parses stash messages or git stash list output. The message is a human-debugging aid only — no automated consumer can break on the format change.
Language pitfalls: ${{ ... }} (workflow expression) vs ${VAR} (bash parameter expansion) are syntactically distinct via the double curlies — no parser ambiguity. The added comment block flags the trap clearly for future contributors.
Wrapper/proxy: N/A — not a wrapper change.
Sweep for gaps
Looked specifically for what the first-pass tends to miss on workflow YAML changes:
- YAML block scalar boundary issues — none, indentation preserved
- Trailing-whitespace gotchas in
|block — none introduced - Quote escaping in nested contexts (YAML → bash) — clean, single-level double quotes
- Race with
set -eand||— already verified clean in first review - Effect on the
concurrency:story — workflow still has no group, but the fix doesn't make this worse
No new findings.
Verdict
Ready to merge once finding #2 is either fixed or explicitly accepted as merge-time-cleanup. The CI itself can't validate this workflow change pre-merge (no syntax-checker for workflow expressions in the existing CI matrix), so the real verification is the next push to dev:
- Stash named
auto-stash-deploy-<run_id>(numeric run id, not "manual") git pull --ff-onlysucceeds- Deploy completes
git stash liston the dev VM shows the entry with the actual run id
🤖 /code-review at extra-high recall effort, 2nd pass.
vybe
left a comment
There was a problem hiding this comment.
Approved per /validate-pr. Tight hotfix, CI green, no security exposure. Minor: the inline (see #942) comment points at an unrelated issue — fix in a follow-up.
… break it PR Abilityai#943 added `git stash push -u -m "..."` before the dev pull. First deploy after merge (run 26454209415) failed: Saved working directory and index state On dev: auto-stash-deploy-... warning: failed to remove trinity-data/archives/: Permission denied warning: failed to remove trinity-data/avatars/...: Permission denied warning: failed to remove trinity-data/q.py: Permission denied No local changes to stash ← our `|| echo` fallback, MISLEADING ... error: Your local changes to the following files would be overwritten by merge: docker-compose.prod.yml The dev VM has Docker-volume directories (trinity-data/, archives/, avatars/) populated by containers running as root. The trinity user can't unlink those files. `git stash -u` tries to remove ALL untracked files as part of its working-tree-cleanup phase; the rm fails on the Docker-owned ones; stash aborts mid-cleanup, leaves the stash entry created but the tracked-file changes NOT reverted in the working tree; exits non-zero; our `|| echo` masks the failure as "no changes"; the subsequent `git pull --ff-only` aborts on the still-modified tracked file. Same symptom as the original bug, different root cause. Tracked-only stash (no `-u`) does what we actually want: capture the docker-compose.prod.yml modification, revert it in the working tree, let pull proceed. Untracked Docker-owned files are irrelevant to git pull — they don't block it and don't need to move. Stash entry from the failed run (`auto-stash-deploy-26454209415`) still exists on the dev VM and contains the docker-compose.prod.yml change. Inspect via `git stash list` + `git stash show -p stash@{N}`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Every deploy to dev has been failing since 2026-05-13 (#826). This patch unjams it.
Failure timeline
error: missing server host— PR #826 movedDEV_HOST/DEV_USERto repo secrets but they were never set.Your local changes to the following files would be overwritten by merge: docker-compose.prod.yml—git pullaborts because the dev VM's checkout has hand-applied changes.Root cause
The dev deploy is a pull-style model: the dev VM owns a persistent source checkout (
~/trinity) that the SSH scriptgit pulls on every deploy. Build happens on the VM, not on CI. Any local modifications to tracked files (intentional hot-fixes, leftover state from a failed deploy, hand-applied prod tweaks) block the pull and break every subsequent deploy.Change
Stash dirty changes under a deploy-run-keyed message before pulling, so the deploy proceeds without losing the hand-applied edits.
-u).git stash list(and the reflog ~90 days) on the VM — recoverable viagit stash show stash@{0}+git stash apply stash@{N}.--ff-onlymakes divergent history fail fast instead of producing a silent merge commit.Why not other options
git reset --hard origin/devgit stashwithout--ff-onlyTest plan
yamllint .github/workflows/deploy-dev.yml)git stash listand verify the previously-modifieddocker-compose.prod.ymlis recoverable asauto-stash-deploy-<run_id>git stash show -p stash@{0}) and decide whether it should be committed back to the repo or discarded permanentlyFollow-up issue to file
"Move dev deploy to image-registry pull (stateless dev VM)" — eliminates this whole class of failure. CI builds + pushes images to GHCR, dev runs only
docker compose pull && up. No git on dev. ~1–2 day rewrite.🤖 Generated with Claude Code