core: document lock ordering and usage in state module

This commit is contained in:
jimmyfraiture
2025-09-24 17:29:45 +01:00
parent 862c9e494b
commit d36bae194b
2 changed files with 14 additions and 7 deletions

View File

@@ -1058,9 +1058,10 @@ impl Session {
if let Ok(mut state) = self.state.try_lock() {
if let Ok(mut active) = self.active_turn.try_lock()
&& let Some(at) = active.as_mut()
&& let Ok(mut ts) = at.turn_state.try_lock() {
ts.clear_pending();
}
&& let Ok(mut ts) = at.turn_state.try_lock()
{
ts.clear_pending();
}
if let Some(task) = state.current_task.take() {
task.abort(TurnAbortReason::Interrupted);
}

View File

@@ -1,8 +1,14 @@
//! Session/turn state module scaffolding.
//! Session/turn state module.
//!
//! This module will encapsulate all mutable state for a Codex session.
//! It starts with lightweight placeholders to enable incremental refactors
//! without changing behaviour.
//! Encapsulates all mutable state for a Codex session and the currently active
//! turn. The goal is to present lock-safe, narrow APIs so other modules never
//! need to poke at raw mutexes or internal fields.
//!
//! Locking guidelines
//! - Lock ordering: `SessionState` → `ActiveTurn` → `TurnState`.
//! - Never hold a lock across an `.await`. Extract minimal data and drop the
//! guard before awaiting.
//! - Prefer helper methods on these types rather than exposing fields.
mod session;
mod turn;