Skip to content

Commit 34aa199

Browse files
authored
chore: handle all cases for EventMsg (#936)
For now, this removes the `#[non_exhaustive]` directive on `EventMsg` so that we are forced to handle all `EventMsg` by default. (We may revisit this if/when we publish `core/` as a `lib` crate.) For now, it is helpful to have this as a forcing function because we have effectively two UIs (`tui` and `exec`) and usually when we add a new variant to `EventMsg`, we want to be sure that we update both.
1 parent 497c539 commit 34aa199

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

codex-rs/core/src/protocol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ pub struct Event {
298298
}
299299

300300
/// Response event from the agent
301-
#[non_exhaustive]
302301
#[derive(Debug, Clone, Deserialize, Serialize)]
303302
#[serde(tag = "type", rename_all = "snake_case")]
304303
pub enum EventMsg {

codex-rs/core/tests/live_agent.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ async fn live_streaming_and_prev_id_reset() {
9999
EventMsg::Error(ErrorEvent { message }) => {
100100
panic!("agent reported error in task1: {message}")
101101
}
102-
_ => (),
102+
_ => {
103+
// Ignore other events.
104+
}
103105
}
104106
}
105107

@@ -135,7 +137,9 @@ async fn live_streaming_and_prev_id_reset() {
135137
EventMsg::Error(ErrorEvent { message }) => {
136138
panic!("agent reported error in task2: {message}")
137139
}
138-
_ => (),
140+
_ => {
141+
// Ignore other events.
142+
}
139143
}
140144
}
141145

@@ -201,7 +205,9 @@ async fn live_shell_function_call() {
201205
EventMsg::Error(codex_core::protocol::ErrorEvent { message }) => {
202206
panic!("agent error during shell test: {message}")
203207
}
204-
_ => (),
208+
_ => {
209+
// Ignore other events.
210+
}
205211
}
206212
}
207213

codex-rs/core/tests/previous_response_id.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ async fn keeps_previous_response_id_between_tasks() {
155155
EventMsg::Error(ErrorEvent { message }) => {
156156
panic!("unexpected error: {message}")
157157
}
158-
_ => (),
158+
_ => {
159+
// Ignore other events.
160+
}
159161
}
160162
}
161163
}

codex-rs/exec/src/event_processor.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use codex_core::protocol::McpToolCallBeginEvent;
1212
use codex_core::protocol::McpToolCallEndEvent;
1313
use codex_core::protocol::PatchApplyBeginEvent;
1414
use codex_core::protocol::PatchApplyEndEvent;
15+
use codex_core::protocol::SessionConfiguredEvent;
1516
use owo_colors::OwoColorize;
1617
use owo_colors::Style;
1718
use shlex::try_join;
@@ -180,8 +181,6 @@ impl EventProcessor {
180181
}
181182
println!("{}", truncated_output.style(self.dimmed));
182183
}
183-
184-
// Handle MCP tool calls (e.g. calling external functions via MCP).
185184
EventMsg::McpToolCallBegin(McpToolCallBeginEvent {
186185
call_id,
187186
server,
@@ -372,8 +371,12 @@ impl EventProcessor {
372371
EventMsg::ApplyPatchApprovalRequest(_) => {
373372
// Should we exit?
374373
}
375-
_ => {
376-
// Ignore event.
374+
EventMsg::AgentReasoning(agent_reasoning_event) => {
375+
println!("thinking: {}", agent_reasoning_event.text);
376+
}
377+
EventMsg::SessionConfigured(session_configured_event) => {
378+
let SessionConfiguredEvent { session_id, model } = session_configured_event;
379+
println!("session {session_id} with model {model}");
377380
}
378381
}
379382
}

codex-rs/mcp-server/src/codex_tool_runner.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,23 @@ pub async fn run_codex_tool_session(
157157
EventMsg::SessionConfigured(_) => {
158158
tracing::error!("unexpected SessionConfigured event");
159159
}
160-
_ => {}
160+
EventMsg::Error(_)
161+
| EventMsg::TaskStarted
162+
| EventMsg::AgentReasoning(_)
163+
| EventMsg::McpToolCallBegin(_)
164+
| EventMsg::McpToolCallEnd(_)
165+
| EventMsg::ExecCommandBegin(_)
166+
| EventMsg::ExecCommandEnd(_)
167+
| EventMsg::BackgroundEvent(_)
168+
| EventMsg::PatchApplyBegin(_)
169+
| EventMsg::PatchApplyEnd(_) => {
170+
// For now, we do not do anything extra for these
171+
// events. Note that
172+
// send(codex_event_to_notification(&event)) above has
173+
// already dispatched these events as notifications,
174+
// though we may want to do give different treatment to
175+
// individual events in the future.
176+
}
161177
}
162178
}
163179
Err(e) => {

0 commit comments

Comments
 (0)