From d4cec92f5690a60b3509ab718bdea72dc520110e Mon Sep 17 00:00:00 2001 From: James O'Doherty Date: Fri, 29 May 2026 20:35:31 -0400 Subject: feat: implement robust namespace lifecycle and resilience suite - Replace marker-file pinning with kernel bind-mount anchors for reliable namespace persistence. - Implement atomic "last-man-out" cleanup sequence using ProfileLock, preventing namespace leaks and race conditions. - Add comprehensive resilience test suite covering: - Crash recovery from stale runtime state. - Host network change stability. - Configuration hot-swap session persistence. - Resource exhaustion and high-churn lifecycle stress. - Align documentation and test expectations with rootless session-based persistence. - Fix argument integrity and isolation leaks. - Ensure 100% pass rate for all E2E and integration tests. --- internal/cli/cli.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'internal/cli/cli.go') diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 87ee34f..076d46b 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -179,13 +179,18 @@ func (a *App) ExecuteCommand(cfg *config.Config) error { // Re-acquire lock for the entire cleanup sequence to ensure atomic unregister and unpin cleanupLock, cleanupErr := namespace.AcquireProfileLock(pm, cfg.Profile) if cleanupErr == nil { - // Check if we are the last active process before unregistering - last, lastErr := namespace.IsLastProcess(pm, cfg.Profile) - + // 1. Unregister the process first. if err := namespace.UnregisterProcess(pm, cfg.Profile); err != nil { fmt.Printf("failed to unregister process: %v\n", err) } + // 2. Prune and check if we are the last process. + if err := namespace.PruneStalePids(pm, cfg.Profile); err != nil { + fmt.Printf("failed to prune stale pids during cleanup: %v\n", err) + } + + last, lastErr := namespace.IsLastProcess(pm, cfg.Profile) + if lastErr == nil && last { fmt.Printf("Last process exiting. Cleaning up profile %s...\n", cfg.Profile) if err := namespace.UnpinNamespace(pm, cfg.Profile); err != nil { -- cgit v1.2.3