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

Method load

atomic-agent/src/turn/session.rs:496–519  ·  view source on GitHub ↗

Load a session by ID. Returns `Ok(None)` if the session file doesn't exist (not an error). # Errors Returns `AgentError::SessionIdInvalid` if the ID contains path traversal characters. Returns `AgentError::SessionLoadFailed` if the file exists but can't be parsed.

(&self, session_id: &str)

Source from the content-addressed store, hash-verified

494 /// Returns `AgentError::SessionIdInvalid` if the ID contains path traversal characters.
495 /// Returns `AgentError::SessionLoadFailed` if the file exists but can't be parsed.
496 pub fn load(&self, session_id: &str) -> AgentResult<Option<AgentSession>> {
497 validate_session_id(session_id)?;
498
499 let path = self.session_path(session_id);
500
501 let data = match std::fs::read(&path) {
502 Ok(data) => data,
503 Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
504 Err(e) => {
505 return Err(AgentError::SessionLoadFailed {
506 session_id: session_id.to_string(),
507 reason: e.to_string(),
508 });
509 }
510 };
511
512 let session: AgentSession =
513 serde_json::from_slice(&data).map_err(|e| AgentError::SessionLoadFailed {
514 session_id: session_id.to_string(),
515 reason: format!("JSON parse error: {}", e),
516 })?;
517
518 Ok(Some(session))
519 }
520
521 /// Save a session to disk atomically.
522 ///

Calls 3

validate_session_idFunction · 0.85
session_pathMethod · 0.80
kindMethod · 0.45