Skip to content

[Docs]: Session Persistence Architecture Undocumented — Three Storage Layers with No Described Contract #580

Description

@hariom888

Summary

Description

Session state in rag-service/main.py is distributed across three distinct storage layers written by different code paths on different schedules:

Layer File Written by Frequency
Global snapshot data/sessions.json cleanup_expired_sessions On eviction/cleanup
Per-session metadata data/<session_id>/session_meta.json _flush_dirty_sessions background thread Every SESSION_FLUSH_INTERVAL_SECONDS
Session registry data/session_registry.json persist_session_registry_entry On upload + TTL update

load_sessions() reads all three layers and applies them in a specific order: sessions.json first, then session_meta.json as an authoritative overlay (chat + flashcards), with last_accessed used as a tiebreaker. None of this is documented anywhere — not in README.md, not in CONTRIBUTING.md, not in docstrings on the functions themselves.

A contributor who adds a new session field (e.g. a notes field) has no documented guidance on:

  • Which layer to write it to.
  • Whether to add it to _snapshot_session_for_persistence, save_sessions_unlocked, or persist_session_registry_entry.
  • What happens to the field on server restart if the flush interval hasn't fired.
  • How the field behaves during session recovery via _recover_session_unlocked.

This has already produced real inconsistencies: flashcards are stored in session_meta.json but not in session_registry.json; processing_progress is stored in the in-memory sessions dict but not flushed to any file; retrieval_cache is explicitly zeroed on persist but this decision is undocumented.

Affected Files

  • README.md — no architecture section
  • CONTRIBUTING.md — no data-layer guidance for contributors
  • rag-service/main.pyload_sessions, save_sessions_unlocked, _flush_dirty_sessions, _snapshot_session_for_persistence, persist_session_registry_entry, _recover_session_unlocked

Steps to reproduce

N/A

Expected behavior

N/A

Actual behavior

N/A

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocsDocumentation onlydocumentationImprovements or additions to documentationfeatureA new feature or improvementfixA targeted fix or cleanupfrontendFrontend-related workrag-serviceFastAPI / model service worktype:docstype:security

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions