AGENT SKILL

git-push-gate-failures

Use when a push is blocked and the cause is unclear.

License 许可
MIT
最近更新
2026-11-14
Stars
★ 4
Forks
1

01 前言 Front Matter

name
git-push-gate-failures
tags
[ "git", "push", "hooks", "deploy", "shell" ]
author
Steadfaste Fleet
version
1.0.0
description
Use when a push is blocked and the cause is unclear.
related_skills
[ "shared-repo-push-gates", "enforcement-change-safety", "shell-scripting" ]

02 资源文件 1

03 SKILL.md 正文

Git Push Gate Failures

Diagnosis patterns for blocked pushes in repos with the fleet governance hooks (pre-push-pull, doctor gate, dogfood). Most rejections are ENVIRONMENTAL — a stale deploy record, a hook false positive, or a shell exit-code trap — not a problem with your diff. Diagnose the gate first; your commit is usually fine.

1. "Deploy sync FAIL" that survives repeated fleet-update runs

Symptom: fleet-doctor.py shows ❌ Deploy sync with "HEAD ahead of last deploy" even after fleet-update.sh runs "cleanly" (rc 0 or rc 1 with a normal-looking log tail). The pre-push gate then blocks every push.

Mechanism: the doctor compares git rev-parse HEAD against ~/.steadfaste-fleet/state/update-commit, which fleet-update.sh writes near the END of its run. If ANY earlier step dies under set -euo pipefail, the record never advances. The log tail looks fine because the failing section (service restarts) is adjacent to the end.

Simplest cause — check this before bash -x: the deploy was never run. Manually cp-ing changed files to ~/.steadfaste-fleet/scripts/ (e.g. to work around a slow fleet-update.sh --force timeout) does NOT advance state/update-commit — only fleet-update.sh writes it, so a manual copy leaves the marker behind HEAD and the dogfood gate blocks every push. Tell: git log --oneline -1 origin/main shows your commit while cat ~/.steadfaste-fleet/state/update-commit is an older SHA, and bash -x finds no dying step because none ran. Fix: bash ops/scripts/fleet-update.sh --force, confirm cat state/update-commit == git rev-parse HEAD, push.

Diagnosis (the tell):

stat -c '%y' ~/.steadfaste-fleet/state/update-commit 2>/dev/null || stat -f '%Sm' ~/.steadfaste-fleet/state/update-commit   # mtime BEFORE your changes? (GNU first, BSD fallback)

An old mtime while deploys "run clean" = the deploy is dying before the record write. Find the dying step: bash -x ops/scripts/fleet-update.sh --force and read the trace around the last output. Fix that step, re-deploy, and confirm the record advanced ("State saved: <hash>" + fresh mtime). rc of a piped run (bash script.sh | tail) is NOT completion proof.

Real root cause found this way (2026-09-01): systemd ≥261 requires the .service suffix in systemctl list-unit-files <name> — a bare name returns EMPTY output/rc=1 even when the unit exists. fleet-update's SERVICE_CTL scope-detection grepped ^${unit} on a suffix-less query, the check failed, it fell back to systemctl --user, and the dbus error ("Failed to connect to user scope bus") under set -euo pipefail killed the deploy before state/update-commit was written. Fix: normalize the unit name ([[ "$unit" == *.* ]] || unit="${unit}.service") before querying.

2. First push to a brand-new remote is rejected

Symptom: git push -u origin main on a repo with an EMPTY remote fails with "pre-push-pull: git fetch failed". The remote was just created via the GitHub UI with no initial commit.

Mechanism: the pre-push hook runs git fetch origin "$branch" unconditionally; on an empty remote the ref doesn't exist, fetch fails with "couldn't find remote ref main", and the hook blocks the push — a false positive (nothing to be behind; the no-verify gate already handles new branches via remote_sha=0).

Fixed hook behavior (2026-09-01): the hook now discriminates with git ls-remote --exit-code origin "$branch" captured as || LSRC=$?:

