← Back to Pull requests

fix(transport): clear stale _exit_error on reconnect and close #1528

Open
unknown opened this pull request with 306 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 14, 2026 07:02 UTC
Author

Fixes #1517

Summary

SubprocessCLITransport.connect() sets self._exit_error in its failure handlers (missing cwd, missing CLI, and generic spawn failures) while self._process remains None, leaving stale error state in two places:

  • Reconnect after failed connect(): A subsequent connect() attempt did not reset self._exit_error up front—causing a successful retry to set self._ready = True while every write() raised CLIConnectionError citing the stale error from the earlier failed attempt, and causing a retry that failed pre-spawn (_find_cli(), _reject_windows_batch_cli(), _build_command()) or was cancelled mid-spawn to retain the earlier attempt's _exit_error.

  • close() after failed connect(): close() returned early at if not self._process: before reaching self._exit_error = None, leaving _exit_error populated even after an explicit await transport.close().
  • Changes:

  • Clear self._exit_error = None at the start of connect() immediately after if self._process: return (connect() remains a no-op when self._process is already set, preserving any recorded _exit_error on an unclosed exited process).

  • Clear self._exit_error = None in the if not self._process: early-return branch of close() so close() has consistent postconditions whether or not a subprocess was spawned.
  • Test plan

  • Added TestReconnectClearsStaleExitError in tests/test_transport.py (9 tests):

  • - Parametrized across all three connect() spawn failure modes (missing_cwd, missing_cli, spawn_error) followed by a successful retry and write()
    - Consecutive failed connect() attempts (missing_cwd -> missing_cli -> PermissionError) replacing _exit_error on each retry before a successful reconnect and write()
    - Retries that fail before open_process() (_build_command() settings load failure) or unwind on cancellation (CancelledError mid-spawn) clearing the prior _exit_error rather than retaining stale state
    - close() after a failed connect() clears _exit_error
    - connect() no-op when _process is already set preserves _exit_error on an unclosed errored process
    - End-to-end real subprocess repro (test_reconnect_after_missing_cwd_real_subprocess, skipped on win32)
  • ruff check src/ tests/ scripts/ and ruff format --check src/ tests/ scripts/

  • mypy src/ scripts/

  • pytest tests/: 1737 passed, 6 skipped
  • Diff: 306 lines (+229 / -77) across 3 files Reviewer: tonydzi Review duration: 23980m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 306 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.343
    Real PR Conversation Timeline
    1 comments
    "Review active on #1528"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.2% (MEDIUM) · Higher = larger blast radius
    40.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.4% · Safe to merge
    21.4%