@@ -96,6 +96,13 @@ private func formatByteSize(_ value: Double) -> String? {
9696 return ByteCountFormatter.string(fromByteCount: Int64(value), countStyle: .file)
9797}
9898
99+private func formatByteSize(_ value: Int) -> String? {
100+ // A negative byte count isn't meaningful; `ByteCountFormatter` would render it
101+ // as a bogus "-1 KB"/"Zero KB" string, so drop it like the `Double` path does.
102+ guard value >= 0 else { return nil }
103+ return ByteCountFormatter.string(fromByteCount: Int64(value), countStyle: .file)
104+}
105+
99106struct StreamStats: Codable, Sendable {
100107 let ingestion: IngestionStats?
101108 let storage: StorageStats?
@@ -118,7 +125,7 @@ struct StreamStats: Codable, Sendable {
118125 if let s = try? container.decode(String.self, forKey: .size) {
119126 self.size = s
120127 } else if let n = try? container.decode(Int.self, forKey: .size) {
121− self.size = ByteCountFormatter.string(fromByteCount: Int64(n), countStyle: .file)
128+ self.size = formatByteSize(n)
122129 } else if let d = try? container.decode(Double.self, forKey: .size) {
123130 self.size = formatByteSize(d)
124131 } else {
@@ -127,7 +134,7 @@ struct StreamStats: Codable, Sendable {
127134 if let s = try? container.decode(String.self, forKey: .lifetime_size) {
128135 self.lifetime_size = s
129136 } else if let n = try? container.decode(Int.self, forKey: .lifetime_size) {
130− self.lifetime_size = ByteCountFormatter.string(fromByteCount: Int64(n), countStyle: .file)
137+ self.lifetime_size = formatByteSize(n)
131138 } else if let d = try? container.decode(Double.self, forKey: .lifetime_size) {
132139 self.lifetime_size = formatByteSize(d)
133140 } else {
@@ -151,7 +158,7 @@ struct StreamStats: Codable, Sendable {
151158 if let s = try? container.decode(String.self, forKey: .size) {
152159 self.size = s
153160 } else if let n = try? container.decode(Int.self, forKey: .size) {
154− self.size = ByteCountFormatter.string(fromByteCount: Int64(n), countStyle: .file)
161+ self.size = formatByteSize(n)
155162 } else if let d = try? container.decode(Double.self, forKey: .size) {
156163 self.size = formatByteSize(d)
157164 } else {
@@ -160,7 +167,7 @@ struct StreamStats: Codable, Sendable {
160167 if let s = try? container.decode(String.self, forKey: .lifetime_size) {
161168 self.lifetime_size = s
162169 } else if let n = try? container.decode(Int.self, forKey: .lifetime_size) {
163− self.lifetime_size = ByteCountFormatter.string(fromByteCount: Int64(n), countStyle: .file)
170+ self.lifetime_size = formatByteSize(n)
164171 } else if let d = try? container.decode(Double.self, forKey: .lifetime_size) {
165172 self.lifetime_size = formatByteSize(d)
166173 } else {