REQ-LOOP-002: Bounded loop termination with synthetic completion that carries the run’s last real output

← Requirements

What it requires

  1. Given max_iterations = N and a model that never completes, When run_loop executes, Then metrics.iterations == N, state == COMPLETE, metadata["terminal_reason"] == "budget_exhausted", and a synthetic assistant message is the last message.
  2. Given a run whose turns produced real content, When the cap is hit, Then the last assistant message contains that content AND the cap annotation, and metadata["cap_carried_content"] == "true".
  3. Given a run whose every turn was empty, When the cap is hit, Then the last assistant message says no substantive output was produced and metadata["cap_carried_content"] == "false".
  4. Given a relay-tier lead whose single delegate is capped, When the child loop ends, Then the relayed summary is tagged "[partial" AND contains the child's own output, and the ON_DELEGATE_COMPLETE payload still reports success=false, the target tier, and result_kind="delegation_failed".
  5. Given a per-identity max_iterations override lower than the global LoopConfig value, When the loop runs, Then the override caps it.
  6. Given a model that repeats an identical tool call, When the duplicate counter reaches 3, Then should_stop() halts the loop.
tier
NOT_RUN

Where it lives

  • src/core6

See it on the map

How it is met

implemented byresults (92 tests)finish_with_carried_outputforce_iteration_cap_completionloopresolve_max_iterationsrunshould_stop92 absent92 tests, a summary by result: every test is in the tests table below

Show on the map

Implemented by

Tests (92)

Reached through calls

92 tests: 92 absent

