Skip to content

fix(slop-diff): redirect slop-scan stdout to a file — piped capture truncates on large reports#2324

Open
Andy-Haigh wants to merge 1 commit into
garrytan:mainfrom
Andy-Haigh:fix/slop-diff-piped-stdout-truncation
Open

fix(slop-diff): redirect slop-scan stdout to a file — piped capture truncates on large reports#2324
Andy-Haigh wants to merge 1 commit into
garrytan:mainfrom
Andy-Haigh:fix/slop-diff-piped-stdout-truncation

Conversation

@Andy-Haigh

Copy link
Copy Markdown

Problem

scripts/slop-diff.ts captures npx slop-scan scan … --json via spawnSync pipes. slop-scan (0.3.0) emits its JSON report with async stdout writes and then exits without flushing, so whether the report survives depends entirely on the consumer's pipe-draining behavior:

Consumer Captured (same repo, real report = 536,666 bytes)
bun spawnSync 536,666 bytes ✓
node spawnSync (any maxBuffer) 8,192 bytes
shell pipe (… --json | wc -c) 65,536 bytes

Under bun run slop:diff the wrapper works today — by luck of bun's pipe implementation. Any node-based execution (running the script with tsx/node, CI runners, or ports of this wrapper into other repos) silently truncates: JSON.parse fails and the script reports "slop-scan returned invalid JSON" — or worse, the base scan silently parses as nothing and the diff runs against an empty baseline, marking every pre-existing finding as "new". I hit this porting the wrapper into a monorepo whose report is ~6.9 MB, where it fails 100% of the time under node.

Fix

Both scan sites go through one runSlopScan() helper that redirects the child's stdout to a temp file (stdio: ["ignore", fd, "pipe"]) and reads it back. File writes are synchronous, so the full report survives regardless of size, runtime, or slop-scan's exit behavior. Temp file is removed in finally. No behavior change otherwise.

Verification

  • Patched wrapper on this repo: full HEAD scan + merge-base worktree scan complete; delta over the branch's changed file reports no new findings (this fix adds no slop).
  • Same fd-redirect approach verified in a downstream port against a 6.9 MB report (previously: 8 KB truncation, 100% failure under node).

Note

The root cause is arguably in slop-scan itself (exit before flush — worth an upstream issue there too), but this wrapper-level fix makes slop-diff robust regardless of the CLI's version or the runtime it's executed with.

🤖 Generated with Claude Code

…uncates at 8KB

slop-scan@0.3.0 emits its JSON report via async stdout writes and then
calls process.exit(), so when stdout is a PIPE (spawnSync capture — this
wrapper), the report is truncated at the first ~8KB chunk. A full-repo
report is multi-MB, so both scans always failed JSON.parse and the /review
and /ship integration silently reported 'slop-scan returned invalid JSON'
(or, for the base scan, diffed against an empty baseline). File writes are
synchronous, so redirecting the child's stdout to a temp file yields the
complete report regardless of size.

Repro: npx slop-scan scan . --json | wc -c  → 8192 on any large repo,
while a shell file-redirect of the same command yields the full report.

Both scan sites now go through one runSlopScan() helper (fd-backed stdout,
temp file cleaned up in finally). Behavior otherwise unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Jul 22, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant