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

Method handle_turn_start

atomic-agent/src/turn/orchestrator/turn.rs:37–112  ·  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

35 ///
36 /// Begins file watching and transitions the session to Active.
37 pub(super) async fn handle_turn_start(
38 &mut self,
39 event: TurnEvent,
40 ) -> AgentResult<DispatchResult> {
41 let session_id = &event.session_id;
42
43 let mut session = self.load_or_create_session(session_id, &event)?;
44 let turn_number = session.turn_count.saturating_add(1);
45 if session.managed_run.is_none() || self.managed_run.is_some() {
46 self.resume_journal_turn(session_id, turn_number, event.timestamp.timestamp())?;
47 }
48 self.commit_hook_event(&event, turn_number)?;
49
50 // Store the prompt
51 if let Some(ref prompt) = event.prompt {
52 session.set_first_prompt(prompt);
53 }
54
55 // Update transcript path
56 if let Some(ref path) = event.transcript_path {
57 session.set_transcript_path(path);
58 }
59
60 // Extract model/provider from raw_json if present.
61 // OpenCode sends: {"model": "claude-opus-4-5", "provider": "anthropic", ...}
62 // This is the most reliable source of model info — it comes from the
63 // chat.message hook which fires at the start of every turn.
64 if let Some(ref raw) = event.raw_json {
65 if let Some(model) = raw.get("model").and_then(|v| v.as_str()) {
66 if !model.is_empty() {
67 session.model = model.to_string();
68 }
69 }
70 if let Some(provider) = raw.get("provider").and_then(|v| v.as_str()) {
71 if !provider.is_empty() {
72 session.agent_vendor = provider.to_string();
73 }
74 }
75 }
76
77 // Begin file watching for this turn
78 if let Err(e) = self.watcher.begin_turn(session_id).await {
79 log::warn!(
80 "Failed to begin file watching for session {}: {}",
81 session_id,
82 e
83 );
84 // Continue anyway — we'll just miss file changes
85 }
86
87 // Mark the turn as started in the session
88 session.begin_turn();
89
90 // State machine transition
91 let result = phase::transition(
92 session.phase,
93 Event::TurnStart,
94 TransitionContext::default(),

Callers 1

dispatchMethod · 0.80

Calls 15

transitionFunction · 0.85
apply_common_actionsFunction · 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
getMethod · 0.65
timestampMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected