Skip to content

git backup pushes but never pulls, and a rejected push is reported as if it will retry #253

Closed

Description

@jqit-ricky

What I ran into

I use external data_dir mode with a private backup repo, from more than one machine. After about three weeks one machine had drifted to 15 commits ahead and 312 behind, missing twelve days of memory it had never seen. Nothing in the logs said anything was wrong.

Two separate things caused that. I think the first matters even if you never want the second.

1. A rejected push is reported as transient

hooks.d/after_save/50-git-backup.sh funnels every push failure into one message:

log "git-backup" "push deferred (will retry next backup)"

That is accurate for a network blip. It is not accurate for a non-fast-forward rejection, which is what you get once the remote has moved ahead. That push cannot succeed on any later attempt, so the message promises something that will not happen, and the backup has in fact stopped.

My logs show 15 push deferred against 8 pushed, and the store never recovered on its own. I only found it because I went looking.

This is a backup integrity problem on its own terms, separate from anything to do with multiple machines. I believed memory was being backed up and it had not been for weeks.

The codebase already draws this exact distinction elsewhere. save-session.sh carries SPAWN_DECLINED_EXIT=3 with a comment that declined and failed "must not be conflated", and haiku.py's _log_failed_spend says "'unknown' is the honest answer when the payload carries no usage. Zero is not." A rejected push is the same shape of problem.

There is also a delivery channel already built for it. session-start-hook.sh writes tmp/capture-gap-notice, and user-prompt-hook.sh renders it as systemMessage with the comment that systemMessage "is the only hook output the HUMAN sees, and a notice only the model sees is how this stayed invisible for a day in the first place." A store that can no longer push is the same class of thing.

2. There is no restore counterpart

The plugin never reads from the remote. Grepping 0.10.0 for git pull, fetch, merge and rebase outside tests/ returns nothing.

The feature is called backup and the README frames it as backup, so this part is a feature request rather than a complaint. But once memory lives in a shared remote and gets used from a second machine, one-way push does more than fail to sync. The second machine reads stale local memory, commits on top of it, and from then on can never push at all.

hooks.d/before_session_start/ already exists, is already dispatched at session-start-hook.sh:86, and ships empty. A 50-git-restore.sh there would mirror after_save/50-git-backup.sh.

What would help:

  • fetch, then fast-forward only when the local branch is cleanly behind
  • config-gated and default off, so nothing changes for existing installs
  • refuse to touch a diverged store, and say so

What I am not asking for

Please do not auto-merge or auto-rebase. recent.md and archive.md are rewritten wholesale by consolidation rather than appended, so a conflict there is real and a wrong resolution corrupts memory silently. Refusing and reporting is the right behaviour.

Environment

remember 0.10.0, Windows 11, Git Bash, external data_dir with {slug}, private backup repo.

