.NET: Dotnet: reset $LASTEXITCODE per command in persistent PowerShell sessions - #8259
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Consecutive native commands returning the same nonzero code cause the second command to report success.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates persistent PowerShell exit-code handling to avoid stale results across commands.
Changes:
- Tracks prior
$LASTEXITCODEand captures$?before flushing. - Adds a Windows regression test for cmdlet-only commands.
File summaries
| File | Description |
|---|---|
ShellSession.cs |
Revises PowerShell exit-code detection. |
LocalShellExecutorTests.cs |
Adds persistent-session coverage. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 8cf7359c7cb3
Model: gpt-5.6-sol-fast
Overview
The PR snapshots $LASTEXITCODE, captures $? before flushing, and adds a regression test that preserves stale-code readback while preventing a later cmdlet from inheriting it. Command serialization, PowerShell-only branching, exception handling, and sentinel parsing constrain the change well. However, the value-comparison heuristic cannot distinguish stale state from a new native command returning the same nonzero code, so repeated failures can be reported as success.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 high) across 1 file. Details are attached to the affected lines below.
Affected areas: dotnet/src/Microsoft.Agents.AI.Tools.Shell/ShellSession.cs
Clear the persistent automatic variable before invoking each command so repeated native failures with the same exit code are reported correctly. Update the Windows regression test to cover repeated failures and reset readback semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Motivation & Context
Dotnet equivalent of #8206
Description & Review Guide
Related Issue
Fixes #
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.