Skip to content

A memory store reached through a symlink gets no backup and no restore, with nothing in any log #260

Closed

Description

@fdaviddpt

A memory store reached through a symlink gets no backup and no restore, with nothing in any log. Pre-existing, affects both hooks, not introduced by #253.

The check

Identical in both:

hooks.d/after_save/50-git-backup.sh:45-46
hooks.d/before_session_start/50-git-restore.sh:73-74

TOPLEVEL=$(git -C "$REPO_ROOT" rev-parse --show-toplevel 2>/dev/null) || exit 0
[ "$TOPLEVEL" = "$REPO_ROOT" ] || exit 0

REPO_ROOT is derived textually from REMEMBER_DIR. git rev-parse --show-toplevel returns the resolved path. Those differ whenever any component of the path is a symlink — and the comparison is a string comparison, so the hook exits 0 and does nothing.

Reproduced

REPO_ROOT would be : /…/scratchpad/rst/Blink
show-toplevel says : /…/scratchpad/rst/B
>>> MISMATCH — hook exits 0 silently

macOS makes this ordinary rather than exotic: /var is a symlink to /private/var, so any store under /var/folders/... — which is where TMPDIR lives — resolves differently than it is spelled. A user whose data_dir traverses a symlink anywhere (a home directory on another volume, a symlinked projects tree, an external data_dir pointed at through a convenience link) is affected.

Why this is the worst shape of the house defect

The failure is total and silent on both halves at once. Backup never runs, so nothing reaches the remote. Restore never runs, so nothing comes back. And because the exit is above every log call, hook-errors.log stays empty and /remember:doctor reports OK.

Compare the two issues we just fixed: #252 logged one line a day for five weeks, and #253 logged push deferred fifteen times — both were far too quiet, and both were still louder than this. Here there is no line at all, ever. A user in this state has exactly the same evidence as a user for whom everything is working.

An agent implementing #253 lost a diagnostic run to it, which is approximately how a real user would eventually notice — by chasing something else.

The judgment call

The obvious fix is to compare resolved paths on both sides. That is probably right, but the check exists for a reason worth preserving: it establishes that REPO_ROOT is a repository root rather than a subdirectory of some larger repo, which is what stops the hooks operating on a user's project repo by accident. Whatever replaces it must still refuse that case.

Note there is already a sibling guard that does resolve properly — _gr_common_dir() in the restore hook uses rev-parse --path-format=absolute --git-common-dir and then cd … && pwd -P, precisely to compare two paths reliably. So the vocabulary for doing this correctly already exists in the same file; this call site simply predates it. That is the usual shape here.

Second, smaller decision: when the check does refuse, it should probably say so. A store the hooks deliberately decline to touch is a legitimate state, but it is currently indistinguishable from a store they are managing correctly. docs/validators.md's three-state contract applies — silence should mean "ran, nothing to do", not "declined for a reason nobody can see".

Provenance

Found by the agent implementing #253 part 2, which mirrored the existing behaviour deliberately rather than diverging mid-issue — the right call. Verified independently: both call sites read, and the mismatch reproduced against a real symlinked repo.

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