MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / _save_session

Method _save_session

src/server/agent_server.py:504–528  ·  view source on GitHub ↗

Persist the conversation to disk so it can be /resume'd. Best-effort, called at each turn end.

(self)

Source from the content-addressed store, hash-verified

502 self._emit({"type": "agent_progress", "session_id": self.session_id, **ev})
503
504 def _save_session(self) -> None:
505 """Persist the conversation to disk so it can be /resume'd. Best-effort,
506 called at each turn end."""
507 try:
508 if self.session is None:
509 return
510 msgs = self.session.conversation.messages
511 if not msgs:
512 return
513 d = _sessions_dir()
514 d.mkdir(parents=True, exist_ok=True)
515 payload = {
516 "session_id": self.session_id,
517 "model": getattr(self.provider, "model", None) or self.config.model or "",
518 "cwd": self.cwd,
519 "updated_at": time.time(),
520 "message_count": len(msgs),
521 "preview": _first_prompt_preview(msgs),
522 "name": self._session_name,
523 "conversation": self.session.conversation.to_dict(),
524 }
525 (d / f"{self.session_id}.json").write_text(json.dumps(payload), encoding="utf-8")
526 except Exception: # noqa: BLE001 — persistence must never break a turn
527 logger.debug("[agent-server] session save failed", exc_info=True)
528 self._record_knowledge()
529
530 @staticmethod
531 def _message_text(msg: object) -> str:

Callers 2

_run_turnMethod · 0.95

Calls 4

_record_knowledgeMethod · 0.95
_first_prompt_previewFunction · 0.85
_sessions_dirFunction · 0.70
to_dictMethod · 0.45

Tested by

no test coverage detected