fix: preserve existing EXIT trap from ides shellHook#2
Open
wanderer wants to merge 5 commits into
Open
Conversation
The ides shellHook sets `trap _ides_leave EXIT` which clobbers any existing EXIT trap. This breaks direnv (and any other tool that relies on EXIT traps) because direnv uses its EXIT trap to capture the environment state after .envrc finishes. With the trap overridden, direnv captures nothing — no PATH, no env vars — making the nix dev shell invisible. Fix: save the existing EXIT trap before setting ours, and chain to it from a wrapper function. Closes manic-systems#1
When ides' shellHook runs inside direnv, the bash subprocess that evaluates .envrc exits immediately after evaluation. This causes the EXIT trap to fire, releasing the lease and stopping all services. Fix: detect direnv via DIRENV_DIR/DIRENV_DIFF env vars. When detected: 1. Walk up the process tree (bash → direnv → real shell) to find the user's actual shell PID for the lease, so the lease stays alive. 2. Skip the EXIT-trap lease cleanup — the daemon's prune_dead will release the lease and stop services when the real shell exits. 3. Still chain to any existing EXIT trap (e.g. direnv's env capture). In normal (non-direnv) shells, behavior is unchanged.
ides enter can fail on first run when the daemon is still starting up (connection reset). Add retry logic (5 attempts, 200ms apart). Also, don't exit the shell if ides enter ultimately fails — just skip lease management. The user can run `ides run` manually.
The daemon's serve() loop checks if active==0 && pruned>0 to detect when all shells have exited (pruned dead leases → stop services → exit). But on startup, stale lease files from previous runs would trigger this condition immediately, causing the daemon to call systemd::down() and exit before any client could connect. Fix: skip the prune-and-exit check on the first iteration. The daemon will still exit after 10 seconds of idle time if no leases are created.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ides shellHook sets
trap _ides_leave EXITwhich clobbers any existing EXIT trap. This breaks direnv (and potentially other tools that rely on EXIT traps) because direnv uses its EXIT trap to capture the environment state after.envrcfinishes executing. With the trap overridden, direnv captures nothing — noPATH, no env vars — making the nix dev shell completely invisible to the shell.Closes #1.