Skip to content

docs: document read-fresh guarantee in DefaultSessionStore#476

Merged
MervinPraison merged 2 commits into
mainfrom
claude/issue-474-20260602-1306
Jun 3, 2026
Merged

docs: document read-fresh guarantee in DefaultSessionStore#476
MervinPraison merged 2 commits into
mainfrom
claude/issue-474-20260602-1306

Conversation

@MervinPraison
Copy link
Copy Markdown
Owner

Fixes #474
Fixes #449

Summary

Documents the read-fresh guarantee changes from PraisonAI PR #1764 that ensure DefaultSessionStore reads always reload from disk under FileLock.

  • Extended Multi-Process Safety section with comprehensive read-fresh behavior documentation
  • Added Mermaid sequence diagram showing cross-instance communication with standard color scheme
  • Completed DefaultSessionStore methods table with 9 missing methods verified from source code
  • Added read-fresh guarantees note to persistence-json.mdx Cross-Platform Support section
  • Updated session-protocol.mdx with DefaultSessionStore improvements and custom store implementation tip
  • Added PR chronology to persistence overview concurrency section

Changes Made

docs/features/session-persistence.mdx

  • Extended Multi-Process Safety section to cover both reads and writes
  • Added sequence diagram showing FileLock behavior across store instances
  • Completed DefaultSessionStore Methods table with all verified methods
  • Added notes about invalidate_cache being no-op for reads

docs/features/persistence-json.mdx

  • Added note about read paths acquiring file locks and reloading from disk
  • Emphasizes no in-memory cache staleness for multiple workers

docs/features/session-protocol.mdx

  • Updated DefaultSessionStore card description to mention read-fresh guarantees
  • Added tip for custom store implementations about reading from backing store

docs/persistence/overview.mdx

  • Added paragraph completing PR chronology from #1709 through #1764
  • Documents evolution from write-side to read-side concurrency safety

Implementation Verified

All documentation changes are based on verified SDK source code:

  • Verified _load_session behavior (lines 265-283)
  • Verified _read_session_fresh implementation (lines 296-303)
  • Verified read methods route through fresh reload (lines 499, 505, 671)
  • Checked regression test test_get_chat_history_sees_other_store_instance (lines 446-458)

Generated with Claude Code

- Extended Multi-Process Safety section with read-fresh behavior details
- Added Mermaid sequence diagram showing cross-instance communication
- Completed DefaultSessionStore methods table with 9 missing methods
- Added cross-platform read-fresh note to persistence-json.mdx
- Updated session protocol with DefaultSessionStore improvements and custom store tip
- Added PR chronology to persistence overview concurrency section

All read methods (get_chat_history, get_session, get_sessions_by_agent)
now reload from disk under FileLock on every call, ensuring multi-process
safety without stale cache windows.

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 2, 2026 13:10
@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Warning

Review limit reached

@MervinPraison, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 52 minutes and 4 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f58fedeb-ed39-479e-9b77-04e0fe6be208

📥 Commits

Reviewing files that changed from the base of the PR and between 50cf8a7 and fd4469a.

📒 Files selected for processing (3)
  • docs/features/session-persistence.mdx
  • docs/features/session-protocol.mdx
  • docs/persistence/overview.mdx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-474-20260602-1306

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation to detail the multi-process safety improvements of the session store, explaining how both read and write paths now reload from disk under a file lock to prevent cache staleness. It also updates the API reference tables and adds a Mermaid sequence diagram. The review feedback points out that the Mermaid sequence diagram contains unsupported class definitions that will cause rendering errors, and suggests correcting a tip about the SessionStoreProtocol to avoid referencing methods that are not actually part of the protocol.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +167 to +173
classDef writer fill:#8B0000,stroke:#7C90A0,color:#fff
classDef reader fill:#8B0000,stroke:#7C90A0,color:#fff
classDef file fill:#189AB4,stroke:#7C90A0,color:#fff

class Writer writer
class Reader reader
class Disk file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Mermaid sequenceDiagram does not support classDef or class statements (which are used in flowcharts or class diagrams). Including them will cause a rendering error in GitHub and other Markdown viewers. These lines should be removed.

