{"record":{"id":"d85e8560a588af1e","repo":"Hmbown/CodeWhale","slug":"runtime-terminal-receipt-monitor-failed-error","errorCode":null,"errorMessage":"Runtime terminal receipt monitor failed: {error}","messagePattern":"Runtime terminal receipt monitor failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":5230,"sourceCode":"        {\n            let _ = engine.send(Op::Shutdown).await;\n        }\n        for (_, worker) in workers {\n            if let Err(error) = await_retained_completion(&worker).await {\n                failure = Some(anyhow!(\"Runtime engine shutdown failed: {error}\"));\n            }\n        }\n        // Recovery reads can publish receipts too. Flushes that already passed\n        // their admission check retain this mutex through all receipt writes;\n        // later readers see the closed latch under the same mutex.\n        {\n            let _recovery = self.recovery_flush.lock().await;\n        }\n        loop {\n            let monitors = self.turn_monitors.lock().clone();\n            for monitor in monitors {\n                if let Err(error) = await_retained_completion(&monitor).await {\n                    failure = Some(anyhow!(\"Runtime terminal receipt monitor failed: {error}\"));\n                }\n            }\n            let mut monitors = self.turn_monitors.lock();\n            monitors.retain(|monitor| !completion_finished(monitor));\n            if monitors.is_empty() {\n                break;\n            }\n        }\n        self.engine_workers\n            .lock()\n            .retain(|(_, worker)| !completion_finished(worker));\n        let mut active = self.active.lock().await;\n        active.engines.clear();\n        active.lru.clear();\n        failure.map_or(Ok(()), Err)\n    }\n\n    fn track_receipt_worker(&self, worker: tokio::task::JoinHandle<()>) {","sourceCodeStart":5212,"sourceCodeEnd":5248,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L5212-L5248","documentation":"During RuntimeThreadManager shutdown, terminal receipt monitors are awaited with await_retained_completion. If any turn monitor resolves with an error, shutdown records 'Runtime terminal receipt monitor failed'. Receipt monitors are background tasks that publish terminal receipts when a turn finishes, so this indicates a monitor task ended abnormally.","triggerScenarios":"Calling RuntimeThreadManager::shutdown while turn monitors are registered; a monitor's retained completion returns Err (monitor task failed or was cancelled), and the retain loop that drops finished monitors then finds remaining failures.","commonSituations":"Tearing down the runtime with turns whose receipt monitors never completed; a monitor task panicking while persisting a receipt; store write failures during receipt publication.","solutions":["Check the wrapped {error} to identify which monitor failed and why","Ensure turn completion paths publish their receipts successfully before shutdown","Verify the turn store is accessible so receipt writes succeed","Call shutdown again or drain remaining monitors if the loop broke out with monitors still present"],"exampleFix":"// before\nlet _ = manager.shutdown().await;\n// after\nmatch manager.shutdown().await {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"receipt monitor\") => {\n        tracing::warn!(\"receipt monitor failed during shutdown: {e:#}\");\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"let monitors = manager.turn_monitors.lock().clone();\nlet monitors_done = monitors.iter().all(completion_finished);","typeGuard":"fn monitor_finished(monitor: &RuntimeCompletion) -> bool { completion_finished(monitor) }","tryCatchPattern":"match manager.shutdown().await {\n    Err(e) if e.to_string().contains(\"receipt monitor\") => {\n        tracing::warn!(\"monitor failure at shutdown (turn receipts may be missing): {e:#}\");\n    }\n    other => other?,\n}","preventionTips":["Let receipt monitors finish (turns reach terminal status) before shutdown","Ensure receipt writes to the store cannot fail silently","Reconcile missing receipts after shutdown if monitors failed"],"tags":["shutdown","monitor","async"],"backgroundTag":"internal-invariant-violation","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}