Skip to content

Carry a redacted stderr excerpt on git command failures#4467

Open
yashranaway wants to merge 2 commits into
pingdotgg:mainfrom
yashranaway:git-error-stderr-excerpt
Open

Carry a redacted stderr excerpt on git command failures#4467
yashranaway wants to merge 2 commits into
pingdotgg:mainfrom
yashranaway:git-error-stderr-excerpt

Conversation

@yashranaway

@yashranaway yashranaway commented Jul 24, 2026

Copy link
Copy Markdown

What Changed

GitCommandError gains an optional stderrExcerpt carrying up to 400 characters of git's stderr, with command arguments and --option=value values redacted out first. The excerpt lives outside the error schema and outside message, so it is only visible to in-process consumers.

Why

Failed git commands recorded only stderrLength, so every precondition failure (branch already exists, stale worktree metadata, permissions, missing ref) collapsed into the same opaque "Git command exited with a non-zero status." and diagnosing meant rerunning the command by hand.

Dropping stderr from messages is clearly deliberate here: existing tests forbid stderr and argument content in message and in client-facing events. This change keeps all of those guarantees (the redaction test now also covers the excerpt, and a new test proves schema encoding excludes it) while giving server-side code a bounded signal to log or inspect. This is the fallback design suggested in the issue.

Fixes #4380

Testing

  • vp test run on GitVcsDriverCore, GitVcsDriver, and GitManager suites passes (105/105), including three new tests: excerpt present on a real failure, excerpt capped and argument-redacted, excerpt absent from schema encoding and from message
  • pnpm typecheck in apps/server and packages/contracts clean
  • vp lint on changed files clean

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Low Risk
Localized to git error construction and redaction; preserves existing guarantees that stderr and secrets do not appear in messages or RPC-encoded errors.

Overview
Adds an optional stderrExcerpt on GitCommandError so server-side code can see a short, redacted slice of git stderr when a command fails, without changing client-facing message or serialized error payloads.

attachGitStderrExcerpt in GitVcsDriverCore builds that excerpt: it redacts whole args (length ≥ 4) and --option=value values (any length), normalizes whitespace, caps at 400 characters, and attaches it only on the error instance. Both non-zero exit paths (executeRaw and executeGit) now run failures through this helper.

The field is declared on the class in packages/contracts but outside the Schema, so schema encoding still omits it. Tests cover real failures, redaction/capping, and that excerpts stay out of message and encoded errors.

Reviewed by Cursor Bugbot for commit 216d1b3. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Carry a redacted stderr excerpt on GitCommandError for in-process consumers

  • Adds an optional stderrExcerpt field to GitCommandError in git.ts; the field is intentionally excluded from the schema and error message so it never leaks to external consumers.
  • Introduces attachGitStderrExcerpt in GitVcsDriverCore.ts, which redacts argument values (above a 4-char minimum) and --option=value pairs from stderr, collapses whitespace, and caps the excerpt at 400 characters.
  • Both runGitCommand and executeGitWithStableDiagnostics now attach the excerpt to non-zero exit errors.
  • Risk: redaction is length-based, so short secrets under 4 characters are not redacted from the excerpt.

Macroscope summarized 216d1b3.

Failed git commands recorded only stderrLength, so every precondition
failure (branch exists, stale worktree metadata, permissions) collapsed
into the same opaque message and diagnosing required rerunning git by
hand.

GitCommandError now carries a bounded stderrExcerpt for in-process
consumers. Argument values are redacted from the excerpt and it stays
out of the error schema and message, so nothing new reaches RPC
clients, client events, or telemetry.

Fixes pingdotgg#4380
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b792ea39-2125-42c4-b361-9593c28f1b3c

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Jul 24, 2026
Comment thread apps/server/src/vcs/GitVcsDriverCore.ts
The length floor that keeps subcommand names readable also discarded
extracted option values shorter than four characters, so a short secret
in --option=value form could survive into the excerpt when stderr echoed
only the value. Apply the floor to whole arguments only and redact
extracted values at any length.
@macroscopeapp

macroscopeapp Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

This PR adds internal-only debugging info to Git command errors. The stderr excerpt is explicitly excluded from serialization (never reaches clients/telemetry), argument values are redacted to protect secrets, and comprehensive tests verify these security properties.

You can customize Macroscope's approvability policy. Learn more.

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

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git command errors discard stderr, making failures opaque to callers

1 participant