Skip to content

fix(session): prevent concurrent cross-process writes - #1839

Merged
limityan merged 1 commit into
GCWing:mainfrom
limityan:yanzhn/session-single-writer
Jul 29, 2026
Merged

fix(session): prevent concurrent cross-process writes#1839
limityan merged 1 commit into
GCWing:mainfrom
limityan:yanzhn/session-single-writer

Conversation

@limityan

@limityan limityan commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Ensure one native BitFun Runtime process writes a persisted Session at a time while allowing different Sessions in the same workspace to run independently.
  • Keep SessionManager as the only Session lifecycle owner and reuse one OS file-lock implementation for Runtime ownership, Session writes, and serialized updates to the shared Session index.
  • Make create/restore fail before publishing writable in-memory state, clean unfinished Session directories after cancellation, and keep transient or ephemeral Sessions out of persistence.

Behavior

Scenario Result
Another process opens the same storage root and Session ID Fails immediately with session_in_use; no polling or automatic takeover
Different Session IDs in the same workspace Writers run independently; shared index updates are serialized
Path aliases resolve to the same storage root Use the same writer identity
Same Session ID under different storage roots File locks are independent; one SessionManager still keeps one active binding per Session ID
Create/restore fails, is cancelled, or times out No writable Session is published; temporary lock and unfinished directory are released
Save/unload/delete fails The loaded Session keeps its writer ownership
Unload/delete succeeds or the process exits The OS lock is released; a stale lock file alone does not block recovery
List/view and non-persistent Sessions Remain lock-free for Session writer ownership

Scope

  • No new public SDK method, Server route, Shared Runtime protocol, background process, or CLI-to-SDK-Host dependency.
  • Agent SDK, BitFun ACP, and Shared TUI retain a structured session_in_use classification. SDK Host exposes the existing retryable action_required; GUI, Embedded TUI, and Headless CLI continue to show an explicit text error without promising a structured field.
  • Desktop acting as an ACP client manages external-agent Session records outside this native Runtime Session lifecycle and is intentionally not included.
  • Durable behavior is documented in the existing runtime deployment architecture document; no PR-specific plan is committed.

Validation

Check Result
cargo check --locked --workspace Passed
cargo test --locked -p bitfun-core -p bitfun-desktop Passed after the latest-main rebase: Core 1608 unit tests plus integration suites; Desktop 193 tests
bitfun-services-core Passed: 86 unit tests plus all Session/index/write-lock contract suites
bitfun-acp / bitfun-cli Passed: 109 / 377 tests
Agent Runtime, SDK Host, and SDK Host app suites Passed
Core boundary checker and its 16 self-tests Passed
Repository hygiene and git diff --check Passed
Independent full-PR architecture and product reviews P0/P1/P2: 0

@limityan
limityan force-pushed the yanzhn/session-single-writer branch 2 times, most recently from 3d8cc76 to fed3f9a Compare July 29, 2026 04:52
@limityan
limityan force-pushed the yanzhn/session-single-writer branch from fed3f9a to 01e8edf Compare July 29, 2026 06:30
@limityan
limityan merged commit 97d66a7 into GCWing:main Jul 29, 2026
7 checks passed
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.

1 participant