Skip to content

fix(pm-git-sync): move empty rebuild markers aside instead of stalling - #12515

Merged
dezren39 merged 2 commits into
mainfrom
claude/pm-git-sync-markers
Nov 22, 2026
Merged

dezren39 merged 2 commits into
mainfrom
claude/pm-git-sync-markers

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Why

On 2026-11-22 the laptop's checkout stopped following main for two hours: 28 merges were not deployed, and nothing said so. A system rebuild had left an empty marker commit (amd 569) on the clone's main; origin/main had moved as well, so the clone was ahead and behind at once, and pm-git-sync only ever fast-forwards. It was unstuck by hand (the marker kept under a tag, main moved to origin/main), the same repair as #2496.

Every rebuild leaves such a marker (lib/rebuild-*.sh), and with merges landing all day the clone is almost always behind by the time it does. So this recurs.

What changes

pm-git-sync now does that repair itself, only in the case where nothing can be lost:

  • If the clone is ahead and behind, and every commit only it has is empty and not a merge, each is kept under a tag rebuild-marker/<subject> (its own short hash if that name is taken by another commit) and main is moved to origin/main with git reset --keep.
  • A local commit that changes a file, or a merge, still fails loudly. The check runs over all local commits before the first tag is written, so a refusal moves and tags nothing.
  • A marker that blocks nothing (origin has not moved) is left where it is; the hourly keeper pushes it, as before.

Checks

  • New suite pm-git-sync-markers.test.sh (added to pm-stack-tests.yml): ahead only; two markers with origin moved; a name already taken; a subject that is not a valid ref name; a commit with a file change beside an empty one; a local merge.
  • Seven planted faults in the new branch (empty check dropped, merge check dropped, tag overwritten, moved when only ahead, no tag written, main not moved, refusal after tagging): each caught.
  • The existing quarantine suite still passes. shfmt, shellcheck clean.

Takes effect

At the next system rebuild: the unit runs the packaged copy (pkgs/pm-git-sync, now 0.3.0). That rebuild's own marker is the first one the new copy will meet.


Generated by Claude Code


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • New Features
    • Git sync now handles local, empty rebuild-marker commits when the remote branch has advanced, preserving them as markers while bringing the branch up to date.
  • Bug Fixes
    • Sync stops without changing repository state when local-only commits contain file changes or are merge commits, rather than treating them as rebuild markers.

A system rebuild leaves an empty "<host> <generation>" commit on the
laptop clone's main and does not push it. Once origin has moved too,
main is ahead and behind at once and the fast-forward-only sync can
never pull again: on 2026-11-22 the laptop sat two hours and 28 merges
behind with nothing deployed.

When every commit only the clone has is empty and not a merge, each is
kept under a tag rebuild-marker/<subject> and main is moved to
origin/main. A local commit that changes a file, or a merge, still
fails loudly and nothing is tagged or moved. A marker that blocks
nothing (origin unmoved) is left for the hourly keeper to push.

Seven planted faults in the new branch are each caught by the new
suite. Takes effect at the next system rebuild: the unit runs the
packaged copy.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 11:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T11:59:26.122416Z 4ec6de7 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.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

When main has diverged from origin/main, the sync script checks local-only commits. It tags commits that are single-parent and have unchanged trees, then moves main to origin/main. A Bash test suite covers this behavior and runs in the workflow.

Changes: Git sync rebuild markers

Layer / File(s) Summary
Validate and preserve rebuild markers
pm-stack/scripts/pm-git-sync.sh, pkgs/pm-git-sync/package.nix
The script validates local-only commits before creating tags. It refuses merges and commits that change files. For eligible commits, it creates rebuild-marker/ tags and resets main to origin/main. The package version changes from 0.2.0 to 0.3.0.
Test and run marker handling
pm-stack/scripts/pm-git-sync-markers.test.sh, .github/workflows/pm-stack-tests.yml
The test suite checks marker handling, tag collisions, unusual subjects, refusal cases, and repository state. The workflow runs the suite.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Sync as pm-git-sync.sh
  participant Local as Local Git repository
  participant Origin as origin/main
  Sync->>Local: Inspect local-only commits
  Local-->>Sync: Commit parents and tree state
  Sync->>Local: Create tags for eligible commits
  Sync->>Local: Reset main to origin/main
  Origin-->>Local: Provide origin/main target
Loading

Suggested reviewers: claude

Merge Risk: Low · up to c3725

The change lets pm-git-sync move empty rebuild-marker commits aside under tags instead of stalling when main has diverged from origin/main. In a narrow case, where a fallback tag name is already taken by a different commit, the script overwrites that tag and the earlier marker loses its preservation reference. The loss is limited to empty marker commits, so the change is mergeable with owner awareness. A small guard before writing the fallback tag would remove the gap.

- [ ] 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

@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: c37256b495

ℹ️ 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".

echo "pm-git-sync: kept empty commit $(git log -1 --format='%h "%s"' "$commit") under tag $tag"
done < <(git rev-list --reverse origin/main..HEAD)
# --keep refuses to touch a file with local changes; there are none.
if ! git reset --quiet --keep origin/main || [ "$(git rev-parse HEAD)" != "$remote" ]; 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.

P2 Badge Guard the reset against a concurrently changed HEAD

If a rebuild commits to this checkout after the validation and tagging snapshots, this reset removes the new commit from main without checking or preserving it. This can overlap with normal operation: nixos/services/pm-stack/default.nix:597–602 schedules sync every 30 seconds, while lib/rebuild-simple-script.sh:31 commits in the checkout without coordination. A completed commit leaves clean files, so --keep does not protect it (git reset -h describes it as “reset HEAD but keep local changes”); the previous pull --ff-only would instead refuse the divergence. Coordinate with writers or atomically ensure that the branch being replaced still points to the validated commit before moving it.

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.

Real, and worth closing even though the window is short. Fixed in the next commit: main is moved only if it is still where it was when its commits were examined (otherwise nothing is moved and the next run looks again), and a commit that lands between that look and the move is kept under rebuild-marker/unexpected-<hash> with a loud failure, so it is never left reachable only from the reflog. Both windows are tested with a stand-in git that commits mid-run; three planted faults in the guard are each caught.


Generated by Claude Code

A rebuild commits in the checkout without coordinating with the sync.
Main is now moved only if it is still where it was when its commits
were examined, and a commit that lands in the instant between that look
and the move is kept under a tag and reported, instead of being left
reachable only from the reflog.

Both windows are tested with a stand-in git that commits mid-run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF
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.

2 participants