{"record":{"id":"a724a2a8fcbbfd5b","repo":"Hmbown/CodeWhale","slug":"web-run-state-should-be-present-until-write-back","errorCode":null,"errorMessage":"web run state should be present until write-back","messagePattern":"web run state should be present until write-back","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/web_run.rs","lineNumber":761,"sourceCode":"    fn new(\n        mut sessions: RwLockWriteGuard<'a, HashMap<String, WebRunSessionState>>,\n        mut pages: RwLockWriteGuard<'a, HashMap<String, StoredWebPage>>,\n    ) -> Self {\n        let state = WebRunState {\n            sessions: std::mem::take(&mut *sessions),\n            pages: std::mem::take(&mut *pages),\n        };\n        Self {\n            sessions,\n            pages,\n            state: Some(state),\n        }\n    }\n\n    fn state_mut(&mut self) -> &mut WebRunState {\n        self.state\n            .as_mut()\n            .expect(\"web run state should be present until write-back\")\n    }\n\n    fn write_back(mut self) {\n        self.restore();\n    }\n\n    fn restore(&mut self) {\n        if let Some(state) = self.state.take() {\n            *self.sessions = state.sessions;\n            *self.pages = state.pages;\n        }\n    }\n}\n\nimpl Drop for WebRunStateWriteBack<'_> {\n    fn drop(&mut self) {\n        self.restore();\n    }","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tools/web_run.rs#L743-L779","documentation":"WebRunStateGuard::new takes the session/page maps out of the RwLock write guards and stashes them in Option state; Drop writes them back. state_mut() panics if called after the state was already consumed (e.g. during or after write-back), which would indicate a double-take or use-after-drop bug in the guard, not bad input.","triggerScenarios":"Thrown at crates/tui/src/tools/web_run.rs:761 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only call state_mut() while the guard is alive and write-back has not run","Return Option/&mut WebRunState via a taking method instead of expecting, if callers can legitimately observe the taken state","Add a debug assertion with a clearer message distinguishing drop-time from mid-use consumption"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}