Skip to content

fix(pm-stack): pm-git-sync owed redeploys — abort restart on dep failure, retry until success (#2391) - #2860

Merged
dezren39 merged 2 commits into
mainfrom
queue/3977-2391-pm-git-sync-owed
Oct 30, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/3977-2391-pm-git-sync-owed

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #2391 (queue task 3977).

Problem

pm-git-sync.sh lost redeploy failures twice: a failed dependency step only printed WARN and the service was restarted anyway onto code whose deps were never installed; and redeploys were computed only from the old..new diff in the run where HEAD moved, so a failed redeploy was never retried and nothing recorded that one was owed — the script exited 0 throughout.

Change (pm-stack/scripts/pm-git-sync.sh)

  • A service's dependency step failing now aborts that service's restart for the run.
  • Failed dep steps and failed restarts are recorded as owed redeploys in a durable state dir (PM_GIT_SYNC_STATE_DIR, default ${XDG_STATE_HOME:-~/.local/state}/pm-git-sync, one record per unit: subtree + dep step).
  • Every run retries owed redeploys, including old==new runs, until dep step + restart succeed; success clears the record.
  • While any redeploy is owed, the run ends with a FAIL journal line naming the units and a non-zero exit — no more silent WARN + exit 0.
  • New PM_GIT_SYNC_SYSTEMCTL env seam (mirrors the existing PM_GIT_SYNC_REPO/PM_GIT_SYNC_BUN seams) so the restart path is stub-able in tests.
  • Unchanged: dirty/off-main fail-loudly rules, pull logic, subtree-diff gating, and per-service dep-step selection (aggregator bun install on package.json/bun.lock change, projector setup-deps.sh on package.json change, dispatch plain restart).

Tests

New harness pm-stack/scripts/pm-git-sync.test.sh (stubbed git origin/clone + systemctl/bun seams), 18 checks, all passing on the laptop:

  • dep step fails → aggregator NOT restarted, owed record exists, run exits non-zero
  • next run with HEAD unmoved retries the dep step; still failing → still owed, still no restart
  • dep recovers → retry restarts the unit, owed record cleared, exit 0
  • restart itself fails → owed recorded; next old==new run retries and clears it

shellcheck -S warning clean on both scripts.

🤖 Queue worker lane E, task 3977


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…ure, retry until success (#2391)

A failed dependency step no longer falls through to a restart: the
redeploy is recorded in a durable state dir (PM_GIT_SYNC_STATE_DIR,
default ~/.local/state/pm-git-sync) and retried on every run,
including old==new runs, until dep step + restart succeed. Failed
restarts are owed the same way. While any redeploy is owed the run
exits non-zero with a FAIL line instead of a silent WARN + exit 0.
Adds PM_GIT_SYNC_SYSTEMCTL seam and a stubbed harness
(pm-git-sync.test.sh, 18 checks) covering dep-fail/retry/recovery
and restart-fail/retry paths.
@dezren39
dezren39 requested a review from a team as a code owner October 30, 2026 23:15
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 27b4357d-0b15-4bc9-b3ad-c136a8e3acc7
Commits

Reviewing files that changed from the base of the PR and between 0744857 and 6d52033.

Files selected for processing: 2
  • pm-stack/scripts/pm-git-sync.sh
  • pm-stack/scripts/pm-git-sync.test.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T23:23:19.513650Z 6d52033 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf1d2e878b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +77 to +79
local subtree="$1" unit="$2" dep="$3"
ATTEMPTED="$ATTEMPTED$unit "
if [ -n "$dep" ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve owed dependency steps when newer source changes arrive

If an aggregator dependency update fails and the next pull changes only aggregator source files, the newly computed dependency step is empty. This attempt then skips the previously owed install, restarts the service, and clears its owed record despite the unresolved dependency failure; the projector has the same problem. Reproducing this with the test fixture produced exit 0 and removed the owed record while the Bun failure marker was still present. Merge any persisted dependency obligation into the new redeploy attempt before restarting.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6d52033: attempt_redeploy now merges a persisted dependency obligation into the unit's next attempt — when the newly computed dep step is empty but an owed record exists, the owed dep step is loaded from the record and must succeed before any restart, and the record is only cleared by a fully successful attempt. Harness scenario 2b reproduces exactly your case (dep-fail owed, then a source-only aggregator pull with the failure marker still present): dep step is attempted, no restart occurs, owed record survives, exit non-zero. 23/23 harness checks pass.

Comment on lines +59 to +61
record_owed() { # <unit> <subtree> <dep-step-or-empty>
mkdir -p "$STATE_DIR"
printf '%s\n%s\n' "$2" "$3" >"$(owed_file "$1")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate failures to persist owed redeploys

If the state directory cannot be created or its record cannot be written, a failed redeploy is still discarded: callers suppress the failure from attempt_redeploy, and finish determines success solely by finding owed files. With a state path that cannot be created, a failed dependency install therefore produces exit 0 and a 'redeploys complete' message, and subsequent unchanged-HEAD runs never retry it. Check persistence failures and propagate them to the final exit status rather than treating an absent record as successful deployment.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6d52033: record_owed now returns failure when the state dir cannot be created or the record cannot be written; both failure branches in attempt_redeploy set OWED_PERSIST_FAILED, and finish exits non-zero with a FAIL line when it is set — an absent record no longer reads as a successful deployment. Harness scenario 5 drives a failed redeploy with the state dir under a regular file (uncreatable): the run exits non-zero. 23/23 harness checks pass.

…rsistable owed records (#2391)

Codex review on PR 2860, both findings fixed:
- P1: a persisted dependency obligation is merged into the units next
  redeploy attempt, so a source-only pull no longer restarts past a
  still-unresolved dep install or clears its owed record.
- P2: record_owed failures propagate via OWED_PERSIST_FAILED and fail
  the run in finish — an absent record no longer reads as success.
Harness gains scenario 2b (source-only pull vs owed dep) and
scenario 5 (unusable state dir); 23 checks pass, shellcheck clean.
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.

fix(pm-stack): pm-git-sync (PR #1526) restarts a service after its dependency step fails, and a failed redeploy is never retried

1 participant