testresultlinked byimplementers exercisedcalls away
Basic response contains no special tokensabsentinferred6 of 61
Batch generation worksabsentinferred6 of 61
Circuit breaker limits tool calls per turnabsentinferred6 of 61
Compaction fires when context exceeds thresholdabsentinferred6 of 61
Compaction triggers at thresholdabsentinferred6 of 61
Context accumulates across turnsabsentinferred6 of 61
Context anchors persist across runsabsentinferred6 of 61
Delegation directive triggers child loopabsentinferred6 of 61
Delegation wiring fires on_delegation_start callbackabsentinferred6 of 61
Dynamic identity creation and generation through engine loopabsentinferred6 of 61
Empty response handled gracefullyabsentinferred6 of 61
Engine state transitions include PLANNING and EXECUTINGabsentinferred6 of 61
Finish reason length continues loopabsentinferred6 of 61
Generate is called exactly once per iterationabsentinferred6 of 61
Hooks fire in correct order during a generation cycleabsentinferred6 of 61
Interrupt stops loopabsentinferred6 of 61
MCP authorization denial propagates through engineabsentinferred6 of 61
Max iterations stops loopabsentinferred6 of 61
Metrics accurate after runabsentinferred6 of 61
Multi-turn engine calls retain contextabsentinferred6 of 61
Root conversation created at run() init when storage wired (gh#48)absentinferred6 of 61
Route callback is invoked for tier selectionabsentinferred6 of 61
Routing fires on_tier_selected callbackabsentinferred6 of 61
Single iteration completesabsentinferred6 of 61
Single-turn engine loop produces coherent responseabsentinferred6 of 61
State transitions IDLE->PLANNING->EXECUTING->COMPLETEabsentinferred6 of 61
Streaming generation worksabsentinferred6 of 61
Streaming interrupt propagates to backend cancel chain absentinferred6 of 61
Tier routing fires callbackabsentinferred6 of 61
Tool call cycle: generate, parse, execute, generateabsentinferred6 of 61
Tool call cycle: generate, parse, execute, regenerateabsentinferred6 of 61
True end-to-end: real prompts, real engine, real modelabsentinferred6 of 61
a context-overflow refusal fails the turn instead of retrying itabsentinferred6 of 61
gh#105: constitutional validator's toolless render must NOT clobber absentinferred6 of 61
gh#111: a tool call whose arg carries raw UTF-8 is preserved, not absentinferred6 of 61
gh#111: raw UTF-8 in backend-cleaned content is sanitized before it absentinferred6 of 61
gh#121: zero-tool-call correction names tier's actual toolsabsentinferred6 of 61
gh#123 part 1: zero-tool-call counter resets after genuine tool call progressabsentinferred6 of 61
gh#158: two concurrent runs accumulate metrics safelyabsentinferred6 of 61
gh#160: an isolated delegation never writes the project, and absentinferred6 of 61
gh#162: a delegate seeded with context answers from the named absentinferred6 of 61
gh#183: a fresh top-level run still clears a stale interruptabsentinferred6 of 61
gh#183: a tier's identity overrides reach a top-level runabsentinferred6 of 61
gh#209/#212: a turn that ends in ERROR records why, for the callerabsentinferred6 of 61
gh#80: a tool call resets the budget windowabsentinferred6 of 61
gh#80: budget off (default) does not gate a tool-call-free spiralabsentinferred6 of 61
gh#80: tokens budget nudges then hard-cuts a tool-call-free spiralabsentinferred6 of 61
gh#84: a successful tool call DOES reset the budgetabsentinferred6 of 61
gh#84: rejected-duplicate tool calls do NOT reset the budgetabsentinferred6 of 61
gh#88: a gemma multi-turn session never accumulates a parrotable absentinferred6 of 61
hook dispatch: info / PRE_GENERATE cancel / POST_GENERATE rewrite / ON_ERRORabsentinferred6 of 61
last_loop_metrics populated after runabsentinferred6 of 61
misc accessors: pause / context_usage / idle / project_dirabsentinferred6 of 61
queue capacity / cap mutation / clear / observer / state slotabsentinferred6 of 61
set_storage wiring covers init_session_conversation pathsabsentinferred6 of 61
should_auto_chain false when no locked tierabsentinferred6 of 61
v2.14.6: a lead that answers in prose is nudged, and its forced absentinferred6 of 61
v2.14.6: after a nudge, a tier that owes a tool call is forced to make oneabsentinferred6 of 61
v2.14.6: an empty turn is retried, never accepted as completeabsentinferred6 of 61
v2.14.6: the model's own tool call stays in the history it is shownabsentinferred6 of 61
v2.14.6: with thinking on, each loop turn ends in a real tool callabsentinferred6 of 61
validation_provider variants are all non-fatalabsentinferred6 of 61
zero-tool-call with explicit_completion halts within retry capabsentinferred6 of 61
v2.14.6: after a prose answer is nudged, the forced retry may only absentinferred6 of 62
Budget-exhausted forced complete sets terminal_reason metadataabsentinferred5 of 62
auto_chain child sets COMPLETE at depth > 0absentinferred5 of 62
auto_chain does not fire without configabsentinferred5 of 62
auto_chain root fires tier change at depth 0absentinferred5 of 62
budget_exhausted child is relayed partial to lead (E2)absentinferred5 of 62
delegation guards reject depth/cycle/repeat/pipeline-depthabsentinferred5 of 62
delegation snapshot + per-tier metrics accumulationabsentinferred5 of 62
gh#111: a delegation whose child produces raw UTF-8 content does not absentinferred5 of 62
gh#119: delegation auto-complete folds child summary into lead's absentinferred5 of 62
gh#123 part 2: zero-tool-call ceiling is per-tier configurableabsentinferred5 of 62
gh#123 part 3: prose-only nudge turn does NOT set failure_reason in metadataabsentinferred5 of 62
gh#123 part 4: ChildContextInfo.max_consecutive_empty_turns_override wired through engineabsentinferred5 of 62
gh#162: resume by target picks that tier's latest delegationabsentinferred5 of 62
gh#169: a capped loop carries its last real content, annotatedabsentinferred5 of 62
gh#169: a capped loop that produced nothing stays distinguishableabsentinferred5 of 62
gh#169: the parent relay receives the capped child's real workabsentinferred5 of 62
gh#181: a hard cut with nothing substantive stays distinguishableabsentinferred5 of 62
gh#181: a thinking-budget hard cut carries the run's real contentabsentinferred5 of 62
gh#181: the parent relay receives the hard-cut child's real workabsentinferred5 of 62
gh#77: entropic.complete is terminal when emitted with sibling pipelineabsentinferred5 of 62
gh#81: interrupt during tool processing halts before pending dispatchabsentinferred5 of 62
gh#81: run_loop(inherit_interrupt=false) clears a stale interruptabsentinferred5 of 62
gh#81: run_loop(inherit_interrupt=true) preserves a pre-set interruptabsentinferred5 of 62
gh#84 combined: should_stop halts the loop when the duplicate absentinferred5 of 62
gh#88 combined: process_tool_results defangs a meta {action} absentinferred5 of 62
max_iterations override caps loop before global limitabsentinferred5 of 62
resume_delegation failure paths surface typed errorsabsentinferred5 of 62
gh#182: a model-supplied max_turns bounds the delegated childabsentinferred5 of 63