Single-turn-loop guard misses the sub-agent and RLM loops; the RLM loop is unlogged, drops history and returns an empty answer
Author: HmbownCreated Sep 24, 2026Updated Sep 30, 2026
Found in a repo-wide legacy / second-authority sweep (2026-09-23). Line references are at ccdd6a6d7.
- What's wrong:
crates/core/tests/single_turn_loop.rsdetects a model call by identifier suffix (stream | create_message | completion | complete,:91). Two loops dodge it by spelling:- Sub-agents call
request_subagent_model_response_with_retries((HEADtools/subagent/mod.rs:12707, called at:13510). This is #6504's loop. - RLM calls
client.create_message_boxed((rlm/turn.rs:353).
- Sub-agents call
- User impact: CI says "exactly one turn loop" while three exist, so the guard gives false assurance. The file's own header says "A guard satisfied by spelling is satisfied by accident."
- Fix: match the call by prefix
create_message*/request_*model*, or better, by theLlmClienttrait method set. Then add the sub-agent and RLM entries toALLOWED_TURN_LOOPSwith their issues (#6504, and finding 7) until they converge. - Issue: none. #6504 doesn't mention the guard.
- What's duplicated:
rlm/turn.rsis its own turn loop with its own prompt (rlm/prompt.rs), history policy and caps. - Evidence:
- The only live entry is the recursive sub-RLM path from the Python REPL (
rlm/bridge.rs:465-500). Its events go to a drain task (:474-481, "we don't surface them"), so the nested model calls never reach the session log. - The public
run_rlm_turnandrun_rlm_turn_with_root(turn.rs:100, 122) have 0 callers. MAX_RLM_ITERATIONS = 25(:28).MAX_HISTORY_MESSAGES = 20(:40) silently drops the middle of the history (:645-650, 697-701), with no compaction.- On exhaustion it returns
answer: String::new()afterlet _ = last_response_text;(:704-718). The final partial answer is discarded, which contradicts theRlmTerminationdocs (:54-57).
- The only live entry is the recursive sub-RLM path from the Python REPL (
- User impact: the user pays for up to 25 hidden model calls per sub-RLM, which may come back empty, and there is no record of them.
- Fix:
- Return
last_response_textonExhausted. - Forward nested events instead of draining them, so they are logged.
- Delete the two dead public entry points.
- Bound by the turn wall clock (
turn_timeout()already exists) instead of a count.
- Return
- Issue: none found.
2026-09-30 takeover: g1 claims the remaining parent deadline and durable nested-event receipt work for #6511/C07-C14, exact paths crates/tui/src/rlm/{bridge,turn}.rs, tools/{spec,rlm}.rs, core/engine.rs and core/engine/turn_loop.rs. Existing ToolResult/output persistence and shared usage accumulator remain the authority; no second event store. Source checkpoint 6e892c0 on e30a5a6c2. Focused tests pending; not yet complete.
Source: Hmbown/CodeWhale