fix(scan): isolate --json/--markdown output during reachability analysis#1371
Open
Martin Torp (mtorp) wants to merge 1 commit into
Open
fix(scan): isolate --json/--markdown output during reachability analysis#1371Martin Torp (mtorp) wants to merge 1 commit into
Martin Torp (mtorp) wants to merge 1 commit into
Conversation
Reachability spawned the Coana CLI with stdio: 'inherit', so Coana's progress/log output went to the parent's stdout and corrupted the machine-readable payload. Since 2>/dev/null only drops stderr, `socket scan create --reach --json` (and `socket scan reach --json`) could not be isolated to just the JSON the way a non-reach scan can. In json/markdown output modes, route the Coana child's stdout to the parent's stderr (fd 2) via the stdio array ['inherit', 2, 'inherit'] so the final JSON/markdown stays alone on stdout while progress stays visible on stderr. Text mode keeps inheriting stdout unchanged.
Benjamin Barslev Nielsen (barslev)
approved these changes
Jun 18, 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.
Problem
socket scan create --reach --json(andsocket scan reach --json) cannot have its output isolated to just the JSON payload. For a non-reach scan you can dosocket scan create --json 2>/dev/null, because the CLI sends all human-facing text (banner, spinner, progress, success/info/warn) to stderr and only the machine-readable result to stdout.Reachability analysis spawned the Coana CLI with
stdio: 'inherit', so Coana's progress/log output was wired straight to the parent's stdout and interleaved with the final JSON. Since2>/dev/nullonly drops stderr, there was no way to get a clean JSON stream. Coana's actual result is written to a file (--socket-mode/--output-dir), so its stdout is purely diagnostic noise.Fix
Make the Coana
stdiooutput-kind aware:'inherit'(unchanged; Coana streams to the terminal as before).['inherit', 2, 'inherit'], which redirects the Coana child's stdout to the parent's stderr (fd 2). stdin and stderr stay inherited.Result: in machine-readable modes the final
logger.log(...)payload is alone on stdout, Coana's progress stays visible on stderr, and2>/dev/nullnow isolates the JSON/markdown — matching the behavior of a non-reach scan. This is preferred over piping/capturing because it preserves real-time progress streaming.This relies only on standard Node stdio fd-sharing, already plumbed end-to-end through the dlx launcher, local-path, and npm-install spawn paths in
spawnCoanaDlx.Changes
src/commands/scan/perform-reachability-analysis.mts— addoutputKindoption; compute the stdio and pass it tospawnCoanaDlx(replacing the hardcoded'inherit').src/commands/scan/handle-create-new-scan.mts— passoutputKind(socket scan create --reach).src/commands/scan/handle-scan-reach.mts— passoutputKind(socket scan reach).src/commands/scan/perform-reachability-analysis.test.mts— 4 new tests asserting stdio routing (text/default →'inherit'; json/markdown →['inherit', 2, 'inherit']).Testing
pnpm check:tsc— cleaneslinton changed files — cleanpnpm test:uniton the reachability + both handler test files — 22/22 pass (2 pre-existing + 4 new)Note
Low Risk
Localized change to child-process stdio wiring for reach scans; text mode unchanged and behavior is covered by new tests.
Overview
Reachability scans with
--jsonor--markdownnow keep machine-readable output on stdout only, matching non-reach scan behavior.Coana was spawned with
stdio: 'inherit', so its progress/logs went to stdout and mixed with the CLI’s final JSON/markdown.performReachabilityAnalysisnow takesoutputKind(defaulttext) and passes'inherit'in text mode or['inherit', 2, 'inherit']in json/markdown so Coana’s stdout is redirected to the parent’s stderr. Callerssocket scan create --reachandsocket scan reachforwardoutputKind. Four unit tests assert the stdio passed tospawnCoanaDlx.Reviewed by Cursor Bugbot for commit 733b293. Configure here.