{"record":{"id":"247d83272d177b95","repo":"atuinsh/atuin","slug":"atuin-running-with-no-parent","errorCode":null,"errorMessage":"Atuin running with no parent!","messagePattern":"Atuin running with no parent!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/atuin-common/src/shell.rs","lineNumber":48,"sourceCode":"pub enum ShellError {\n    #[error(\"shell not supported\")]\n    NotSupported,\n\n    #[error(\"failed to execute shell command: {0}\")]\n    ExecError(String),\n}\n\nimpl Shell {\n    #[must_use]\n    pub fn current() -> Self {\n        let sys = System::new_all();\n\n        let process = sys\n            .process(get_current_pid().expect(\"Failed to get current PID\"))\n            .expect(\"Process with current pid does not exist\");\n\n        let parent = sys\n            .process(process.parent().expect(\"Atuin running with no parent!\"))\n            .expect(\"Process with parent pid does not exist\");\n\n        let shell = parent.name().to_string_lossy().trim().to_lowercase();\n        let shell = shell.strip_prefix('-').unwrap_or(&shell);\n\n        Self::from_string(shell)\n    }\n\n    #[must_use]\n    pub fn from_env() -> Self {\n        std::env::var(\"ATUIN_SHELL\")\n            .map_or(Self::Unknown, |shell| Self::from_string(&shell.trim().to_lowercase()))\n    }\n\n    #[must_use]\n    pub fn config_file(&self) -> Option<std::path::PathBuf> {\n        let mut path = directories::BaseDirs::new()?.home_dir().to_owned();\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/atuinsh/atuin/blob/c0c717ab04c881764bcad4b3d169a507e2432643/crates/atuin-common/src/shell.rs#L30-L66","documentation":"Shell::current needs the parent process (the shell that invoked atuin) to detect the shell name. It calls process.parent() and unwraps with expect; when the OS reports no parent PID (process is orphaned or reparented, e.g. to PID 1/init with no listed parent), the process panics with 'Atuin running with no parent!'.","triggerScenarios":"Calling Shell::current from a process whose parent link is absent: double-forked daemons, orphaned processes reparented to init, or platforms where sysinfo cannot read the parent PID field.","commonSituations":"Running atuin commands from daemonized or detached contexts; shell wrappers that exec/double-fork before invoking atuin; minimal containers where parent metadata is unavailable.","solutions":["Invoke atuin directly from an interactive shell rather than from a detached/orphaned process.","Pass the shell explicitly (e.g. via config or the shell_name path with an explicit parent) instead of relying on detection.","Relax the expect to fall back to the $SHELL environment variable when no parent exists.","Avoid double-forking between the shell and the atuin invocation."],"exampleFix":"// before\nlet parent = sys.process(process.parent().expect(\"Atuin running with no parent!\"))\n    .expect(\"Process with parent pid does not exist\");\n\n// after\nlet parent = process\n    .parent()\n    .and_then(|ppid| sys.process(ppid))\n    .map(|p| p.name().to_string_lossy().to_lowercase())\n    .unwrap_or_else(|| std::env::var(\"SHELL\").unwrap_or_default());","handlingStrategy":"fallback","validationCode":"// Rust: detect orphaned/detached context before calling Shell::current\nlet mut sys = sysinfo::System::new_all();\nlet orphaned = sysinfo::get_current_pid().ok()\n    .and_then(|pid| sys.process(pid))\n    .and_then(|p| p.parent())\n    .is_none();\nif orphaned { /* use $SHELL or explicit shell name */ }","typeGuard":null,"tryCatchPattern":"// Rust\nlet shell = std::panic::catch_unwind(Shell::current)\n    .ok()\n    .or_else(|| std::env::var(\"SHELL\").ok().map(|s| Shell::from_string(&s)))\n    .unwrap_or(Shell::Unknown);","preventionTips":["Invoke atuin directly from the shell, not from daemonized or double-forked processes.","Prefer shell hooks that pass an explicit shell name/PID.","Fall back to the $SHELL environment variable for orphaned processes.","Avoid exec chains that detach atuin from its parent shell."],"tags":["process","panic","orphaned-process","shell-detection"],"backgroundTag":"resource-not-found","analyzedSha":"c0c717ab04c881764bcad4b3d169a507e2432643","analyzedAt":"2026-09-12T07:40:01.341Z","contentChangedAt":"2026-09-12T07:40:01.341Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}