Skip to content

Make subprocess stderr routing an explicit policy (#340)#372

Draft
leynos wants to merge 1 commit into
issue-339-decouple-process-from-clifrom
issue-340-stderr-mode-policy
Draft

Make subprocess stderr routing an explicit policy (#340)#372
leynos wants to merge 1 commit into
issue-339-decouple-process-from-clifrom
issue-340-stderr-mode-policy

Conversation

@leynos

@leynos leynos commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #340

Replaces the suppress_stderr boolean with the named policy type the issue proposes:

pub enum StderrMode {
    Forward,
    Suppress,
}
  • The runner selects the policy from CLI state in ninja_process_options (the only place that consults Cli::resolved_diag_json(); the process layer stopped calling it in Decouple runner process execution from Cli (#339) #371).
  • NinjaProcessOptions, run_command_and_stream, and spawn_and_stream_output consume the policy.
  • Under Suppress, child stderr is still drained but discarded, so JSON diagnostics keep stderr machine-readable exactly as before.

Stacked on #371 (designed together per #347); retargets to main automatically once #371 merges.

Validation

  • make check-fmt / make lint / make test — pass (37 suites; JSON-diagnostics BDD scenarios unchanged and green)

🤖 Generated with Claude Code

Summary by Sourcery

Introduce an explicit stderr routing policy for subprocesses and wire it through the runner and process layers.

Enhancements:

  • Replace the boolean stderr suppression flag with a StderrMode enum to make subprocess stderr handling explicit and self-describing.
  • Propagate the new stderr routing policy through NinjaProcessOptions and subprocess execution helpers so JSON diagnostics can suppress child stderr while still draining it.

Diagnostic JSON mode was threaded into process execution as a bare
boolean that silently changed child stderr forwarding, leaking a
reporting decision into subprocess transport handling.

Replace the flag with a named `StderrMode` policy (`Forward` /
`Suppress`). The runner chooses the policy from CLI state at the
orchestration boundary (`ninja_process_options`); the process layer
only consumes it. Under `Suppress`, child stderr is still drained but
discarded, keeping stderr machine-readable for JSON diagnostics
exactly as before.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 22c8a6a6-bd96-43ef-99e5-d3db5c1fdb15

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-340-stderr-mode-policy

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai

sourcery-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Replace the boolean stderr suppression flag with an explicit StderrMode policy and thread it through the runner and process layers so stderr routing is decided at the runner boundary while preserving existing JSON-diagnostics behavior.

Sequence diagram for stderr_mode selection and routing

sequenceDiagram
    actor User
    participant Cli
    participant Runner
    participant Process

    User->>Cli: set resolved_diag_json()
    Runner->>Runner: ninja_process_options(cli)
    Runner->>Runner: set stderr_mode (Forward or Suppress)
    Runner->>Process: run_ninja_build_internal(request.options.stderr_mode)
    Process->>Process: run_command_and_stream(cmd, status_observer, stderr_mode)
    Process->>Process: spawn_and_stream_output(child, status_observer, stderr_mode)
    alt [stderr_mode.is_suppressed()]
        Process->>Process: forward_child_output(stderr, io::sink(), stderr)
    else [not suppressed]
        Process->>Process: forward_child_output(stderr, io::stderr(), stderr)
    end
Loading

File-Level Changes

Change Details Files
Introduce StderrMode enum and replace suppress_stderr boolean throughout the subprocess pipeline.
  • Add StderrMode enum with Forward and Suppress variants plus helper is_suppressed() to express stderr routing policy.
  • Change NinjaProcessOptions to hold stderr_mode instead of a suppress_stderr boolean.
  • Update run_command_and_stream and spawn_and_stream_output signatures and internal logic to consume StderrMode and use is_suppressed() when deciding whether to forward or discard stderr.
src/runner/process/mod.rs
Select stderr routing policy in the runner based on CLI JSON diagnostics mode and pass it into process options.
  • Derive stderr_mode in ninja_process_options from Cli::resolved_diag_json(), mapping JSON mode to Suppress and non-JSON mode to Forward.
  • Propagate stderr_mode through run_ninja_build_internal and run_ninja_tool_internal calls instead of the old suppress_stderr flag.
src/runner/mod.rs

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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