← Back to Pull requests

fix(logger): misc fixes and ergonomics improvements #1662

Merged
dnut merged 8 files (265 lines) on Jul 20, 2026 19:02 UTC
View on GitHub
dnut dnut commented on Jul 01, 2026 21:33 UTC
Author

  • fix pointer cast mut->const->mut compile error. this made it impossible to use the field function with mutable pointers

  • remove quoted/literal distinction from logger api. only the presence of whitespace should determine whether fields are quoted. this should not be customizable by the user.

  • use a default formatter for .field() and add .fieldFmt() for when you want to customize the formatter. previously this function was confusing to use. ergonomics is very important for code as widely used as a logger. the default formatters will be the right answer in almost every case. i doubt there will be many exceptions, if any.

  • add log function for when there are no args

  • start using field and log in a few places
  • Diff: 265 lines (+195 / -70) across 8 files Reviewer: ajw221 Review duration: 27209m
    All Vouch review confidence checks passed
    Residual risk 0.09 = Change Risk (0.47) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 265 lines diff across 8 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.69 · 5 substantive comment(s)
    0.69
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.334
    Real PR Conversation Timeline
    15 items
    codecov[bot] codecov[bot] commented on Jul 16, 2026 13:45 UTC
    Bot

    Codecov Report


    :x: Patch coverage is 69.07216% with 30 lines in your changes missing coverage. Please review.

    | Files with missing lines | Patch % | Lines |
    |---|---|---|
    | v2/lib/telemetry.zig | 10.00% | 9 Missing :warning: |
    | v2/services/gossip.zig | 0.00% | 6 Missing :warning: |
    | v2/lib/snapshot/download.zig | 0.00% | 4 Missing :warning: |
    | v2/lib/telemetry/log.zig | 94.28% | 4 Missing :warning: |
    | v2/services/accounts\_db.zig | 0.00% | 4 Missing :warning: |
    | v2/lib/accounts\_db/rooted.zig | 0.00% | 1 Missing :warning: |
    | v2/lib/gossip/node.zig | 0.00% | 1 Missing :warning: |
    | v2/services/snapshot.zig | 0.00% | 1 Missing :warning: |

    :x: Your patch check has failed because the patch coverage (69.07%) is below the target coverage (85.00%). You can increase the patch coverage or adjust the target coverage.

    | Files with missing lines | Coverage Δ | |
    |---|---|---|
    | v2/lib/accounts\_db/rooted.zig | 0.00% <0.00%> (ø) | |
    | v2/lib/gossip/node.zig | 0.00% <0.00%> (ø) | |
    | v2/services/snapshot.zig | 0.00% <0.00%> (ø) | |
    | v2/lib/snapshot/download.zig | 10.44% <0.00%> (-0.02%) | :arrow_down: |
    | v2/lib/telemetry/log.zig | 57.50% <94.28%> (+5.57%) | :arrow_up: |
    | v2/services/accounts\_db.zig | 0.00% <0.00%> (ø) | |
    | v2/services/gossip.zig | 0.00% <0.00%> (ø) | |
    | v2/lib/telemetry.zig | 59.73% <10.00%> (-2.29%) | :arrow_down: |
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    Copilot Copilot commented on code on Jul 16, 2026 18:01 UTC
    Code Review
    v2/lib/telemetry.zig:1
    @@ -277,18 +277,68 @@ pub fn Logger(comptime scope_str: []const u8) type {
             }
     
             pub fn Entry(comptime entry_count: usize) type {
    +            const log_zig = @import("telemetry/log.zig");
                 return struct {
                     logger: LoggerSelf,
    -                level: log.Level,
    -                entries: [entry_count]log.EntryField,
    +                level: log_zig.Level,
    +                entries: [entry_count]log_zig.EntryField,
                     const EntrySelf = @This();
     
    +                /// Formats using the default formatter for the type, if it exists. To
    +                /// customize the format, use `fromValue` or `fromFmt`.

    This docstring says to customize formatting via fromValue/fromFmt, but field() now takes a pointer and the customization path is fieldFmt(name, EntryValueFmt.fromValue/fromFmt(...)). The current wording is misleading for callers.

    Copilot Copilot commented on code on Jul 16, 2026 18:01 UTC
    Code Review
    v2/lib/telemetry/log.zig:1
    @@ -592,66 +590,52 @@ pub const EntryField = struct {
     
     test EntryField {
         try std.testing.expectFmt("foo=bar", "{f}", .{
    -        EntryField.init("foo", .fromValue(.literal, "{s}", &"bar")),
    +        EntryField.init("foo", .fromValue("{s}", &"bar")),
         });
         try std.testing.expectFmt("", "{f}", .{EntryField.listFmt(&.{})});
    -    try std.testing.expectFmt("foo=\"bar\"", "{f}", .{
    -        EntryField.listFmt(&.{.init("foo", .fromValue(.quoted, "{s}", &"bar"))}),
    +    try std.testing.expectFmt("foo=\"foo bar\"", "{f}", .{
    +        EntryField.listFmt(&.{.init("foo", .fromValue("{s}", &"foo bar"))}),
         });
     }
     
     /// Type-erased formatter.
     pub const EntryValueFmt = struct {
    -    surround: Surround,
         ptr: *const anyopaque,
         formatFn: *const fn (
    -        surround: Surround,
             value: *const anyopaque,
             w: *std.Io.Writer,
         ) std.Io.Writer.Error!void,
     
         pub fn format(self: EntryValueFmt, w: *std.Io.Writer) std.Io.Writer.Error!void {
    -        try self.formatFn(self.surround, self.ptr, w);
    +        try self.formatFn(self.ptr, w);
         }
     
    -    pub const Surround = enum {
    -        literal,
    -        quoted,
    -
    -        fn str(surround: Surround) []const u8 {
    -            return switch (surround) {
    -                .literal => "",
    -                .quoted => "\"",
    -            };
    -        }
    -    };
    -
         /// Resulting formatter will write the equivalent of:
         /// `std.Io.Writer.print(w, fmt_str, .{value_ptr.*})`.
         pub fn fromValue(
    -        surround_value: Surround,
             comptime fmt_str: []const u8,
    -        /// Pointer to an integer.
    +        /// Pointer to a value.
             value_ptr: anytype,
         ) EntryValueFmt {
             const is_comptime_known = isComptimeKnown(value_ptr.*);
    +        comptime var ptr_info = @typeInfo(@TypeOf(value_ptr));
    +        ptr_info.pointer.is_const = true;
             const erased = struct {
                 fn formatImpl(
    -                surround: Surround,
                     ptr: *const anyopaque,
                     w: *std.Io.Writer,
                 ) std.Io.Writer.Error!void {
    -                const value: @TypeOf(value_ptr) = if (is_comptime_known)
    +                const value: @Type(ptr_info) = if (is_comptime_known)
                         value_ptr
                     else
                         @ptrCast(@alignCast(ptr));
    -                try w.writeAll(surround.str());
    +                const has_whitespace = WhitespaceDetector.detect(fmt_str, .{value.*});
    +                if (has_whitespace) try w.writeAll("\"");
                     try w.print(fmt_str, .{value.*});
    -                try w.writeAll(surround.str());
    +                if (has_whitespace) try w.writeAll("\"");

    EntryValueFmt now formats twice (once via WhitespaceDetector.detect and again to the real writer) to decide quoting. This increases cost for every field/message, and the cost is multiplied again when std.fmt.count is used in Message.computeHeader (count + write). Consider an optimization/caching strategy for whitespace detection (or a quote policy) to avoid redundant formatting work on hot paths.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Jul 16, 2026 18:01 UTC
    Reviewer

    Pull request overview

    This PR updates the v2 telemetry logger API to improve ergonomics and consistency, including simplifying quoting behavior (quote only when formatted output contains whitespace) and adding a .log() helper for no-arg messages. It also updates several services/call sites to use the new logging APIs.

    Changes:

  • Add Logger.Entry.field() default formatting and introduce fieldFmt() for explicit formatting customization.

  • Remove the explicit quoted/literal distinction from EntryValueFmt and implement whitespace-driven quoting via a WhitespaceDetector.

  • Add .log() (no-args) and migrate a handful of log statements from logf(..., .{}) to log(...), plus convert one multiline log into structured fields.
  • Reviewed changes

    Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

    <details>
    <summary>Show a summary per file</summary>

    | File | Description |
    | ---- | ----------- |
    | v2/services/snapshot.zig | Use new .log() helper for no-arg logging. |
    | v2/services/gossip.zig | Convert startup log to structured fields + .log(). |
    | v2/services/accounts_db.zig | Replace logf(..., .{}) with .log(...) in several places. |
    | v2/lib/telemetry/log.zig | Remove surround mode and add whitespace-based quoting; update tests; add WhitespaceDetector. |
    | v2/lib/telemetry.zig | Update Logger entry API: default .field() formatting, add fieldFmt(), add .log(), and adjust message encoding usage. |
    | v2/lib/snapshot/download.zig | Convert completion log to structured fields + .log(). |
    | v2/lib/gossip/node.zig | Use new .log() helper for no-arg logging. |
    | v2/lib/accounts_db/rooted.zig | Use new .log() helper for no-arg logging. |
    </details>

    ---

    💡 <a href="/Syndica/sig/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.

    dnut dnut commented on code on Jul 16, 2026 18:05 UTC
    Code Review
    v2/lib/telemetry.zig:1
    @@ -277,18 +277,68 @@ pub fn Logger(comptime scope_str: []const u8) type {
             }
     
             pub fn Entry(comptime entry_count: usize) type {
    +            const log_zig = @import("telemetry/log.zig");
                 return struct {
                     logger: LoggerSelf,
    -                level: log.Level,
    -                entries: [entry_count]log.EntryField,
    +                level: log_zig.Level,
    +                entries: [entry_count]log_zig.EntryField,
                     const EntrySelf = @This();
     
    +                /// Formats using the default formatter for the type, if it exists. To
    +                /// customize the format, use `fromValue` or `fromFmt`.
    dnut dnut commented on code on Jul 16, 2026 18:32 UTC
    Code Review
    v2/lib/telemetry/log.zig:1
    @@ -592,66 +590,52 @@ pub const EntryField = struct {
     
     test EntryField {
         try std.testing.expectFmt("foo=bar", "{f}", .{
    -        EntryField.init("foo", .fromValue(.literal, "{s}", &"bar")),
    +        EntryField.init("foo", .fromValue("{s}", &"bar")),
         });
         try std.testing.expectFmt("", "{f}", .{EntryField.listFmt(&.{})});
    -    try std.testing.expectFmt("foo=\"bar\"", "{f}", .{
    -        EntryField.listFmt(&.{.init("foo", .fromValue(.quoted, "{s}", &"bar"))}),
    +    try std.testing.expectFmt("foo=\"foo bar\"", "{f}", .{
    +        EntryField.listFmt(&.{.init("foo", .fromValue("{s}", &"foo bar"))}),
         });
     }
     
     /// Type-erased formatter.
     pub const EntryValueFmt = struct {
    -    surround: Surround,
         ptr: *const anyopaque,
         formatFn: *const fn (
    -        surround: Surround,
             value: *const anyopaque,
             w: *std.Io.Writer,
         ) std.Io.Writer.Error!void,
     
         pub fn format(self: EntryValueFmt, w: *std.Io.Writer) std.Io.Writer.Error!void {
    -        try self.formatFn(self.surround, self.ptr, w);
    +        try self.formatFn(self.ptr, w);
         }
     
    -    pub const Surround = enum {
    -        literal,
    -        quoted,
    -
    -        fn str(surround: Surround) []const u8 {
    -            return switch (surround) {
    -                .literal => "",
    -                .quoted => "\"",
    -            };
    -        }
    -    };
    -
         /// Resulting formatter will write the equivalent of:
         /// `std.Io.Writer.print(w, fmt_str, .{value_ptr.*})`.
         pub fn fromValue(
    -        surround_value: Surround,
             comptime fmt_str: []const u8,
    -        /// Pointer to an integer.
    +        /// Pointer to a value.
             value_ptr: anytype,
         ) EntryValueFmt {
             const is_comptime_known = isComptimeKnown(value_ptr.*);
    +        comptime var ptr_info = @typeInfo(@TypeOf(value_ptr));
    +        ptr_info.pointer.is_const = true;
             const erased = struct {
                 fn formatImpl(
    -                surround: Surround,
                     ptr: *const anyopaque,
                     w: *std.Io.Writer,
                 ) std.Io.Writer.Error!void {
    -                const value: @TypeOf(value_ptr) = if (is_comptime_known)
    +                const value: @Type(ptr_info) = if (is_comptime_known)
                         value_ptr
                     else
                         @ptrCast(@alignCast(ptr));
    -                try w.writeAll(surround.str());
    +                const has_whitespace = WhitespaceDetector.detect(fmt_str, .{value.*});
    +                if (has_whitespace) try w.writeAll("\"");
                     try w.print(fmt_str, .{value.*});
    -                try w.writeAll(surround.str());
    +                if (has_whitespace) try w.writeAll("\"");

    This is complex to optimize and I don't think it's worth prioritizing at this point.

    InKryption InKryption commented on code on Jul 16, 2026 19:16 UTC
    Code Review
    v2/lib/telemetry/log.zig:1
    @@ -660,26 +644,24 @@ pub const EntryValueFmt = struct {
         /// Resulting formatter will write the equivalent of:
         /// `std.Io.Writer.print(w, fmt_strs, args_ptr.*)`.
         pub fn fromFmt(
    -        surround_value: Surround,
             comptime fmt_str: []const u8,
             /// Pointer to a tuple of arguments, instead of the value.
             /// Must outlive the return value.
             args_ptr: anytype,
         ) EntryValueFmt {
             const erased = struct {
                 fn formatImpl(
    -                surround: Surround,
                     ptr: *const anyopaque,
                     w: *std.Io.Writer,
                 ) std.Io.Writer.Error!void {
                     const args: @TypeOf(args_ptr) = @ptrCast(@alignCast(ptr));
    -                try w.writeAll(surround.str());
    +                const has_whitespace = WhitespaceDetector.detect(fmt_str, args.*);
    +                if (has_whitespace) try w.writeAll("\"");
                     try w.print(fmt_str, args.*);
    -                try w.writeAll(surround.str());
    +                if (has_whitespace) try w.writeAll("\"");

                    if (has_whitespace) try w.writeByte('"');
    try w.print(fmt_str, args.*);
                    if (has_whitespace) try w.writeByte('"');
    

    InKryption InKryption commented on code on Jul 16, 2026 19:34 UTC
    Code Review
    v2/lib/telemetry/log.zig:1
    @@ -839,3 +821,100 @@ test Iso8601Fmt {
     inline fn isComptimeKnown(value: anytype) bool {
         return @typeInfo(@TypeOf(.{value})).@"struct".fields[0].is_comptime;
     }
    +
    +/// Discards all data written to it, but tracks whether any whitespace character
    +/// (per `std.ascii.whitespace`) was ever written. Unbuffered: every write goes
    +/// through `drain`, so `found` is up-to-date without needing to flush.
    +pub const WhitespaceDetector = struct {
    +    writer: std.Io.Writer,
    +    found: bool,
    +
    +    pub fn init() WhitespaceDetector {
    +        return .{
    +            .writer = .{
    +                .vtable = &.{ .drain = drain },
    +                .buffer = &.{},
    +            },
    +            .found = false,
    +        };
    +    }

        pub fn init(buffer: []u8) WhitespaceDetector {
            return .{
                .writer = .{
                    .vtable = &.{ .drain = drain },
                    .buffer = buffer,
                },
                .found = false,
            };
        }
    

    Never any harm in taking a buffer, the caller can always just pass &.{} if they don't care. Though passing a buffer will help to amortize indirect calls.

    InKryption InKryption commented on code on Jul 16, 2026 20:44 UTC
    Code Review
    v2/lib/telemetry/log.zig:1
    @@ -839,3 +821,100 @@ test Iso8601Fmt {
     inline fn isComptimeKnown(value: anytype) bool {
         return @typeInfo(@TypeOf(.{value})).@"struct".fields[0].is_comptime;
     }
    +
    +/// Discards all data written to it, but tracks whether any whitespace character
    +/// (per `std.ascii.whitespace`) was ever written. Unbuffered: every write goes
    +/// through `drain`, so `found` is up-to-date without needing to flush.
    +pub const WhitespaceDetector = struct {
    +    writer: std.Io.Writer,
    +    found: bool,
    +
    +    pub fn init() WhitespaceDetector {
    +        return .{
    +            .writer = .{
    +                .vtable = &.{ .drain = drain },
    +                .buffer = &.{},
    +            },
    +            .found = false,
    +        };
    +    }
    +
    +    pub fn detect(comptime fmt_str: []const u8, args: anytype) bool {
    +        var white_space: WhitespaceDetector = .init();
    +        white_space.writer.print(fmt_str, args) catch unreachable;
    +        return white_space.found;
    +    }
    +
    +    fn drain(
    +        w: *std.Io.Writer,
    +        data: []const []const u8,
    +        splat: usize,
    +    ) std.Io.Writer.Error!usize {
    +        const self: *WhitespaceDetector = @alignCast(@fieldParentPtr("writer", w));
    +        const rest = data[0 .. data.len - 1];
    +        const pattern = data[data.len - 1];
    +        var written: usize = pattern.len * splat;
    +        for (rest) |bytes| written += bytes.len;
    +
    +        if (!self.found) {
    +            for (rest) |bytes| {
    +                if (std.mem.indexOfAny(u8, bytes, &std.ascii.whitespace) != null) {
    +                    self.found = true;
    +                    return written;
    +                }
    +            }
    +            if (splat != 0 and std.mem.indexOfAny(u8, pattern, &std.ascii.whitespace) != null)
    +                self.found = true;
    +        }
    +
    +        return written;
    +    }
    +};
    +
    +test WhitespaceDetector {
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeAll("no-whitespace-here");
    +        try std.testing.expect(!wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeAll("hello world");
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeAll("end ");
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeAll(" start");
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.print("value={d}", .{42});
    +        try std.testing.expect(!wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.print("value = {d}", .{42});
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.print("value={s}", .{"hello world"});
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeByte('\t');
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeByte('\n');
    +        try std.testing.expect(wd.found);
    +    }

        var wd: WhitespaceDetector = undefined;
    
        wd = .init();
        try wd.writer.writeAll("no-whitespace-here");
        try std.testing.expect(!wd.found);
    
        wd = .init();
        try wd.writer.writeAll("hello world");
        try std.testing.expect(wd.found);
    
        wd = .init();
        try wd.writer.writeAll("end ");
        try std.testing.expect(wd.found);
    
        wd = .init();
        try wd.writer.writeAll(" start");
        try std.testing.expect(wd.found);
    
        wd = .init();
        try wd.writer.print("value={d}", .{42});
        try std.testing.expect(!wd.found);
    
        wd = .init();
        try wd.writer.print("value = {d}", .{42});
        try std.testing.expect(wd.found);
    
        wd = .init();
        try wd.writer.print("value={s}", .{"hello world"});
        try std.testing.expect(wd.found);
    
        wd = .init();
        try wd.writer.writeByte('\t');
        try std.testing.expect(wd.found);
    
        wd = .init();
        try wd.writer.writeByte('\n');
        try std.testing.expect(wd.found);
    

    dnut dnut commented on code on Jul 17, 2026 03:20 UTC
    Code Review
    v2/lib/telemetry/log.zig:1
    @@ -660,26 +644,24 @@ pub const EntryValueFmt = struct {
         /// Resulting formatter will write the equivalent of:
         /// `std.Io.Writer.print(w, fmt_strs, args_ptr.*)`.
         pub fn fromFmt(
    -        surround_value: Surround,
             comptime fmt_str: []const u8,
             /// Pointer to a tuple of arguments, instead of the value.
             /// Must outlive the return value.
             args_ptr: anytype,
         ) EntryValueFmt {
             const erased = struct {
                 fn formatImpl(
    -                surround: Surround,
                     ptr: *const anyopaque,
                     w: *std.Io.Writer,
                 ) std.Io.Writer.Error!void {
                     const args: @TypeOf(args_ptr) = @ptrCast(@alignCast(ptr));
    -                try w.writeAll(surround.str());
    +                const has_whitespace = WhitespaceDetector.detect(fmt_str, args.*);
    +                if (has_whitespace) try w.writeAll("\"");
                     try w.print(fmt_str, args.*);
    -                try w.writeAll(surround.str());
    +                if (has_whitespace) try w.writeAll("\"");

    5a2fffe99a58b5bbd13860a0a1da0b33a291987b

    dnut dnut commented on code on Jul 17, 2026 03:20 UTC
    Code Review
    v2/lib/telemetry/log.zig:1
    @@ -839,3 +821,100 @@ test Iso8601Fmt {
     inline fn isComptimeKnown(value: anytype) bool {
         return @typeInfo(@TypeOf(.{value})).@"struct".fields[0].is_comptime;
     }
    +
    +/// Discards all data written to it, but tracks whether any whitespace character
    +/// (per `std.ascii.whitespace`) was ever written. Unbuffered: every write goes
    +/// through `drain`, so `found` is up-to-date without needing to flush.
    +pub const WhitespaceDetector = struct {
    +    writer: std.Io.Writer,
    +    found: bool,
    +
    +    pub fn init() WhitespaceDetector {
    +        return .{
    +            .writer = .{
    +                .vtable = &.{ .drain = drain },
    +                .buffer = &.{},
    +            },
    +            .found = false,
    +        };
    +    }
    +
    +    pub fn detect(comptime fmt_str: []const u8, args: anytype) bool {
    +        var white_space: WhitespaceDetector = .init();
    +        white_space.writer.print(fmt_str, args) catch unreachable;
    +        return white_space.found;
    +    }
    +
    +    fn drain(
    +        w: *std.Io.Writer,
    +        data: []const []const u8,
    +        splat: usize,
    +    ) std.Io.Writer.Error!usize {
    +        const self: *WhitespaceDetector = @alignCast(@fieldParentPtr("writer", w));
    +        const rest = data[0 .. data.len - 1];
    +        const pattern = data[data.len - 1];
    +        var written: usize = pattern.len * splat;
    +        for (rest) |bytes| written += bytes.len;
    +
    +        if (!self.found) {
    +            for (rest) |bytes| {
    +                if (std.mem.indexOfAny(u8, bytes, &std.ascii.whitespace) != null) {
    +                    self.found = true;
    +                    return written;
    +                }
    +            }
    +            if (splat != 0 and std.mem.indexOfAny(u8, pattern, &std.ascii.whitespace) != null)
    +                self.found = true;
    +        }
    +
    +        return written;
    +    }
    +};
    +
    +test WhitespaceDetector {
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeAll("no-whitespace-here");
    +        try std.testing.expect(!wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeAll("hello world");
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeAll("end ");
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeAll(" start");
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.print("value={d}", .{42});
    +        try std.testing.expect(!wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.print("value = {d}", .{42});
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.print("value={s}", .{"hello world"});
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeByte('\t');
    +        try std.testing.expect(wd.found);
    +    }
    +    {
    +        var wd: WhitespaceDetector = .init();
    +        try wd.writer.writeByte('\n');
    +        try std.testing.expect(wd.found);
    +    }

    5a2fffe99a58b5bbd13860a0a1da0b33a291987b

    dnut dnut commented on code on Jul 17, 2026 03:30 UTC
    Code Review
    v2/lib/telemetry/log.zig:1
    @@ -839,3 +821,100 @@ test Iso8601Fmt {
     inline fn isComptimeKnown(value: anytype) bool {
         return @typeInfo(@TypeOf(.{value})).@"struct".fields[0].is_comptime;
     }
    +
    +/// Discards all data written to it, but tracks whether any whitespace character
    +/// (per `std.ascii.whitespace`) was ever written. Unbuffered: every write goes
    +/// through `drain`, so `found` is up-to-date without needing to flush.
    +pub const WhitespaceDetector = struct {
    +    writer: std.Io.Writer,
    +    found: bool,
    +
    +    pub fn init() WhitespaceDetector {
    +        return .{
    +            .writer = .{
    +                .vtable = &.{ .drain = drain },
    +                .buffer = &.{},
    +            },
    +            .found = false,
    +        };
    +    }

    I don't see how using a buffer here could help. There's nothing expensive to amortize because it's a discarding writer. Using a buffer would introduce pointless copies for data that's being discarded. This also means that found won't be accurate until after calling flush. Accepting a buffer here just feels like a footgun to me.

    ajw221 ajw221 approved these changes on Jul 20, 2026 18:32 UTC
    Approved Reviewer

    Approved these changes.

    InKryption InKryption approved these changes on Jul 20, 2026 18:37 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    dnut dnut
    Labels
    risk: low confidence: 81.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.7% (MEDIUM) · Higher = larger blast radius
    46.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.5% · Lower = rushed or shallow review
    81.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 8.6% · Safe to merge
    8.6%
    Repository