{"record":{"id":"d04149cfe6625e5c","repo":"openai/codex","slug":"snapshot-command-exited-with-status-status-std","errorCode":null,"errorMessage":"Snapshot command exited with status {status}: {stderr}","messagePattern":"Snapshot command exited with status (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"codex-rs/core/src/shell_snapshot.rs","lineNumber":308,"sourceCode":"    handler.stdin(Stdio::null());\n    handler.current_dir(cwd);\n    #[cfg(unix)]\n    unsafe {\n        handler.pre_exec(|| {\n            codex_utils_pty::process_group::detach_from_tty()?;\n            Ok(())\n        });\n    }\n    handler.kill_on_drop(true);\n    let output = timeout(snapshot_timeout, handler.output())\n        .await\n        .map_err(|_| anyhow!(\"Snapshot command timed out for {shell_name}\"))?\n        .with_context(|| format!(\"Failed to execute {shell_name}\"))?;\n\n    if !output.status.success() {\n        let status = output.status;\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        bail!(\"Snapshot command exited with status {status}: {stderr}\");\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).into_owned())\n}\n\n/// Removes shell snapshots that either lack a matching session rollout file or\n/// whose rollouts have not been updated within the retention window.\n/// The active session id is exempt from cleanup.\npub async fn cleanup_stale_snapshots(\n    codex_home: &AbsolutePathBuf,\n    active_session_id: ThreadId,\n    state_db: Option<StateDbHandle>,\n) -> Result<()> {\n    let snapshot_dir = codex_home.join(SNAPSHOT_DIR);\n\n    let mut entries = match fs::read_dir(&snapshot_dir).await {\n        Ok(entries) => entries,\n        Err(err) if err.kind() == ErrorKind::NotFound => return Ok(()),","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/core/src/shell_snapshot.rs#L290-L326","documentation":"After the snapshot shell process exits, run_script_with_timeout checks output.status.success(); a non-zero exit code triggers this bail with the exit status and captured stderr. The status is from the login-shell run that sources rcfiles and emits the snapshot (or, during validation, from re-sourcing the written snapshot with set -e). Any rcfile error that propagates as a non-zero exit surfaces here.","triggerScenarios":"Running the snapshot script under zsh/bash -lc where: an rcfile has a syntax error; a sourced script runs under set -e and a command fails; the shell binary itself is broken (missing interpreter, wrong arch); validation run fails because the generated snapshot no longer sources cleanly.","commonSituations":"Broken dotfiles after an OS or shell upgrade (deprecated options in .zshrc); a failed tool init (missing binary referenced in .bash_profile); shell binaries corrupted or replaced; snapshots generated against a different shell version failing validation on re-source.","solutions":["Run zsh -lc true (or bash -lc true) in the same environment — non-zero exit plus the stderr shown in the error pinpoints the failing rcfile line","Fix the rcfile error named in stderr (syntax error, missing command, bad option)","For set -e-style failures, guard the failing command in rcfiles (cmd || true) or make it conditional on interactive shells","Until fixed, disable the shell snapshot feature — failure is non-fatal to the session"],"exampleFix":"# ~/.bash_profile — before\nsource ~/bin/my-init.sh   # exits 1 when tool missing\n\n# after\n[[ -f ~/bin/my-init.sh ]] && source ~/bin/my-init.sh || echo \"my-init skipped\" >&2","handlingStrategy":"try-catch","validationCode":"// Validate rcfiles load cleanly before enabling snapshots\n// shell: zsh -n ~/.zshrc (syntax) and zsh -lc true (execution) must pass","typeGuard":null,"tryCatchPattern":"match write_shell_snapshot(...).await {\n    Err(e) if e.chain().any(|c| c.to_string().contains(\"exited with status\")) => {\n        log_shell_rc_error(&e); Ok(None) // degrade, session continues\n    }\n    other => other,\n}","preventionTips":["Run zsh -lc true / bash -lc true after dotfile changes; a non-zero exit will break snapshots","Guard failing init lines in rcfiles (|| true) or make them interactive-only","Keep the shell binary and rcfile syntax valid after OS/shell upgrades"],"tags":["rust","codex","shell-snapshot","nonzero-exit","dotfiles"],"backgroundTag":"command-exited-nonzero","analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}