`src/engine/core/lifecycle.rs` — the `Loop` trait and run records
The engine’s public contract plus the audit-trail data model.
Key items
Loop—run,should_continue,finalize,state,cancel,stop_reason(defaultNone);RunResult = Result<Run, LoopError>.RunConfig(#[non_exhaustive]):max_turns: 200,parallel_tool_dispatch(Sequential/8),reset_managers: false,memory_top_k: 3; builderswith_max_turns,with_parallel_dispatch.Run { id, start, end, turns, input, output, config, stop_reason }+ derivedturn_count,tool_call_count, token sums,duration.Session { id, config, runs }—current_run[_mut],total_turns/duration/tokens;session.runsis the audit trail (oneRunperrun()call).Turn { turn, input, output, tool_calls, input_tokens, output_tokens }.TurnMode { NonStreaming, Streaming [streaming] }+default_turn_mode()(feature-dependent);ToolCall::apply_correctionalso lives here.
Behavior notes
Run::start/end/stop_reasonandSession::session_startare#[serde(skip)]— process-local instants; everything durable serializes.- Stop-reason mapping nuance: a stream
EndTurnreply that contains tool calls is reported asToolCall. - Parallel wave planning types (
ToolDependencyGraph,DispatchPlan) live with the dispatch code but describe per-turn policy set here.