fix(transport): clear stale _exit_error on reconnect and close #1528
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
tonydzi
Fixes #1517
Summary
SubprocessCLITransport.connect()setsself._exit_errorin its failure handlers (missing cwd,missing CLI, and generic spawn failures) whileself._processremainsNone, leaving stale error state in two places:connect(): A subsequentconnect()attempt did not resetself._exit_errorup front—causing a successful retry to setself._ready = Truewhile everywrite()raisedCLIConnectionErrorciting 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 failedconnect():close()returned early atif not self._process:before reachingself._exit_error = None, leaving_exit_errorpopulated even after an explicitawait transport.close().Changes:
self._exit_error = Noneat the start ofconnect()immediately afterif self._process: return(connect()remains a no-op whenself._processis already set, preserving any recorded_exit_erroron an unclosed exited process).self._exit_error = Nonein theif not self._process:early-return branch ofclose()soclose()has consistent postconditions whether or not a subprocess was spawned.Test plan
TestReconnectClearsStaleExitErrorintests/test_transport.py(9 tests):- Parametrized across all three
connect()spawn failure modes (missing_cwd,missing_cli,spawn_error) followed by a successful retry andwrite()- Consecutive failed
connect()attempts (missing_cwd->missing_cli->PermissionError) replacing_exit_erroron each retry before a successful reconnect andwrite()- Retries that fail before
open_process()(_build_command()settings load failure) or unwind on cancellation (CancelledErrormid-spawn) clearing the prior_exit_errorrather than retaining stale state-
close()after a failedconnect()clears_exit_error-
connect()no-op when_processis already set preserves_exit_erroron an unclosed errored process- End-to-end real subprocess repro (
test_reconnect_after_missing_cwd_real_subprocess, skipped onwin32)ruff check src/ tests/ scripts/andruff format --check src/ tests/ scripts/mypy src/ scripts/pytest tests/: 1737 passed, 6 skipped