mj_controller/
session_manager.rs1use std::collections::{BTreeMap, VecDeque};
4use std::path::PathBuf;
5use std::sync::{Arc, Mutex};
6use std::time::{Duration, Instant};
7
8use anyhow::{Context, Result, bail, ensure};
9use tokio::sync::{mpsc, oneshot, watch};
10
11use crate::database::{
12 ProjectionApplyOutcome, ProjectionIntegrityError, apply_projection_page,
13 save_materialized_session,
14};
15use crate::worker_client::{RelayClient, RelayEventPage, RelayRejected, RelayTransportDead};
16use mj_checkpoint::archive::verify_archive_streaming;
17use mj_core::credentials::{CredentialSyncSignal, relay_event_credential_sync_reason};
18use mj_core::elicitation::ElicitationResponse;
19use mj_core::state::{ManagedSessionSnapshot, MaterializedSession};
20use mj_transcript::projection::{
21 ProjectionIndex, apply_committed_projection_event_indexed, materialized_session_from_canonical,
22 project_relay_event_indexed,
23};
24
25use crate::targets::{
26 CancellableProcessExecutor, CommandExecutor, CommandPlan, CommandSpec, TargetLocator,
27 TargetRecoveryOutcome, TargetRecoveryPlan, ensure_recovery_target_running,
28};
29use mj_core::relay::{RelayCommand, RelayCursor, RelayOperationalState};
30
31pub use mj_client::session::{
32 ManagedSessionView, ReviewerAction, ReviewerOutcome, ViewError, new_command_id,
33};
34#[cfg(test)]
35use mj_core::worker_launch::ReviewerLaunchConfig;
36
37const SESSION_SYNC_INTERVAL: Duration = Duration::from_millis(150);
38const PROJECTION_TRANSACTION_EVENT_BUDGET: usize = 128;
42const RECONNECT_INTERVAL: Duration = Duration::from_secs(1);
43const RECONNECT_BACKOFF_CEILING: Duration = Duration::from_secs(30);
46const UNREACHABLE_FAILURE_THRESHOLD: u32 = 2;
47const WORKER_RESTART_TIMEOUT: Duration = Duration::from_secs(30);
48const WORKER_RESTART_COOLDOWN: Duration = Duration::from_secs(60);
49const SESSION_MANAGER_SHUTDOWN_GRACE: Duration = Duration::from_millis(750);
50
51mod types;
52pub use types::*;
53mod recovery;
54pub(crate) use recovery::*;
55mod channels;
56pub use channels::*;
57mod handle;
58pub use handle::*;
59mod client_backend;
60use client_backend::*;
61mod actor_types;
62use actor_types::*;
63mod remote;
64pub use remote::*;
65mod spawn;
66pub use spawn::*;
67mod actor;
68use actor::*;
69mod standalone;
70pub use standalone::*;
71
72#[cfg(test)]
73mod tests;