·5 min read
A stray PowerShell error turned my digest into 391 MB
DailyBrief is supposed to compress a day of work into a digest small enough to hand to a model. Then I measured one that was 391 MB. A script meant to produce a small JSON file had written something far larger, and the only symptom was the size of the file.
The cause was one line. In the same commit I fixed a second bug that had been hiding in plain sight: a function that was supposed to repair broken Georgian text and had never repaired a single character.
- Project
- DailyBrief
- Date
- Jul 2026
- Stack
- PowerShell 5.1, Electron, Node
- Commit
- 09a6bfc
What broke
The digest is built by core/kanban-check.ps1. It walks the active tasks, gathers evidence for each one (changed files, recent commits, the task's comments) and writes the result to a check-digest-<runid>.json file. The model later reads that file. The whole design of the app depends on that file being small, because every token in it is paid for.
The commit message records what I observed: a 391 MB digest file. That is not a model problem or a data problem. Something in the script was producing output I never asked for, and the JSON serializer was faithfully writing it all down.
The second bug was quieter. Early versions of the scripts had saved Georgian text through the wrong encoding, so Georgian words on the board came back as strings of accented Latin letters. I had already written fixMojibake in main.js to undo that. It runs inside readJson, on every JSON file the app loads. It still never repaired anything, and a function that does nothing looks exactly like data that was never broken.
What the code showed
In PowerShell, every statement in a block emits whatever it returns into the output stream, and a foreach used as an expression collects all of it. The digest tasks were built like this (simplified from kanban-check.ps1):
$digestTasks = @(foreach ($t in $activeTasks) {
# ... build one task object ...
& (Join-Path $base 'scan-folder.ps1') -TaskId ([string]$t.id) -Dir ([string]$dirs[0])
# ... more code, ending with the task object ...
})The call to scan-folder.ps1 was meant to be a side effect: it advances the baseline so the next check diffs from this moment. I never wanted its output. But anything that script emitted, including a stray .NET error record, went into $digestTasks as an extra element next to my task objects. Later, ConvertTo-Json -Depth 6 walked those elements. An error record is not a string, it is a graph: exception, invocation info, script stack trace, target object, and references back into the runtime. Serializing it to depth 6 produced the 391 MB file.
The Georgian bug had a different shape. The comment I wrote in the fixed version states the root cause: the corruption was a cp1252 decode, not latin1. Every Georgian letter in UTF-8 is three bytes, such as E1 83 90 for ა. The middle byte is always 0x82 or 0x83. In cp1252 the range 0x80 to 0x9F maps to characters like ƒ (U+0192), which are outside latin1. When my old code turned the text back into bytes with latin1, Node kept only the low byte of each character, produced invalid UTF-8, and the function's own safety check rejected the result. The guard worked perfectly. It protected English text from damage and also protected every corrupted Georgian string from repair.
The fix
Commit 09a6bfc (Jul 2026) changed kanban-check.ps1 by one line and a comment:
# $null = : this runs inside the $digestTasks foreach EXPRESSION.
# anything it emits (stray output, error records) would be captured
# into the array and ConvertTo-Json would serialize whole .NET
# object graphs into the digest.
$null = & (Join-Path $base 'scan-folder.ps1') -TaskId ([string]$t.id) -Dir ([string]$dirs[0]) 2>$null$null = throws away the success output, and 2>$null throws away the error stream, so neither can reach the array. The same commit changed .gitignore to cover the per-run check-digest-* and check-patch-* files, so these files stop turning up in the repo folder.
For the text repair I replaced the latin1 round trip with a proper cp1252 reverse table, 27 entries mapping characters like 0x0192 back to 0x83. The new fixMojibake works on each run of non-ASCII characters on its own, so a string that mixes clean Georgian with corrupted Georgian heals both parts. A run is replaced only if every character maps back to a byte and those bytes decode as clean multi-byte UTF-8. One more case had to be handled: the original corrupter had dropped bytes it could not map, such as 0x90, which leaves an incomplete sequence at the end. That last letter cannot be recovered, so the function strips it instead of keeping the garbage.
What I would do differently
I would not have trusted either bug to announce itself. The digest builder had no size check, and a script whose whole job is to be small should fail loudly when its output is not. A hard cap on the digest file, with an error in the log when it is exceeded, would have turned a silent 391 MB file into a visible failure on the first bad run.
I would also write a test for fixMojibake before shipping it, with one real corrupted Georgian string and its expected repair. The function had a safety check, and the check was the whole reason it did nothing. A single round trip on a real input would have shown that in a minute.
The habit I kept from this: in PowerShell, output is a side effect of every call, and in a script that feeds a model, an unbounded side effect is a cost bug.
Where this fits
This was one of several bugs that shaped DailyBrief's glue code in its first weeks, between PowerShell, Node and a headless Claude CLI. The full DailyBrief case study covers the whole pipeline, the lean runner and the other failures that real daily use produced.
See how the digest, the model call and the patch fit together, and what else went wrong along the way.
Read the full case study#powershell#debugging#encoding#electron
Keep reading
Have a project in mind?