MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / handle_turn_start

Method handle_turn_start

atomic-agent/src/turn/orchestrator/turn.rs:68–198  ·  view source on GitHub ↗

Handle a TurnStart event (UserPromptSubmit). Begins file watching and transitions the session to Active.

(
        &mut self,
        event: TurnEvent,
    )

Source from the content-addressed store, hash-verified

66 ///
67 /// Begins file watching and transitions the session to Active.
68 pub(super) async fn handle_turn_start(
69 &mut self,
70 event: TurnEvent,
71 ) -> AgentResult<DispatchResult> {
72 let session_id = &event.session_id;
73
74 let mut session = self.load_or_create_session(session_id, &event)?;
75 let turn_number = session.turn_count.saturating_add(1);
76 if session.managed_run.is_none() || self.managed_run.is_some() {
77 self.resume_journal_turn(session_id, turn_number, event.timestamp.timestamp())?;
78 }
79 self.commit_hook_event(&event, turn_number)?;
80
81 // Store the prompt
82 if let Some(ref prompt) = event.prompt {
83 session.set_first_prompt(prompt);
84 }
85
86 // Update transcript path
87 if let Some(ref path) = event.transcript_path {
88 session.set_transcript_path(path);
89 }
90
91 // Extract model/provider from raw_json if present.
92 // OpenCode sends: {"model": "claude-opus-4-5", "provider": "anthropic", ...}
93 // This is the most reliable source of model info — it comes from the
94 // chat.message hook which fires at the start of every turn.
95 if let Some(ref raw) = event.raw_json {
96 if let Some(model) = raw.get("model").and_then(|v| v.as_str()) {
97 if !model.is_empty() {
98 session.model = model.to_string();
99 }
100 }
101 if let Some(provider) = raw.get("provider").and_then(|v| v.as_str()) {
102 if !provider.is_empty() {
103 session.agent_vendor = provider.to_string();
104 }
105 }
106 }
107
108 // Begin file watching for this turn
109 if let Err(e) = self.watcher.begin_turn(session_id).await {
110 log::warn!(
111 "Failed to begin file watching for session {}: {}",
112 session_id,
113 e
114 );
115 // Continue anyway — we'll just miss file changes
116 }
117
118 // CB-12A: capture the durable turn-start boundary (RFC §10.1).
119 //
120 // Pure observation — never reconciles, interprets or materializes
121 // (RFC §12.1/§12.2; reconciliation stays in repository command
122 // boundaries). A failed capture leaves the baseline absent, and the
123 // turn-end classification then refuses to claim ObservationOnly.
124 match atomic_repository::Repository::open_readonly(&self.repo_root) {
125 Ok(repo) => {

Callers 1

dispatchMethod · 0.80

Calls 15

capture_turn_boundaryFunction · 0.85
transitionFunction · 0.85
apply_common_actionsFunction · 0.85
drain_watch_noticeFunction · 0.85
is_noneMethod · 0.80
resume_journal_turnMethod · 0.80
commit_hook_eventMethod · 0.80
set_first_promptMethod · 0.80
set_transcript_pathMethod · 0.80
set_boundary_startMethod · 0.80
load_accumulatorMethod · 0.80

Tested by

no test coverage detected