{"record":{"id":"7ea05fe0be3b14a1","repo":"BigPizzaV3/CodexPlusPlus","slug":"remote-control-recovery-state-lock-poisoned","errorCode":null,"errorMessage":"Remote Control recovery state lock poisoned","messagePattern":"Remote Control recovery state lock poisoned","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/remote_control_recovery.rs","lineNumber":53,"sourceCode":"}\n\npub fn config_generation(profile: &RelayProfile, target_provider: &str) -> String {\n    let mut digest = Sha256::new();\n    digest.update(profile.id.trim().as_bytes());\n    digest.update([0]);\n    digest.update(profile.config_contents.as_bytes());\n    digest.update([0]);\n    digest.update(target_provider.trim().as_bytes());\n    format!(\"{:x}\", digest.finalize())\n}\n\npub fn load_pending_remote_control_recoveries(\n    path: Option<&Path>,\n) -> anyhow::Result<Vec<PendingRemoteControlRecovery>> {\n    let path = pending_path(path);\n    let _guard = state_lock()\n        .lock()\n        .map_err(|_| anyhow::anyhow!(\"Remote Control recovery state lock poisoned\"))?;\n    Ok(load_state(&path)?.requests)\n}\n\npub fn enqueue_pending_remote_control_recovery(\n    path: Option<&Path>,\n    request: PendingRemoteControlRecovery,\n) -> anyhow::Result<()> {\n    validate_request(&request)?;\n    let path = pending_path(path);\n    let _guard = state_lock()\n        .lock()\n        .map_err(|_| anyhow::anyhow!(\"Remote Control recovery state lock poisoned\"))?;\n    let mut state = load_state(&path)?;\n    // The first observed profile/provider snapshot is authoritative. Retries for the same\n    // thread must not overwrite it after the user switches relay profiles.\n    if state\n        .requests\n        .iter()","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/remote_control_recovery.rs#L35-L71","documentation":"load_pending_remote_control_recoveries reads the persisted Remote Control recovery state under a process-wide mutex. If a thread panicked while holding that mutex (e.g. a bug in load_state or serialization), the RwLock/Mutex is poisoned and every later .lock() returns Err. The library converts that into this anyhow error instead of silently proceeding with possibly-corrupt state.","triggerScenarios":"Calling load_pending_remote_control_recoveries after any earlier thread panicked while holding state_lock(); concurrent access where one closure panics (e.g. unwrapping a bad path) between enqueue and load.","commonSituations":"Long-running manager app where a background thread panicked in a recovery helper earlier in the session; tests that panic inside a closure holding the lock and then re-call the API.","solutions":["Find and fix the code that panicked while holding the state lock (panic is the root cause, poisoning is the symptom).","Wrap lock-internal code in catch_unwind or avoid panicking operations (use map_err instead of unwrap) inside the critical section.","Replace state_lock() with a poisoning-resistant primitive such as parking_lot::Mutex, or call lock().unwrap_or_else(|p| p.into_inner()) if state corruption is acceptable.","Restart the process; poisoning is per-lock-instance so a restart clears it."],"exampleFix":"// before\nlet _guard = state_lock().lock().map_err(|_| anyhow::anyhow!(\"Remote Control recovery state lock poisoned\"))?;\n// after\nlet _guard = state_lock().lock().unwrap_or_else(|poisoned| poisoned.into_inner());","handlingStrategy":"try-catch","validationCode":"// No pre-check possible for poisoning; ensure prior calls didn't panic\n// e.g. assert_no_poison: run a cheap lock probe\nlet probe = state_lock().lock();\nif probe.is_err() { /* lock poisoned: restart or recover before calling API */ }","typeGuard":null,"tryCatchPattern":"match load_pending_remote_control_recoveries(None) {\n    Ok(requests) => requests,\n    Err(e) if e.to_string().contains(\"lock poisoned\") => {\n        // log original panic source, recover state via into_inner or restart\n        Vec::new()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Never panic (unwrap/expect) inside code holding the recovery state lock.","Consider parking_lot::Mutex to avoid poisoning semantics.","Keep lock critical sections small and infallible.","Log panics with backtrace to identify the poisoning culprit quickly."],"tags":["concurrency","mutex-poisoned","rust"],"backgroundTag":"mutex-poisoned","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}