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:
Mika Kuns
2026-09-02 14:26:56 +02:00
parent 20685827fb
commit 81a5fc5d33
7 changed files with 110 additions and 18 deletions
@@ -3,6 +3,7 @@ using ClaudeDo.Data.Git;
using ClaudeDo.Data.Models;
using ClaudeDo.Data.Repositories;
using ClaudeDo.Worker.Config;
using ClaudeDo.Worker.External;
using ClaudeDo.Worker.Planning;
using ClaudeDo.Worker.Runner;
using ClaudeDo.Worker.Skills;
@@ -72,11 +73,12 @@ public sealed class InteractiveLaunchSpecServiceTests : IDisposable
=> Task.FromResult<IReadOnlyList<SessionSkillEntity>>(Installed);
}
private InteractiveLaunchSpecService BuildService() =>
private InteractiveLaunchSpecService BuildService(HandoffRoundTracker? handoffRounds = null) =>
new(_db.CreateFactory(), _seeder, _registry,
new WorktreeManager(new GitService(), _db.CreateFactory(), new WorkerConfig(), NullLogger<WorktreeManager>.Instance),
new GitService(),
new WorkerConfig { ClaudeBin = _claudeStubPath });
new WorkerConfig { ClaudeBin = _claudeStubPath },
handoffRounds ?? new HandoffRoundTracker());
private async Task<string> SeedListAsync(string? workingDir = null, string name = "L")
{
@@ -1043,7 +1045,13 @@ public sealed class InteractiveLaunchSpecServiceTests : IDisposable
var beforeCount = await CountTasksAsync();
var svc = BuildService();
// In production, HandoffMcpTools.HandoffListHandler calls Register BEFORE the hub asks
// this service to build the spec -- simulate that here so the brief's round info is
// demonstrably read from HandoffRoundTracker, not recomputed.
var tracker = new HandoffRoundTracker();
tracker.Register(handlerTaskId, nextPhase);
var svc = BuildService(tracker);
var spec = await svc.BuildForMergeHelperHandoffAsync(handlerTaskId, new[] { survivor }, nextPhase, CancellationToken.None);
var sessionDir = TrackSessionDir(spec);
@@ -1090,6 +1098,10 @@ public sealed class InteractiveLaunchSpecServiceTests : IDisposable
Assert.Contains(survivor, handoffBrief);
Assert.Contains("phase 3", handoffBrief, StringComparison.OrdinalIgnoreCase);
// Round info always names the current round and the total cap -- this is the ONE
// Register call above, so round 1 of MaxHandoffs.
Assert.Contains($"round 1 of {HandoffRoundTracker.MaxHandoffs}", handoffBrief);
if (expectFinalNote)
{
Assert.Contains("FINAL round", handoffBrief);