fix: Lazily instantiate the KV-IR writer when using disk buffering to prevent uploading files that only contain IR preamble.#18
Merged
davemarco merged 3 commits intoy-scope:mainfrom Feb 25, 2026
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
davidlion
approved these changes
Feb 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I noticed a subtle behavioral change introduced by the KV-IR PR related to when the IR preamble gets written to the tag’s IR file.
Consider the expected behavior from the old implementation.
Suppose logs are written for a specific tag and the plugin crashes. During recovery, we upload that tag’s IR file to S3 and then truncate the file so it becomes empty. If no additional logs arrive for that tag and the plugin crashes again, the file remains empty and is deleted on startup. Nothing further is uploaded.
This worked because of how the old writer used an intermediate buffer. Even though the IR file itself already existed on disk, the writer did not write the preamble directly into the file. Instead, the preamble and subsequent bytes were written into a buffer, and that buffer was only flushed into the IR file when the first log record was actually written. If no logs arrived after recovery, nothing ever triggered a flush, so the truncated file stayed truly empty.
With the KV-IR changes, this behavior is different. The writer now writes the IR preamble directly into the IR file as soon as the writer is instantiated. As a result, after recovery and truncation, the new IR file is no longer truly empty — it immediately contains the preamble. If no logs are written for that tag and the plugin crashes again, this preamble-only file is treated as non-empty and gets uploaded to S3.
To address this, I changed the code to lazily instantiate the writer so that the IR preamble is only written once there is at least one log record to write, restoring the previous behavior.
Note a buffered writer wrapper could also solve this problem, but for now decided just to use the exported IR interface directly.
Checklist
breaking change.
Validation performed
Sent some logs to plugin with disk buffer. Then closed and restarted plugin multiple times. Only the first restart actually sent logs. Later restarts sent nothing. Tmp folders were empty as well.