</Tip>

<Tip>
If your custom store backs onto shared storage (Redis, Postgres, S3, another file system), make `get_chat_history`, `get_session`, and `get_sessions_by_agent` read from that backing store on every call rather than caching in process memory. `DefaultSessionStore` guarantees this; downstream code such as `BotSessionManager._load_history` relies on it.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The SessionStoreProtocol only defines five core methods: add_message, get_chat_history, clear_session, delete_session, and session_exists. It does not define get_session or get_sessions_by_agent, nor does BotSessionManager or other downstream code rely on those methods being present in custom stores. This tip should be updated to only mention get_chat_history to avoid confusing developers implementing custom stores.

If your custom store backs onto shared storage (Redis, Postgres, S3, another file system), make get_chat_history read from that backing store on every call rather than caching in process memory. DefaultSessionStore guarantees this; downstream code such as BotSessionManager._load_history relies on it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the documentation to reflect the “read-fresh under FileLock” guarantee for DefaultSessionStore, ensuring multi-process/multi-instance users understand that key read APIs reload from disk and don’t serve stale in-memory cache data.

Changes:

  • Expanded multi-process safety docs to explicitly cover disk-fresh reads (plus a sequence diagram).
  • Updated protocol/custom-store guidance to encourage “read from backing store on each call” behavior.
  • Added/updated persistence docs to mention read-side locking/reload behavior and the PR chronology.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
docs/features/session-persistence.mdx Documents read-fresh guarantees, adds a Mermaid sequence diagram, and expands the DefaultSessionStore methods table.
docs/features/persistence-json.mdx Adds a cross-platform note clarifying that key read APIs lock + reload from disk each call.
docs/features/session-protocol.mdx Adds custom-store guidance and updates the DefaultSessionStore card to mention read-fresh behavior.
docs/persistence/overview.mdx Adds PR chronology text documenting evolution from write-side to read-side concurrency/read-fresh guarantees.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +91 to +93
<Tip>
If your custom store backs onto shared storage (Redis, Postgres, S3, another file system), make `get_chat_history`, `get_session`, and `get_sessions_by_agent` read from that backing store on every call rather than caching in process memory. `DefaultSessionStore` guarantees this; downstream code such as `BotSessionManager._load_history` relies on it.
</Tip>
<CardGroup cols={2}>
<Card icon="file" title="DefaultSessionStore">
JSON file-based persistence with atomic writes and file locking. Zero dependencies.
JSON file-based persistence with atomic writes and file locking. Zero dependencies. All mutating methods *and* read methods reload from disk inside the file lock, so multiple processes can safely share one session directory.
| `clear_session(session_id)` | Clear all messages |
| `delete_session(session_id)` | Delete session completely |
| `list_sessions(limit)` | List all sessions |
| `invalidate_cache(session_id)` | Drop the in-memory cache entry (no-op for reads; reads always reload) |
The session store uses file locking to ensure safe concurrent access:
The session store is safe under concurrent multi-process and multi-instance use on **both reads and writes**:

- **Atomic writes** — every mutator (`add_message`, `set_agent_info`, `set_gateway_info`, `clear_session`, `update_session_metadata`) reloads the session from disk inside `FileLock`, mutates, then atomically writes (temp file + `os.replace`). Concurrent writers cannot drop each other's messages.
These improvements were added in PraisonAI PR #1466 to ensure robust multi-threaded operation in production environments.
</Note>

The JSON session store (`DefaultSessionStore`) reloads from disk under `FileLock` for every mutator as of PR #1709 (metadata), PR #1724 (agent info, gateway info, clear), and PR #1727 (`LocalManagedAgent._persist_state`). PRs #1759 and #1764 extended the same `FileLock`-guarded reload to the read path (`get_chat_history`, `get_session`, `get_sessions_by_agent`), so two processes pointed at the same `~/.praisonai/sessions/` directory observe each other's writes without any stale-cache window.
@MervinPraison MervinPraison merged commit 96fe861 into main Jun 3, 2026
1 check was pending
@MervinPraison MervinPraison deleted the claude/issue-474-20260602-1306 branch June 3, 2026 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants