feat: round-limit handling — Continue affordance at the cap + configurable cap (#1999)

* feat: round-limit handling — Continue affordance at the cap + configurable cap

When the agent loop runs out of rounds (per-message step cap, default 20)
while still actively using tools, it stopped silently mid-task. Now:

1. The loop emits a `rounds_exhausted` SSE event at the cap, and the UI shows
   a "Continue" pill at the bottom of the chat that resumes the task from where
   it left off. Repeated cap-hits each get a fresh Continue (multiple continues
   in a row).
2. The cap is configurable in Settings → Agent ("Max steps per message"),
   validated on the client, at the save endpoint, and at the read site.

- src/agent_loop.py: track `_exhausted_rounds` (set only when a full
  tool-executing round completes on the last allowed round — i.e. the agent
  wanted to keep going); emit `{"type":"rounds_exhausted","rounds":N}` (logged).
- routes/chat_routes.py: read `agent_max_rounds` (clamped 1..200), pass as
  `max_rounds`; forward the new event through the SSE relay.
- routes/auth_routes.py: validate numeric settings on save (int + clamp;
  agent_max_rounds 1..200, agent_max_tool_calls 0..1000; 400 on non-int).
- src/settings.py: default `agent_max_rounds = 20`.
- static/: Settings input + client-side clamp; the Continue pill (reuses the
  existing .stopped-indicator / .continue-btn classes and theme vars
  --border/--fg/--bg/--accent); appended to the chat container so it survives
  the message re-render at stream finalize. chat.js cache version bumped.

* test: cover rounds_exhausted emission (cap-hit vs normal finish)

Drives the real stream_agent_loop with mocked LLM stream / tool exec / settings:
a tool block every round exhausts the cap and must emit rounds_exhausted; a
plain answer hits the done-break and must not. Guards the for/else logic.
This commit is contained in:
Kenny Van de Maele
2026-06-04 22:36:05 +02:00
committed by GitHub
parent a54f41037d
commit 64d65b73c1
9 changed files with 215 additions and 14 deletions
+32
View File
@@ -3478,6 +3478,38 @@ body.bg-pattern-sparkles {
.continue-btn:hover {
opacity:0.8;
}
/* Round-cap "Continue" affordance a cohesive centered pill at the chat
bottom (not the bare red in-message stopped style). */
.rounds-exhausted {
justify-content:center;
gap:12px;
width:fit-content;
max-width:90%;
margin:14px auto 4px;
padding:7px 8px 7px 16px;
border:1px solid var(--border);
border-radius:999px;
background:color-mix(in srgb, var(--fg) 4%, transparent);
opacity:1;
}
.rounds-exhausted .rounds-exhausted-label {
color:color-mix(in srgb, var(--fg) 60%, transparent);
font-size:0.95em;
}
.rounds-exhausted .continue-btn {
font-size:0.9em;
font-weight:600;
opacity:1;
color:var(--bg);
background:var(--accent, var(--red));
border-radius:999px;
padding:4px 14px;
line-height:1.3;
}
.rounds-exhausted .continue-btn:hover {
opacity:0.88;
}
.ctx-indicator {
display:inline-flex; align-items:center; gap:1px;
font-size:0.75rem;