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

Method load

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

1007 /// Returns `AgentError::SessionIdInvalid` if the ID contains path traversal characters.
1008 /// Returns `AgentError::SessionLoadFailed` if the file exists but can't be parsed.
1009 pub fn load(&self, session_id: &str) -> AgentResult<Option<AgentSession>> {
1010 validate_session_id(session_id)?;
1011
1012 let path = self.session_path(session_id);
1013
1014 let data = match std::fs::read(&path) {
1015 Ok(data) => data,
1016 Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
1017 Err(e) => {
1018 return Err(AgentError::SessionLoadFailed {
1019 session_id: session_id.to_string(),
1020 reason: e.to_string(),
1021 });
1022 }
1023 };
1024
1025 let session: AgentSession =
1026 serde_json::from_slice(&data).map_err(|e| AgentError::SessionLoadFailed {
1027 session_id: session_id.to_string(),
1028 reason: format!("JSON parse error: {}", e),
1029 })?;
1030
1031 Ok(Some(session))
1032 }
1033
1034 /// Save a session to disk atomically.
1035 ///

Calls 4

validate_session_idFunction · 0.85
session_pathMethod · 0.80
readFunction · 0.50
kindMethod · 0.45