{"record":{"id":"086d467859a7140d","repo":"vectordotdev/vector","slug":"cannot-extend-a-file-through-the-truncation-api-writer","errorCode":null,"errorMessage":"cannot extend a file through the truncation API","messagePattern":"cannot extend a file through the truncation API","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-buffers/src/variants/disk_v2/writer.rs","lineNumber":1240,"sourceCode":"                        WriterCheckpointScanAction::Continue => {}\n                        WriterCheckpointScanAction::Stop => break,\n                    }\n                }\n            }\n        }\n\n        // Windows does not permit truncating a file while the scan's read handle remains open.\n        drop(reader);\n        self.apply_writer_checkpoint_scan(scan).await\n    }\n\n    async fn truncate_current_data_file(&mut self, size: u64) -> io::Result<()> {\n        let writer = self\n            .writer\n            .as_mut()\n            .expect(\"writer should exist after `ensure_ready_for_write`\");\n        if size > writer.current_data_file_size {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidInput,\n                \"cannot extend a file through the truncation API\",\n            ));\n        }\n        writer.writer.flush().await?;\n\n        let data_file_path = self.ledger.get_current_writer_data_file_path();\n        self.ledger\n            .filesystem()\n            .truncate_file(&data_file_path, size)\n            .await?;\n\n        writer.current_data_file_size = size;\n        self.data_file_size = size;\n\n        Ok(())\n    }\n","sourceCodeStart":1222,"sourceCodeEnd":1258,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-buffers/src/variants/disk_v2/writer.rs#L1222-L1258","documentation":"The disk v2 buffer writer's truncate_current_data_file shrinks the active data file (e.g. after acknowledging consumed records). This error is raised when the requested size exceeds the writer's tracked current_data_file_size, because the truncation API cannot grow a file. The check uses the writer's in-memory size tracker instead of live metadata.","triggerScenarios":"Calling truncate_current_data_file with a size larger than current_data_file_size; acknowledged offsets pointing beyond the tracked data file size due to stale bookkeeping or a checkpoint/checkpoint mismatch after recovery.","commonSituations":"Replaying acknowledgements from an old checkpoint against a newer data file; a bug in offset/size accounting in the buffer; concurrent compaction and acknowledgement processing.","solutions":["Fix the caller to clamp the truncation size to current_data_file_size before calling.","Verify acknowledgement/checkpoint bookkeeping so retained sizes never exceed the tracked file size.","If triggered after recovery, rebuild the buffer directory state or discard the corrupt buffer."],"exampleFix":"// before\nwriter.truncate_current_data_file(acked_size).await?;\n// after\nlet size = acked_size.min(writer.current_data_file_size);\nwriter.truncate_current_data_file(size).await?;","handlingStrategy":"validation","validationCode":"// clamp acknowledged size to the tracked data file size\nfn clamp_truncate_size(acked: u64, tracked: u64) -> u64 {\n    acked.min(tracked)\n}","typeGuard":null,"tryCatchPattern":"match writer.truncate_current_data_file(size).await {\n    Err(e) if e.kind() == io::ErrorKind::InvalidInput => {\n        // stale size accounting: resync with writer.current_data_file_size\n    }\n    other => other?,\n}","preventionTips":["Always clamp requested sizes against current_data_file_size.","Serialize acknowledgement processing with compaction to avoid stale sizes.","Log and alarm on acked offsets exceeding tracked file size — it indicates accounting corruption."],"tags":["buffers","disk","writer","truncate"],"backgroundTag":"invalid-argument-value","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}