LSRC=0
git ls-remote --exit-code origin "$branch" >/dev/null 2>&1 || LSRC=$?
if [[ $LSRC -eq 2 ]]; then
  : # ref absent → first push, allow (no-verify gate still checks new branches)
else
  exit 1   # ref present (0) or network/auth failure (≠2) → fail CLOSED
fi

⚠️ FAIL-OPEN trap: a bare if git ls-remote ...; then block; fi treats a NETWORK failure (exit 128) the same as "ref absent" (exit 2) — a dead remote pushes through. Only the exact -eq 2 check fails closed.

On a host with a pre-fix deployed hook: create the remote ref manually (first commit via GitHub UI, or push once from a non-hook context) so the fetch succeeds, or deploy the hook fix first.

3. Exit-code-vs-output shell traps (set -euo pipefail)

Two commands return non-zero for EXPECTED results, silently killing scripts:

  • systemctl is-enabled <unit> exits 1 when MASKED (prints "masked") — the desired state, not a failure.
  • git ls-remote --exit-code <remote> <ref> exits 2 when the ref is absent — "no match" is the expected case.

Trap A — || echo fallback fires on EXIT CODE, not empty output:

state="$(systemctl is-enabled hibernate.target 2>/dev/null || echo unknown)"
[[ "$state" == "masked" ]]  # FAILS — value is "masked\nunknown"

state="$(systemctl is-enabled hibernate.target 2>/dev/null || true)"
[[ "$state" == "masked" ]]  # works

Trap B — standalone non-zero command kills the script before $?: capture in the ||, initialize first, branch only on the exact code:

LSRC=0
git ls-remote --exit-code origin main >/dev/null 2>&1 || LSRC=$?
[[ $LSRC -eq 2 ]] && echo "absent"

4. Push blocked after rebasing over a peer's overlapping fix

Symptom: git pull --rebase succeeds (possibly after resolving a conflict), but the push is then blocked by the dogfood gate: ❌ Deploy sync, ❌ Script content (<name>), ❌ Checksum: <file>.sh. Your commit looks fine.

A register() source can be SILENTLY UNCOMMITTED by a .gitignore pattern. When a new registered file is missing from a commit, check git check-ignore <src> FIRST: a filename matching a broad rule (*secret*, *token*) makes git add skip it with no error, so the commit lands with only the register line. The doctor then FAILs Deploy source missing: <file> on every host. Fix by renaming the artifact out of the pattern (keeps the guard intact) or adding an explicit !negation; verify it staged with git ls-files <src> before committing. Do not re-implement a peer's in-flight fix to the same artifact without checking git log --all -- <path> and git ls-tree origin/main -- <path> first — if the peer is actively pushing that fix, your re-implementation is a wrong-direction commit you must then revert and push the revert.

Mechanism: the dogfood gate diffs DEPLOYED scripts (~/.steadfaste-fleet/scripts/) against repo HEAD. A peer's overlapping commit changed the same script in the repo; your deployed copy still carries YOUR pre-rebase version → checksum mismatch → gate blocks. The gate compares deploy state, not your diff — your commit is not the problem.

The checksum line may name files you did NOT touch. ❌ Checksum: checks.py / cli.py on a push whose diff touches neither usually means a PEER's merged commit changed them and your host's deploy is stale — not that your diff is wrong. Do not chase the named file; it is correct, just not deployed. Verify with git log --oneline origin/main -1 vs cat ~/.steadfaste-fleet/state/update-commit: tip-ahead-of-deploy confirms the stale-deploy reading, and the fix is the same re-deploy + push below.

