feat(worker): surface the handoff round budget in the merge-helper handoff brief
A handler session only learned the chain was capped when handoff_list_handler threw at the end of its work, stranding open tasks. The round count already lived in HandoffRoundTracker the whole time -- it just never reached the brief. InteractiveLaunchSpecService now reads HandoffRoundTracker.GetState (read-only, doesn't advance the round) and renders round N of MaxHandoffs plus the remaining count into the handoff brief, replacing the old one-line finalNote. The rejection error also names the next action (start a new handler run) instead of just failing.
This commit is contained in:
@@ -198,6 +198,63 @@ public sealed class HandoffMcpToolsTests : IDisposable
|
||||
secondSut.HandoffListHandler(handlerTask.Id, survivors, "wait", CancellationToken.None));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 3)]
|
||||
[InlineData(2, 2)]
|
||||
[InlineData(4, 0)]
|
||||
public void HandoffRoundTracker_GetState_ReportsCountAfterNRegistrations(int registrations, int expectedRemaining)
|
||||
{
|
||||
var tracker = new HandoffRoundTracker();
|
||||
var taskId = Guid.NewGuid().ToString();
|
||||
|
||||
for (var i = 0; i < registrations; i++)
|
||||
tracker.Register(taskId, "wait");
|
||||
|
||||
var (count, sealedState) = tracker.GetState(taskId);
|
||||
Assert.Equal(registrations, count);
|
||||
Assert.Equal(expectedRemaining, HandoffRoundTracker.MaxHandoffs - count);
|
||||
Assert.False(sealedState);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandoffRoundTracker_GetState_UnregisteredTask_ReturnsZero()
|
||||
{
|
||||
var tracker = new HandoffRoundTracker();
|
||||
var (count, sealedState) = tracker.GetState(Guid.NewGuid().ToString());
|
||||
Assert.Equal(0, count);
|
||||
Assert.False(sealedState);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandoffRoundTracker_Register_DoesNotMutateStateVisibleFromGetState_BeyondItsOwnCall()
|
||||
{
|
||||
var tracker = new HandoffRoundTracker();
|
||||
var taskId = Guid.NewGuid().ToString();
|
||||
|
||||
tracker.Register(taskId, "wait");
|
||||
var (beforeCount, _) = tracker.GetState(taskId);
|
||||
Assert.Equal(1, beforeCount);
|
||||
|
||||
// GetState itself must be read-only -- calling it repeatedly must not advance the round.
|
||||
tracker.GetState(taskId);
|
||||
tracker.GetState(taskId);
|
||||
var (afterCount, _) = tracker.GetState(taskId);
|
||||
Assert.Equal(beforeCount, afterCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandoffRoundTracker_RejectedHandoff_ErrorNamesTheNextAction()
|
||||
{
|
||||
var tracker = new HandoffRoundTracker();
|
||||
var taskId = Guid.NewGuid().ToString();
|
||||
tracker.Register(taskId, "merge_final");
|
||||
|
||||
var result = tracker.Register(taskId, "wait");
|
||||
|
||||
Assert.True(result.Rejected);
|
||||
Assert.Contains("new handler run", result.Error, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandoffListHandler_TwoHandlerTasks_DoNotShareACounter()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user