Concurrent PAI Sessions: Shared State Has No Concurrency Protection #841
Replies: 3 comments 2 replies
-
|
Great research! I've been multi-term'ing with 3 PAI in separate directories and notice a lot more claude.json corruptions (upstream). This seems like a semi-solved issue with your mitigation suggestions. I hope we can solve this at the root. |
Beta Was this translation helpful? Give feedback.
-
|
Regarding multi-device, I stumbled upon Happy Engineering (https://happy.engineering/), but does not seem to get updated... :-( |
Beta Was this translation helpful? Give feedback.
-
|
This is definitely something I'm seeing some. I heavily multi-session. Something that my PAI had a thought of, was to do a Another thought I just had, although not usable everywhere, but on Linux, potentially using D-Bus |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The Problem
PAI adds significant shared mutable state on top of Claude Code's
~/.claude/directory — memory files, task/team JSON, CLAUDE.md template rendering, learning signals, Algorithm state. None of it has file locking, atomic writes, or any concurrency protection.Running multiple PAI-enabled CC sessions simultaneously can corrupt or silently lose data. This is compounded by the fact that Claude Code itself has unresolved concurrency bugs in its own shared files.
This topic has surfaced repeatedly in this community from different angles — hook concurrency, session lifecycle, context integrity, multi-machine sync, parallel agents — but has never been mapped as a single systemic problem.
PAI-Specific Shared Mutable State at Risk
MEMORY/LEARNING/,MEMORY/RELATIONSHIP/, etc.~/.claude/tasks/{team}/~/.claude/teams/{team}/config.json~/.claude/CLAUDE.mdPAI/USER/PROJECTS/, learning signals, etc.Prior Discussions in This Community
This problem has been hit from multiple angles here, each addressed in isolation:
Issues
API Error: 400 due to tool use concurrency issueswhen PAI hooks fired concurrently. Maintainer response: "This is a Claude Code platform limitation, not something PAI can fix." The user had independently added a directive forcing sequential tool use as a workaround.SessionManagerclass with concurrent session limits (max 5), cleanup, and lifecycle tracking. Was part of a PAI-UI server batch — closed with that effort but the underlying need (session awareness) was never shipped to CLI users.Discussions
Upstream Claude Code Bugs (Open, Unfixed)
PAI inherits all of these — they affect the base layer:
.claude.jsoncorrupted by concurrent writes — 165 corrupted backups in 40 minSafety Tiers for Concurrent Use
Safe
One PAI session + one or more vanilla CC sessions in different directories — minimal shared state beyond
.claude.jsonand credentials (CC upstream risk only).Risky
Two PAI sessions in different directories — both write to shared
MEMORY/, both could enter Algorithm mode, both could update learning signals.Dangerous
Two PAI sessions in the same directory — all of the above plus project-scoped CLAUDE.md, session history, and project memory all collide. Two PAI sessions using agent teams — task and team JSON files have no locking whatsoever.
Possible Mitigations
Short-term (documentation + detection):
claudeprocess is detectedMedium-term (defensive writes):
rename()) for all PAI JSON and markdown files — process-safe on POSIXflock) around read-modify-write cycles for task/team filesLong-term (architectural):
Current Workaround
Run only one PAI session at a time. Secondary sessions should be vanilla CC (
claudewithout PAI hooks/context) in separate project directories.Researched and written by Claude (Opus 4.6), @virtualian's Viki, and Ian Marr.
Beta Was this translation helpful? Give feedback.
All reactions