{"record":{"id":"ae7424377b8758fa","repo":"xai-org/grok-build","slug":"upload-queue-closed-ae7424","errorCode":null,"errorMessage":"upload queue closed","messagePattern":"upload queue closed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-file-utils/src/queue.rs","lineNumber":975,"sourceCode":"            compress: false,\n            parent_span: tracing::Span::current(),\n            _in_flight: None,\n        };\n        self.stats.pending.fetch_add(1, Ordering::Relaxed);\n        self.stats.pending_bytes.fetch_add(size, Ordering::Relaxed);\n        self.stats.enqueued.fetch_add(1, Ordering::Relaxed);\n        match self.tx.try_send(item) {\n            Ok(()) => self.stats.notify_transition(),\n            Err(e) => {\n                let closed = matches!(&e, mpsc::error::TrySendError::Closed(_));\n                let rejected = e.into_inner();\n                self.stats.pending.fetch_sub(1, Ordering::Relaxed);\n                self.stats.pending_bytes.fetch_sub(size, Ordering::Relaxed);\n                self.stats.enqueued.fetch_sub(1, Ordering::Relaxed);\n                self.stats.notify_transition();\n                if closed {\n                    remove_item_files(&rejected, Some(&self.stats));\n                    return Err(anyhow::Error::new(QueueClosed).context(\"upload queue closed\"));\n                }\n                if let Some(sidecar) = &rejected.sidecar_path {\n                    try_remove_temp(sidecar, Some(&self.stats));\n                }\n                self.stats.enqueue_fallbacks.fetch_add(1, Ordering::Relaxed);\n                self.spawn_inline_upload_owned_snapshot(\n                    rejected.source.path().to_path_buf(),\n                    gcs_path.to_string(),\n                    content_type.to_string(),\n                    size,\n                    rejected.completion_tx,\n                );\n            }\n        }\n        rx.await\n            .map_err(|_| {\n                anyhow::Error::new(QueueClosed).context(\"worker dropped completion channel\")\n            })?","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-file-utils/src/queue.rs#L957-L993","documentation":"Raised while enqueuing an upload when the queue was closed concurrently: the enqueue path detected `closed`, removed the rejected item's files, and returned QueueClosed wrapped with 'upload queue closed'. It means the upload queue is shutting down (or already shut down) and will not accept new items, so the caller's file cannot be scheduled for background upload.","triggerScenarios":"Calling enqueue/upload concurrently with queue shutdown — e.g. a session ending calls close()/drop on the queue while another task is mid-enqueue; the close flag flips after stats were updated, so the item is rejected and its temp files cleaned up.","commonSituations":"Race between a final artifact upload and session teardown; abrupt client shutdown cancelling the queue; a bug where close() is called too early in the lifecycle.","solutions":["Check the queue's closed/shutdown state before enqueueing and skip the upload (or write directly) if closed.","Ensure all enqueue calls are ordered before close()/shutdown in the session teardown sequence.","Perform the upload inline (spawn_inline_upload style) as a fallback when the queue rejects the item.","If the error appears without intentional shutdown, audit who calls close() and fix the premature shutdown."],"exampleFix":"// before\nlet url = queue.enqueue_upload(item).await?;\n// after\nlet url = if queue.is_closed() {\n    tracing::warn!(\"upload queue closed; uploading inline\");\n    inline_upload(&item).await?\n} else {\n    queue.enqueue_upload(item).await?\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_queue_closed(err: &anyhow::Error) -> bool {\n    err.chain().any(|c| c.to_string().contains(\"upload queue closed\"))\n}","tryCatchPattern":"match queue.enqueue_upload(item).await {\n    Ok(url) => url,\n    Err(e) if is_queue_closed(&e) => {\n        tracing::warn!(\"queue shutting down; uploading inline\");\n        inline_upload(&item).await?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Order all enqueues strictly before close()/shutdown in teardown","Check the queue's closed state before enqueueing during shutdown windows","Keep an inline-upload fallback for end-of-session artifacts","Track queue lifecycle with a single owner task to avoid close/enqueue races"],"tags":["upload","queue","shutdown","concurrency"],"backgroundTag":"queue-closed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}