Activity

  1. fdaviddpt commented on Jul 31, 2026

    @fdaviddpt
    Contributor

    Part 1 is fixed and merged (#256). Part 2 is still open, deliberately — details below. Leaving this issue open for it.

    Thank you for the report. Two things in it did most of the work:

    • You separated the two problems yourself, and you were right that the first matters even if the second never happens. That framing is why part 1 could be built and reviewed on its own terms today rather than waiting on a design decision.
    • You cited the codebase's own precedents back at us — SPAWN_DECLINED_EXIT=3, _log_failed_spend's "'unknown' is the honest answer", and the capture-gap-notice → systemMessage channel. I checked all three; they are exactly where you said, and the systemMessage comment at user-prompt-hook.sh:93 ("a notice only the model sees is how this stayed invisible for a day in the first place") turned out to be the right argument for where this belongs too.

    What changed

    A permanent rejection is no longer reported as a transient deferral. The three push deferred (will retry next backup) sites — :222, :234, :244 — now share one classifier.

    The classification comes from git push --porcelain, not from the message text. The safety property that makes this work is the asymmetry you would want: an unreachable remote exits 128 with completely empty stdout, so a transient failure gives git nothing to say and falls through to the unchanged quiet deferral. Reporting loudly requires positive evidence from git — a !-flagged ref line. It cannot fire on a network blip.

    That parse is deliberately strict, because a pre-push hook writes to the same streams and we confirmed it can inject a convincing fake: rc must be non-zero, only lines after git's own To <url> header count, and a line must have exactly three tab-delimited fields with ! in the first. A test runs a real pre-push hook printing "rejected — non-fast-forward, fetch first" on both streams and asserts the push still reports pushed.

    Three states now, not two: pushed / deferred, will retry / rejected, the backup has stopped. The third carries git's own rejection text, says the commit exists on this machine only, and says plainly that nothing will fetch, merge or rebase on your behalf.

    On the surface: log line always, and systemMessage after 3 consecutive rejections (git_backup.reject_notice_after, 0 disables). Escalation rather than first-occurrence because that channel is the most intrusive one in the codebase and overusing it destroys its value — and it costs nothing here, because a rejection never clears itself, so a threshold can only postpone a true report, never swallow one.

    Your "what I am not asking for" was followed exactly. Nothing auto-merges or auto-rebases, and there is now a structural test that fails if fetch, pull, merge or rebase ever appears in that file. Your reasoning — that recent.md and archive.md are rewritten wholesale by consolidation, so a conflict there is real and a wrong resolution corrupts memory silently — is correct and is now the documented constraint.

    Part 2, honestly

    The restore counterpart is a feature, not a defect, and it is the maintainer's decision rather than mine to take unilaterally. Your specification is the one I would build from if it goes ahead: fetch, fast-forward only when cleanly behind, config-gated and default off, refuse a diverged store and say so. hooks.d/before_session_start/ does exist, is dispatched at session-start-hook.sh:86, and does ship empty — I verified that, and that git pull|fetch|merge|rebase appears nowhere outside tests/.

    This issue stays open for it. The PR says Part of #253, not Closes.

    Delivery

    None of this is on your machine yet — it is on main and not in a release. A fix that has not reached your install is not a fix, and we have been caught by exactly that here before. I will follow up on this issue when it ships.

  2. fdaviddpt commented on Jul 31, 2026

    @fdaviddpt
    Contributor

    Both halves shipped in v0.12.0 — on your machine's next plugin update, not just on main. FORCE_AUTOUPDATE_PLUGINS=1 on a session start moves a stale cache immediately; the manifest inside the install (.claude-plugin/plugin.json) should read 0.12.0.

    Part 1 — a non-fast-forward rejection is no longer reported as push deferred (will retry next backup). It says the backup has STOPPED, carries git's own rejection text, and after three consecutive rejections it reaches you through systemMessage rather than only the log.

    Part 2 — restore exists, opt-in, git_restore.enabled (default false). Fetch is detached so nothing network-shaped sits in front of your first prompt; the fast-forward is local, using refs an earlier session already fetched. Fast-forward only. A diverged store is refused with both counts named, and a structural test fails the build if merge, rebase, reset or checkout -f ever appear in that file — your constraint, now enforced by CI rather than by intention.

    Two things worth having, since you'll be the first person to run this against a real two-machine setup:

    A bug your issue caused us to find, and CI caught before release. The detached fetch inherited the backup lock — _take_lock holds its flock on fd 9, a forked child inherits every descriptor, and an inherited fd holds the same lock. On Linux that meant the fetch held the whole store locked for its lifetime, so every session start in that window skipped its fast-forward and any after_save backup landing in it was blocked. Invisible on macOS, which ships no flock(1) and takes a different path. Fixed, and the Linux branch is now executable on the maintainers' machines so it can't hide again.

    Known, unfixed, and relevant to you: a store reached through a symlink gets no backup and no restore, with nothing in any log — the hooks compare the store path textually against a resolved git rev-parse --show-toplevel (#260). If your data_dir traverses a symlink anywhere, that will bite before anything else does. Also #257: a failed commit is log-only, so memory may not be committed even locally.

    Thanks for splitting the report the way you did. Part 1 could be built, reviewed and shipped on its own terms today precisely because you separated it from the feature — and your "please do not auto-merge or auto-rebase" is now the documented constraint in the code, with the recent.md/archive.md reasoning attached.

  3. added 5 commits that reference this issue on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions