Skip to content

Include an inhibitor helper's stderr when it exits immediately [patch] - #40

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/15-helper-stderr
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/15-helper-stderr

Conversation

@matt-edmondson

Copy link
Copy Markdown
Collaborator

Fixes #15

What changed

ChildProcessHold.Start sent the helper's stderr to a no-op handler. A helper that failed during the 250 ms startup grace period (for example gnome-session-inhibit with no GNOME session manager, or a polkit denial for systemd-inhibit) was reported only as exited immediately with code N.

  • While the helper starts up, stderr lines go into a small locked buffer (StartupErrorOutput). It keeps the last 4 KB, counting the joining spaces, and drops the oldest lines first, since the final lines usually give the reason.
  • When the helper exits within the grace period, the untimed WaitForExit() now runs as well. This makes sure the async stderr reader has delivered its last lines before the message is built. The message becomes … exited immediately with code 1. It reported: <stderr>. If the helper wrote nothing, the message is unchanged.
  • Once startup succeeds, recording stops. A long-running helper keeps having its stderr drained and dropped as before, so the buffer can't grow.

Tests

  • Start_WhenTheHelperExitsImmediately_IncludesItsStandardErrorInTheMessage runs /bin/sh -c "echo boom >&2; exit 1" and checks for boom (this is the issue's acceptance case).
  • Start_WhenTheHelperFloodsStandardError_KeepsOnlyTheLastOfItInTheMessage writes about 9 KB of filler and then the reason. It checks that the reason is kept, the oldest output is dropped, and the message stays bounded.
  • With the source change reverted, both new tests fail. With it applied, the full suite passes (31/31). Off Unix they are inconclusive, like the existing ChildProcessHold tests.

Generated by Claude Code

ChildProcessHold drained the helper's stderr into a no-op handler, so a
helper that failed during the startup grace period was reported only by
exit code. Keep the last 4 KB of stderr while the helper starts, wait for
the streams to finish after it exits, and add what it wrote to the
SleepBlockException message. Recording stops once startup succeeds.

Fixes #15

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4SLyvTvUJUdcrUu7F
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

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.

"Inhibitor helper exited immediately with code N" discards the helper's own stderr explaining why

2 participants