Skip to content

fix: restart sandbox when gpg-agent restarts after macOS sleep/reboot - #34

Merged
malaporte merged 1 commit into
mainfrom
missing-gpg-agent
Apr 15, 2026
Merged

malaporte merged 1 commit into
mainfrom
missing-gpg-agent

Conversation

@malaporte

Copy link
Copy Markdown
Owner

Summary

GPG commit signing inside the sandbox would occasionally fail with No agent running after the host gpg-agent restarted (e.g. after macOS sleep/wake, screen lock, or reboot). This fixes two related bugs in resolveGpgSocketInfo.

Changes

  • Fix auto-start command: Replace gpg-agent --daemon with gpgconf --launch gpg-agent when the agent socket is missing at sandbox start time. On macOS the agent is managed by launchd; using gpg-agent --daemon directly can spawn a conflicting second instance or fail silently. gpgconf --launch is the correct cross-platform way to ensure the agent is running.

  • Fix stale socket detection: Include the socket inode in the config fingerprint (agent-extra-socket:/path/to/socket:<inode>). Previously only the path was included, so when gpg-agent restarted and recreated the socket at the same path (new inode), the fingerprint was unchanged and the sandbox kept the old dead bind-mount. Now a restarted agent produces a different fingerprint, triggering a transparent sandbox restart with the fresh socket.

Testing

Tested end-to-end on macOS/Docker Desktop:

  1. Confirmed GPG signing works in a running sandbox.
  2. Killed the host gpg-agent (gpgconf --kill gpg-agent) to simulate a sleep/wake cycle.
  3. Ran pippin -c 'echo test | gpg --clearsign' — observed:
    • pippin: started gpg-agent (auto-start via gpgconf --launch)
    • pippin: sandbox configuration changed, restarting... (inode change detected)
    • GPG signing succeeded in the restarted sandbox with the fresh socket mounted.
  4. All 139 unit tests pass, typecheck clean.

Reviewer Notes

The inode-based fingerprint means every gpg-agent restart will trigger a sandbox restart. This is intentional and correct — the old container has a dead socket bind-mount and must be replaced. The restart is transparent to the user (same behaviour as a config change).

- Replace gpg-agent --daemon with gpgconf --launch gpg-agent for correct
  macOS agent startup (avoids spawning a conflicting second instance)
- Include socket inode in config fingerprint so that when the host gpg-agent
  restarts (new socket inode, same path), the config hash changes and the
  sandbox is transparently restarted with the fresh socket mounted
@malaporte
malaporte marked this pull request as ready for review April 15, 2026 08:05
@malaporte
malaporte merged commit 6d986db into main Apr 15, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.21.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant