{"record":{"id":"22f65da55f6aac11","repo":"Hmbown/CodeWhale","slug":"another-terminal-clipboard-write-is-still-queued","errorCode":null,"errorMessage":"another terminal clipboard write is still queued","messagePattern":"another terminal clipboard write is still queued","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/tui/src/tui/clipboard.rs","lineNumber":288,"sourceCode":"                        break;\n                    }\n                }\n            })\n            .context(\"spawn terminal clipboard writer\")?;\n        Ok(Self {\n            request_tx,\n            completion_rx,\n        })\n    }\n\n    fn enqueue(&self, text: &str, in_tmux: bool) -> Result<()> {\n        let request = TerminalClipboardWriteRequest {\n            text: text.to_string(),\n            in_tmux,\n        };\n        self.request_tx.try_send(request).map_err(|err| match err {\n            std::sync::mpsc::TrySendError::Full(_) => {\n                anyhow::anyhow!(\"another terminal clipboard write is still queued\")\n            }\n            std::sync::mpsc::TrySendError::Disconnected(_) => {\n                anyhow::anyhow!(\"terminal clipboard writer stopped\")\n            }\n        })\n    }\n\n    fn poll_completion(&self) -> Option<TerminalClipboardWriteCompletion> {\n        self.completion_rx.try_recv().ok()\n    }\n}\n\n/// Clipboard reader/writer helper.\npub struct ClipboardHandler {\n    terminal_context: TerminalClipboardContext,\n    terminal_writer: Option<TerminalClipboardWriter>,\n    #[cfg(all(target_os = \"linux\", not(target_env = \"ohos\"), not(test)))]\n    primary: Option<primary::PrimarySelection>,","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/clipboard.rs#L270-L306","documentation":"Terminal clipboard writes are serialized through a channel to a dedicated writer thread that owns the terminal. `enqueue` uses `try_send` (non-blocking); when the single-slot queue is already full — a previous write has not been drained yet — the new request is refused with this error rather than blocking the caller.","triggerScenarios":"Calling `enqueue` twice in quick succession before the writer thread consumed the first `TerminalClipboardWriteRequest`, so `try_send` returns `TrySendError::Full`.","commonSituations":"Copying multiple selections rapidly in the TUI; a slow or paused terminal (tmux, flow control) delays the writer; bulk copy operations issuing many clipboard writes back-to-back.","solutions":["Retry the enqueue after a short delay (rate-limit clipboard writes)","Wait for or track completion of the previous clipboard write before enqueueing","Coalesce/dedupe clipboard writes so only the latest text is sent"],"exampleFix":"// before\nclipboard.enqueue(text1);\nclipboard.enqueue(text2); // may fail: queue full\n// after\nif clipboard.enqueue(text2).is_err() {\n    // drop or retry later; only the latest text matters\n    std::thread::sleep(std::time::Duration::from_millis(50));\n    let _ = clipboard.enqueue(text2);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match clipboard.enqueue(text) {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"still queued\") => {\n        // drop or retry after a short delay; the queued write still lands\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Throttle clipboard writes; coalesce rapid copies to the latest text","Check channel capacity before high-frequency enqueue loops","Handle queue-full as an expected, non-fatal condition"],"tags":["clipboard","terminal","backpressure"],"backgroundTag":"rate-limit-exceeded","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"}