Skip to content

docs: update Session Hierarchy page with concurrency-safety guarantees#478

Open
MervinPraison wants to merge 1 commit into
mainfrom
claude/issue-477-20260602-1346
Open

docs: update Session Hierarchy page with concurrency-safety guarantees#478
MervinPraison wants to merge 1 commit into
mainfrom
claude/issue-477-20260602-1346

Conversation

@MervinPraison
Copy link
Copy Markdown
Owner

Summary

Updates docs/features/session-hierarchy.mdx with comprehensive concurrency safety documentation following PR #1790 in the main PraisonAI repository.

  • Agent-centric Quick Start example (per AGENTS.md rule 9)
  • Hero Mermaid sequence diagram showing fork/message race scenario
  • New Concurrency & Safety section listing all thread-safe operations
  • Realistic user interaction flow with threading example
  • Mintlify components: Steps, AccordionGroup, CardGroup
  • Updated frontmatter with sidebarTitle and improved description
  • How It Works section with visual flow diagram
  • Progressive disclosure and user-friendly tone per AGENTS.md standards

Key Changes

Concurrency Safety: Documents that all mutating methods on HierarchicalSessionStore now use locked read-modify-write operations, ensuring chat messages added concurrently are never lost during fork/snapshot/revert operations.

User-Focused: Follows AGENTS.md requirement to start with agent-centric examples and provide copy-paste runnable code.

Visual Learning: Includes Mermaid diagrams using standard color scheme to help users understand both the race condition scenario and the internal locking flow.

Fixes #477

Generated with Claude Code

fixes #477)

- Add agent-centric Quick Start with Agent example first
- Include hero Mermaid sequence diagram showing concurrent fork/message scenario
- Add Concurrency & Safety section listing all thread-safe operations
- Provide realistic user interaction flow example with threading
- Use Mintlify components (Steps, AccordionGroup, CardGroup)
- Update frontmatter with sidebarTitle and improved description
- Add How It Works section with visual flow diagram
- Follow AGENTS.md standards for progressive disclosure and user-friendly tone

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
@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 12 minutes and 1 second. 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: 8cc4a528-2871-4bfe-8233-ffb22c20a6a8

📥 Commits

Reviewing files that changed from the base of the PR and between aa7ace5 and b5e4073.

📒 Files selected for processing (1)
  • docs/features/session-hierarchy.mdx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-477-20260602-1346

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 Session Hierarchy documentation to include sequence diagrams, quick start guides, concurrency safety details, a threading example, and best practices. The review feedback identifies three key issues: first, the Mermaid sequence diagram uses unsupported class directives that will cause rendering errors; second, the concurrency safety claims are inaccurate because operations like fork_session do not hold the file lock for the entire read-modify-write cycle; and third, the provided threading example is unsafe and prone to race conditions where messages can be lost.

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 +30 to +36
classDef user fill:#8B0000,stroke:#7C90A0,color:#fff
classDef agent fill:#189AB4,stroke:#7C90A0,color:#fff
classDef store fill:#10B981,stroke:#7C90A0,color:#fff

class User user
class Agent,ForkWorker agent
class Store store
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 sequence diagrams do not support classDef or class directives. Including them will cause rendering errors in Mintlify/Mermaid. Please remove these lines to ensure the diagram renders correctly.

Comment on lines +85 to +96
Every mutation goes through a locked read-modify-write, so chat messages added in one process are never lost when another process forks, snapshots, reverts, shares, or retitles the same session.

| Operation | Safe with concurrent `add_message`? |
|---|---|
| `create_session(parent_id=...)` | Yes |
| `fork_session()` | Yes |
| `create_snapshot()` | Yes |
| `revert_to_snapshot()` | Yes |
| `revert_to_message()` | Yes |
| `share_session()` / `unshare_session()` | Yes |
| `set_title()` | Yes |
| `add_message()` | Yes (#1745) |
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 documentation states that operations like fork_session, create_snapshot, revert_to_snapshot, etc., are safe under concurrent add_message writes. However, looking at the implementation in praisonaiagents/session/hierarchy.py, these methods release the file lock between loading and saving the session (unlike add_message which uses _modify_session_locked to hold the lock for the entire read-modify-write cycle). This means concurrent writes can be overwritten and lost. Please update the documentation to accurately reflect this limitation.

Every mutation on HierarchicalSessionStore is not fully safe under concurrent writes. Only add_message uses a locked read-modify-write cycle that prevents data loss. Other operations like fork_session, create_snapshot, and revert_to_snapshot release the lock between loading and saving, which can lead to concurrent messages being overwritten and lost.

| Operation | Safe with concurrent add_message? |
|---|---|
| create_session(parent_id=...) | No |
| fork_session() | No |
| create_snapshot() | No |
| revert_to_snapshot() | No |
| revert_to_message() | No |
| share_session() / unshare_session() | No |
| set_title() | No |
| add_message() | Yes (#1745) |

Comment on lines +114 to +128
# Background job forks for experiment (concurrent with user)
import threading
def experiment():
fork_id = store.fork_session(session_id, title="Weather Analysis")
store.add_message(fork_id, "user", "Analyze historical patterns")

thread = threading.Thread(target=experiment)
thread.start()

# User sends another message during the fork
store.add_message(session_id, "user", "What about tomorrow?")

thread.join()
# Both messages survive: original session has both weather messages,
# fork has the pre-fork conversation only
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

This concurrent threading example is actually unsafe and prone to a race condition where the user's message "What about tomorrow?" can be lost. Because fork_session does not hold the file lock during its entire read-modify-write cycle, the concurrent add_message can be overwritten when fork_session saves the parent session back to disk. Please add a warning or modify the example to avoid concurrent mutations on the same session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: update Session Hierarchy page with concurrency-safety guarantees (PR #1790)

1 participant