Fix: re-run bash ops/scripts/fleet-update.sh (deploys the rebased repo state, including the peer's version), verify the deployed file matches repo (diff <(grep -v '^# SOURCE:' ops/scripts/X.sh) <(grep -v '^# SOURCE:' ~/.steadfaste-fleet/scripts/X.sh)), then push.

Confirm the push actually landed, not just that the command ran: after a re-deploy the push can still be raced — the threat-pipeline cron pushes its own auto-commits between your pull --rebase and your push, so the push is rejected as non-fast-forward. git pull --rebase again and retry; once the push shows A..B main -> main it has landed even if a later line in the same chain printed an earlier failure. Verify with git log --oneline -1 origin/main == your commit before reporting success. Also re-run fleet-update.sh one final time AFTER the push so the deployed tree carries the just-pushed commit — the push gate's internal deploy can trail the newest commit.

Rebase conflict gotcha (2026-09-02): during git pull --rebase, --ours is the UPSTREAM (incoming, peer) version and --theirs is YOUR replayed commit — the opposite of a merge. Taking --theirs on a conflict keeps YOUR version, so your commit still carries a duplicate of a peer's identical fix. To yield to the peer's already-pushed version, use git checkout --ours <file> then git add; verify with git show <sha> -- <file> (should be empty for the duplicated file) before amending. Prefer the peer's version when it is identical-or-better and already public.

Orphaned <<<<<<< HEAD after a hand-resolved conflict: when you resolve a conflict block by keeping only the top side (e.g. a patch whose delete starts at the =======/>>>>>>> boundary), the leading <<<<<<< HEAD line survives as stray text; the marker is NOT auto-removed by clearing the bottom side. The result compiles/passes silently and only shows up as a stray heredoc/test text later. After resolving ANY conflict block, grep -rn '^<<<<<<<\|^=======\|^>>>>>>>' <path> and delete every leftover line before git rebase --continue — a verified zero-marker file is the only safe state. When several files conflict, resolve all of them in one pass, then grep the set clean before continuing.

5. Push blocked by a "PENDING cycles" governance leak (no live lock)

Symptom: the doctor FAILs ❌ PENDING cycles — "N unscored cycle(s) from finished task(s)" — and the pre-push gate blocks every push. The cycles listed are NOT yours; they are sibling/daemon/crashed sessions that called begin_change and never scored. Each has decision='PENDING', user_overrode IS NULL, and its task's .governance-*.json lock is gone.

The two distinct root causes — diagnose before patching:

  1. Malformed-heartbeat locks are pinned "never stale". _is_lock_stale (in loop-gov-mcp.py, purge-stale-governance-locks.py, and the enforcer) previously returned False forever when datetime.fromisoformat raised: a time-only heartbeat (09:12:00Z — no date, fromisoformat needs one) or a naive no-TZ timestamp (aware-vs-naive subtraction raises TypeError). Both were caught and treated as fresh, so the crashed session's lock never aged past TTL and was never purged.
  2. Purge deletes the lock file but leaves the orphaned cycle. The doctor's leak rule is "PENDING cycle whose task_id has NO live lock = FAIL". Removing the lock does NOT clear the cycle — the doctor still FAILs and blocks. Fix as a pair: when a lock is purged as stale, also resolve that task's PENDING cycle(s) to MOVE_ON, and run the purge from begin_change (the acquiring gate) not just _check_lock.

Check the deployed copy matches repo first — diff the deployed ~/.steadfaste-fleet/tools/loop-governance/loop-gov-mcp.py against mcp-servers/loop-gov-mcp.py; the ONLY allowed difference is the injected # SOURCE: / # Do NOT edit header lines. Any other diff (or a running gateway process started before the fix — "deploy ≠ load") means the running code is stale and the fix hasn't loaded.

Same deploy≠load window refuses end_change with a reviewer EXCEPTION, not a clean banner. After deploying a loop-gov change, the RUNNING MCP daemon still executes the old module; a non-trivial close then fails because the in-memory reviewer hits code it does not have yet. The error reads like a reviewer/data bug ('str' object has no attribute 'get') rather than a "restart pending" notice. Recognize the transition window, not a regression: retrying repeats the same error; feedback_accept/close what you can, have the operator restart the gateway, then retry end_change after the restart. A watchdog alert naming "N loop-gov daemon(s) ... running pre-deploy code" is the same condition. The same window also produces a bogus-looking doctor run — re-read the doctor as a bare python3 …fleet-doctor.py AFTER the deploy process exits, and do not chase warns/fails captured mid-deploy.

Hermetic repro for a purge fix (no real state touched): repoint the module's GOVERNANCE_STATE_DIR / LOOP_DB at a temp dir, write a stale time-only-heartbeat lock, seed a PENDING cycle for its task, run _purge_stale_locks(), assert the lock is gone AND the cycle flipped to MOVE_ON. Proving the cycle resolution is what unblocks the gate — deleting the lock alone demonstrably does not.

6. Push blocked by "❌ Review provenance" — an unbacked recorded-in claim

Symptom: the doctor FAILs ❌ Review provenance naming a docs/evidence file that presents itself as a recorded review, and the pre-push gate blocks every push on the host — regardless of how unrelated your diff is.

Mechanism: check_review_provenance (fleet_doctor) shells out to ops/scripts/quality/review-provenance-check.py, which scans every text file under docs/ for a recorded-in: adversarial_reviews review_id=… CLAIM in its header. A claim is verified against the host's LOCAL loop-governance DB (~/.steadfaste-fleet/data/loop-governance.db); if no row carries that id, the file is an unbacked claim → FAIL. A review row lives on the host where adversarial-review.py --cycle-id N --review RAN, so a docs file committed to the shared repo carries a claim only one host can truthfully verify — every other host FAILs on it. It is often another session's (or a merged upstream's) artifact, not yours — but it still blocks you, and you own it.

Verify before touching it (never mark an unbacked claim as if it were verifiable):

sqlite3 ~/.steadfaste-fleet/data/loop-governance.db \
  "SELECT review_id, cycle_id FROM adversarial_reviews WHERE review_id LIKE '<id>%';"

A query with rows = the claim is valid on this host; empty = the row is elsewhere or fabricated. Then run the checker standalone to see the enumeration and the offending line:

~/.steadfaste-fleet/venv/bin/python3 ops/scripts/quality/review-provenance-check.py --repo .

Legal fixes (the checker accepts exactly these; both are exact strings — check_review_provenance matches the literal constant, so a trailing explanation on the declaration line breaks the match and re-FAILs):

  • > \provenance: advisory`` at the top of the file — truthful when the row is not verifiable on this host; move any explanation of WHY to the body below the declaration, never on the declaration line.
  • > \provenance: not-a-review`— for a model-named header that is not a review at all. Do NOT graft arecorded-in` id that does not exist in the local store just to satisfy the gate — that makes the file a fabricated claim and is the exact defect the check exists to stop. Say plainly in the note whether the row is present or absent.

7. Push blocked by the REVIEW RECEIPT gate — and the deploy it then demands

Symptom: ❌ Push blocked: this range touches an always-review path and carries no clean review receipt. followed by Expected receipt: <state>/.reviewed-<slug>-<tip>.json.

Mechanism: the receipt is written by the GOVERNANCE SERVER at a PERMITTED close (end_change → review gate → _write_review_receipt), never by ops/scripts/orch-bus/adversarial-review.py (which only records an LLM verdict row). So the order is close, then push — backwards from intuition, and by design: the review that used to land after the push now gates it.

  • The per-blob pass has a budget (~15 blobs / 240s per close) and verdicts are keyed by blob CONTENT. A partial close is RESUMED by calling end_change again — it says "closing again continues from here" — so on a multi-file range expect 2-3 calls rather than one. Fixing a file after a FINDINGS verdict produces a NEW blob, judged on its own; re-close after every commit.
  • The receipt is bound to the RANGE (base…tip), but the gate also accepts ANY receipt whose reviewed_blobs cover every file the range changes — which is how a rebase that rewrote the tip can still push.
  • adversarial_reviews has one row per cycle. A second --review for the same --cycle-id answers "already reviewed (UNIQUE constraint)" and does NOT re-judge; a fresh judgement needs rereview_change (opens the cycle's verdict again, requires a note stating what changed plus its evidence). Read the recorded row (verdict + findings_json) from ~/.steadfaste-fleet/data/loop-governance.db — note this is NOT state/loop-governance.db.
  • A review whose material was a PATH, not content, returns a hollow CLEAN — the reviewer reports unverified-claim on the path itself ("the window contains only this path"). Pass the plan/diff CONTENT as material, and treat a CLEAN that names an unreadable window as no approval at all.
  • Push as a LONE git push. The enforcer refuses a compound push (git push && git rev-parse …, git push | tail, cd X && git push) because it cannot prove the shape; a CLEAN receipt can authorise a push with no active lock, but only for the bare command. Verify in a separate call.

The deploy chicken-and-egg — use a lock-carrier cycle, never an override. The push gate also requires a doctor-clean DEPLOYED state, while the deploy (fleet-dogfood.sh) is a WRITE-class command that itself needs a repo lock. Once you have closed the cycle, the lock is gone and the deploy is blocked, so the two gates appear to deadlock. The sanctioned exit is a deploy-only cycle:

begin_change(task_id="deploy-<thing>",
             description="Lock-carrier cycle for a DEPLOY-ONLY action: deploy and push the "
                         "already-reviewed range <sha> (cycle N, closed CLEAN with a receipt). "
                         "No source change is made on this cycle.")
# then: dogfood --force → lone `git push` → feedback_accept → end_change

State plainly in the description that no source changes — that is what the cycle's own review needs to agree with — and expect the close to warn receipt NOT written … lists no files once the range is already pushed (benign: an empty range has nothing to authorise).

Verification checklist

  • [ ] stat the update-commit mtime before debugging your diff
  • [ ] bash -x the deploy to find the dying step (don't trust the log tail)
  • [ ] Test the hook with a 4-case scratch matrix: first push → ALLOW; normal push → PASS; fetch fails + ref exists → BLOCK; remote unreachable → BLOCK
  • [ ] A4 adversarial gate on hook/deploy changes before commit

Fleet-shared vs local- (user preference, workflow decision)

Decide by who needs the artifact, NOT by what dodges a doctor warning. A genuinely fleet-useful artifact (a gate backend, a reviewer wrapper, a shared helper) belongs FLEET-SHARED in the repo with a proper register() entry, then deploy + push. Renaming it to local- purely to clear a doctor stale-deploy warning is backwards — the answer to a genuine fleet need is to register and deploy it, not hide it as a one-off. local- is for one-off, host-specific things only. Ask "would another host want this?" — if yes, make it fleet-shared. The user: "if it isn't fleet shared, then what's the point?" (respond in kind, not by dodging the warning).

Public-repo publishing discipline (user preference, 2026-09-01)

When creating a PUBLIC repo (e.g. the omarchy-omar project), the user's hard rule: zero PII — no real usernames, hostnames, LAN/WAN IPs, domains, phone/email, bot or session identifiers, machine serials. Public repos are crawled; a leaked identifier is permanent. Practice:

  • Use placeholders everywhere: YOURUSER, 192.168.1.x, example.com, mymac. Configs are templates for strangers to copy, never live values.
  • Before pushing, grep the whole tree: grep -rniE '192\.168|<realhost>|<realdomain>|<chat-id>' . → clean. (Never paste a REAL identifier into the pattern — this line used to carry one, which is the exact leak it warns about.)
  • Audit doc cross-references resolve (](path) from each file's own dir); broken links fail the repo's own QA.
  • Scripts ship with a --check mode and pass bash -n before commit.

Related

  • references/fine-grained-pat-capabilities.md — fine-grained GitHub PAT format, create/push permission gaps (Administration vs Contents), and the browser-created-repo unblock.
  • shared-repo-push-gates (sibling) — gate catalog + concurrent-session discipline; this skill is the diagnosis playbook for when a gate blocks.

04 同仓库更多 Skills