refactor: remove redundant autonomous turn counter reset from ContinueTurnAsync

This commit is contained in:
copilot-swe-agent[bot]
2026-05-12 00:35:10 +00:00
committed by GitHub
Unverified
parent 0681e046ea
commit a47da4de3d
2 changed files with 5 additions and 7 deletions
@@ -342,12 +342,6 @@ internal sealed class HandoffAgentExecutor :
skipAddIncoming: true).ConfigureAwait(false);
}
// Reset the counter when ending the turn (handoff requested or turn limit reached).
// This also covers the case where the turn is interrupted by outstanding requests:
// the counter is reset at the start of the next HandleAsync call, but we still
// clean up here on a normal turn exit for clarity.
this._autonomousModeTurnCount = 0;
HandoffState outgoingState = new(state.IncomingState.TurnToken, result.HandoffTargetId, this._agent.Id);
await context.SendMessageAsync(outgoingState, cancellationToken).ConfigureAwait(false);
@@ -242,7 +242,11 @@ public class HandoffAgentExecutorTests : AIAgentHostingExecutorTestsBase
public async Task Test_HandoffAgentExecutor_AutonomousMode_InvokesAgentUpToTurnLimitPlusOne(int turnLimit)
{
// Arrange: agent with many prepared turns; no handoff ever requested; autonomous mode ON
int totalTurns = turnLimit + 2; // More turns prepared than the limit to detect over-invocation
// We prepare (turnLimit + 2) turns so that if the implementation over-invokes by one,
// TestReplayAgent.Turn will be (turnLimit + 2) rather than the expected (turnLimit + 1).
// TestReplayAgent does NOT increment Turn when it runs out of prepared messages, so preparing
// exactly (turnLimit + 1) would make an extra invocation silently undetectable.
int totalTurns = turnLimit + 2;
TestReplayAgent agent = new(
Enumerable.Range(0, totalTurns)
.Select(i => TestReplayAgent.ToChatMessages($"Turn {i} response"))