{"record":{"id":"f6b52ada9fe44b0b","repo":"vectordotdev/vector","slug":"invalidinput-f6b52a","errorCode":"InvalidInput","errorMessage":"cannot extend a file through the truncation API","messagePattern":"cannot extend a file through the truncation API","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"lib/vector-buffers/src/variants/disk_v2/writer.rs","lineNumber":1241,"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":1223,"sourceCodeEnd":1259,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-buffers/src/variants/disk_v2/writer.rs#L1223-L1259","documentation":"In the disk-buffer v2 writer, `truncate_current_data_file` applies a shrink to the current data file after flushing, and guards the invariant that the requested size must not exceed `writer.current_data_file_size`. Violating it returns `InvalidInput` \"cannot extend a file through the truncation API\". Because this runs after a writer-checkpoint scan (with the reader dropped for Windows compatibility), an oversized request indicates the writer's notion of the file size disagrees with the truncation target — an internal consistency failure, not normal operation.","triggerScenarios":"Buffer internals requesting truncation past the tracked data-file size — e.g. corrupted ledger/checkpoint state after a crash, manual tampering with the data directory, or a bug in offset arithmetic feeding `truncate_current_data_file`. Ordinary Vector users should never see this from config alone.","commonSituations":"Data-disk-buffer files edited/copied by hand; mixing buffer directories between Vector versions or instances; disk state mutated while Vector was stopped; bugs in buffer checkpoint recovery.","solutions":["If the buffer's on-disk state is suspect, move aside/delete the `data_dir` buffer directory and let Vector recreate it (accepted data loss of buffered events).","Report upstream with the Vector version and buffer config if it reproduces on an untouched data directory — the size mismatch is an internal invariant break.","Ensure only one Vector instance uses a given buffer directory and that versions are not interleaved across restarts."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Internal guard before requesting truncation:\nif size > writer.current_data_file_size {\n    warn!(size, current = writer.current_data_file_size,\n          \"skipping truncation that would extend the data file\");\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep buffer directories single-instance, single-version; never share or hand-edit them.","If a buffer's state may be inconsistent after a crash, recreate the directory instead of forcing recovery.","Report reproducible occurrences upstream — this path indicates an internal invariant break."],"tags":["disk-buffer","checkpoint","truncate","io","vector"],"backgroundTag":"cannot-extend-via-truncate","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}