Skip to content

Commit c79b55d

Browse files
yotsudaclaude
andcommitted
refactor(busy-route): drop dead "old DLL null-cwd" fallback
Follow-up to a6ffe85. The version-lockstep connection guard (NamedPipeServer.cs's \`version_mismatch\` branch) refuses any proxy/DLL pair whose versions disagree, so a busy response that reaches PowerShellTools.cs is guaranteed to come from a same-version DLL — i.e. one that emits the \`cwd\` field. The "leave it null on older DLLs and we fall back to HOME" branch the prior commit added was structurally unreachable. Removed the intermediate \`sourceCwd\` local and the comment about old-DLL backward compatibility. Kept the \`Directory.Exists\` check because the cwd path itself can still be unreachable at runtime (deleted folder between snapshot and spawn, disconnected network drive) — that's a different class of edge case from version skew and the HOME fallback there is a real safety net for spawn success. Updated the \`Cwd\` field's docstring on \`GetStatusResponse\` to explain the field is nullable solely because \`Directory.GetCurrentDirectory\` can throw on a disconnected drive (so the DLL emits null), not because old DLLs might omit it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a6ffe85 commit c79b55d

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

PowerShell.MCP.Proxy/Models/JsonRpcModels.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ public class GetStatusResponse
8484
/// response — busy / user_command / mcp_command / standby /
8585
/// completed. Used by the busy-auto-route path so a freshly-spawned
8686
/// console can land at the same cwd before re-running the AI's
87-
/// pipeline. Null on older DLLs that predate the field.
87+
/// pipeline. Nullable only because <c>Directory.GetCurrentDirectory</c>
88+
/// can throw on a disconnected network drive — the version-lockstep
89+
/// connection guard rules out the "old DLL didn't send the field"
90+
/// case at the wire level.
8891
/// </summary>
8992
[JsonPropertyName("cwd")]
9093
public string? Cwd { get; set; }

PowerShell.MCP.Proxy/Tools/PowerShellTools.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,20 @@ public static async Task<string> InvokeExpression(
351351
// exact same call, with the new console at HOME (= losing
352352
// the cwd the user/AI had been working in). Two
353353
// round-trips and a manual `Set-Location` for every busy
354-
// race. Now: read the source's cwd from the busy
355-
// response (DLL emits `cwd` from the get_status path),
356-
// start the new console there, and run the pipeline as a
357-
// single recursive call. The DLL has emitted `cwd` since
358-
// a recent compatible version; older DLLs leave it null
359-
// and we fall back to HOME (= the old behavior).
360-
var sourceCwd = jsonResponse.Cwd;
361-
var startLoc = (!string.IsNullOrEmpty(sourceCwd) && Directory.Exists(sourceCwd))
362-
? sourceCwd
354+
// race.
355+
//
356+
// The version-lockstep connection guard (see
357+
// NamedPipeServer.cs's `version_mismatch` branch) means
358+
// any DLL that survived the handshake speaks the same
359+
// protocol as this proxy, so jsonResponse.Cwd is always
360+
// populated for busy responses — no "null because old
361+
// DLL" case to handle. Directory.Exists IS still checked
362+
// because the cwd path itself can be unreachable at
363+
// runtime (deleted folder, disconnected network drive);
364+
// in that genuine edge case we fall back to HOME so the
365+
// spawn can at least succeed.
366+
var startLoc = (!string.IsNullOrEmpty(jsonResponse.Cwd) && Directory.Exists(jsonResponse.Cwd))
367+
? jsonResponse.Cwd
363368
: Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
364369

365370
Console.Error.WriteLine($"[INFO] Runspace busy ({jsonResponse.Reason}), auto-routing to new console at {startLoc}...");

0 commit comments

Comments
 (0)