{"record":{"id":"a0de9d227d336d9a","repo":"xai-org/grok-build","slug":"no-user-grok-home-resolved-refusing-to-write-a-cw","errorCode":null,"errorMessage":"no user grok home resolved; refusing to write a cwd-relative pager.toml that startup would never read","messagePattern":"no user grok home resolved; refusing to write a cwd-relative pager\\.toml that startup would never read","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager-render/src/appearance/config.rs","lineNumber":1895,"sourceCode":"        if !(trimmed.is_empty() || trimmed.starts_with('#') || trimmed.starts_with('[')) {\n            out.push_str(\"# \");\n        }\n        out.push_str(line);\n        out.push('\\n');\n    }\n    out\n}\n\n/// Serializes the pager.toml read-modify-write so two rapid settings\n/// toggles can't interleave and clobber each other (mirrors the shell's\n/// `save_config` `SAVE_LOCK`).\nstatic PAGER_TOML_SAVE_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());\n\npub fn persist_respect_manual_folds(enabled: bool) -> std::io::Result<()> {\n    use std::io::{Error, ErrorKind};\n\n    if xai_grok_config::user_grok_home().is_none() {\n        return Err(Error::new(\n            ErrorKind::NotFound,\n            \"no user grok home resolved; refusing to write a cwd-relative pager.toml \\\n             that startup would never read\",\n        ));\n    }\n    let _guard = PAGER_TOML_SAVE_LOCK\n        .lock()\n        .unwrap_or_else(|poisoned| poisoned.into_inner());\n\n    let path = crate::util::pager_toml_path();\n    let content = match std::fs::read_to_string(&path) {\n        Ok(c) => c,\n        Err(e) if e.kind() == ErrorKind::NotFound => String::new(),\n        Err(e) => return Err(e),\n    };\n    let updated = upsert_respect_manual_folds(&content, enabled)\n        .map_err(|e| Error::new(ErrorKind::InvalidData, e))?;\n    if let Some(dir) = path.parent() {","sourceCodeStart":1877,"sourceCodeEnd":1913,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager-render/src/appearance/config.rs#L1877-L1913","documentation":"persist_respect_manual_folds refuses to write pager.toml when xai_grok_config::user_grok_home() returns None, returning NotFound with this message. Writing a cwd-relative pager.toml would be silently ignored at startup, so the save is intentionally aborted. It protects the appearance/folds settings from being written where they can never be read.","triggerScenarios":"Calling persist_respect_manual_folds in an environment where no home directory resolves (HOME unset, no passwd entry, no valid GROK home override).","commonSituations":"Running under systemd services/cron with a scrubbed environment; containers without HOME set; test harnesses with cleared env vars.","solutions":["Set HOME (or the grok-home override env var) to an existing writable directory before invoking","Ensure the process runs as a user with a resolvable home directory","Persist settings in a context where the home is known, e.g. an interactive shell","Provide the setting via configuration/env rather than relying on the file save"],"exampleFix":"// before\npersist_respect_manual_folds(true)?; // NotFound when HOME unset\n// after\nstd::env::set_var(\"HOME\", \"/home/dev\"); // or launch with a proper environment\npersist_respect_manual_folds(true)?;","handlingStrategy":"validation","validationCode":"if xai_grok_config::user_grok_home().is_none() {\n    eprintln!(\"cannot persist pager.toml: no user grok home resolved\");\n    return;\n}\npersist_respect_manual_folds(enabled)?;","typeGuard":null,"tryCatchPattern":"match persist_respect_manual_folds(enabled) {\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        eprintln!(\"settings not saved: set HOME so pager.toml can be written\");\n    }\n    other => other?,\n}","preventionTips":["Verify user_grok_home() resolves before exposing settings-save UI","Launch services with HOME set to a writable directory","In tests, set a temp HOME/GROK home fixture","Never fall back to cwd-relative config writes"],"tags":["config","env","filesystem","pager"],"backgroundTag":"missing-env-var","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}