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

Method load

atomic-agent/src/turn/session.rs:488–511  ·  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

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

Calls 3

validate_session_idFunction · 0.85
session_pathMethod · 0.80
kindMethod · 0.45