Skip to content

Keep out-of-turn session edits from being overwritten by running turns - #76

Open
Telli wants to merge 7 commits into
claude/fervent-gates-uqka3bfrom
claude/fervent-gates-uqka3b-session-concurrency
Open

Telli wants to merge 7 commits into
claude/fervent-gates-uqka3bfrom
claude/fervent-gates-uqka3b-session-concurrency

Conversation

@Telli

@Telli Telli commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Stacked on #75. Merge that first; this PR's base then retargets to main.

Summary

A prompt turn saves an in-memory copy of the session that it read when it started. Edits made while it ran were silently reverted when it finished. Affected edits:

  • permissions revoke-trust (a revoked plugin became trusted again)
  • model and permission preferences
  • todo add/update/remove
  • plan summaries
  • work import

Separately, todo and plan commands took the turn lock. They therefore failed after about 10 s whenever a turn was running.

Approach

  • New store decorator. ConcurrencySafeSessionStore (in Sessions/Concurrency) wraps HostAwareSessionStore, so it covers both file and SQLite stores.
  • Out-of-turn writers run inside ISessionUpdateCoordinator.RunAsync. It holds a short per-session snapshot lock and records each metadata key (and the title) changed, as { start, latest }.
  • Every other save takes the same lock. For each recorded key:
    • If the saver still holds the start value, it has a stale copy, so the edit is carried forward.
    • If the saver changed the value deliberately (e.g. an in-turn todo sync that re-read the session), its value is kept and becomes the latest.
  • Turn boundaries. ConversationRuntime resets the overlay before its in-lock re-read and again after its final save. Its primary-mode and approval-settings saves now run inside the turn lock, on the fresh snapshot; before, they ran before the lock was taken.
  • Converted writers. SessionPreferenceService, WorkItemService, TodoService and PlanWorkflowService now use the scope instead of the turn lock. The new constructor parameters are optional, so existing direct constructions keep working.
  • Bundle export skips lock and overlay files. A locked .turn.lock could previously make the export fail.

Validation

  • dotnet build SharpClawCode.sln --configuration Release --warnaserror
  • dotnet test SharpClawCode.sln --configuration Release (unit 355, parity 20, integration 136; all passing)
  • Relevant package, CLI, MCP, plugin, and cross-platform checks were run. Only Linux was run; CI covers Windows and macOS.

New tests:

  • ConcurrencySafeSessionStoreTests: a stale save carries the edit forward; a deliberate newer change wins; removed keys and title changes are carried; reset starts a new window.
  • A todo edit completes while the turn lock is held.

Risk and compatibility

  • Durable JSON/session formats remain compatible or include a migration. The snapshot format is unchanged. Two new transient files appear in the session directory: .snapshot.lock and .metadata-overlay.json.
  • Dangerous file, shell, and network operations still pass through permissions.
  • No credentials, local state, or generated secrets are included.

Each session save now takes a short file lock. One limitation: a stale writer that deliberately sets a key back to its exact pre-edit value cannot be told apart from a stale copy, so the concurrent edit wins.


Generated by Claude Code

A prompt turn saves an in-memory session copy read at turn start, so trust
revocations, preference changes, todo edits, plan summaries, and work-item
imports made while it ran were silently reverted when it finished. Todo
and plan commands also took the turn lock and failed after ~10s whenever
a turn was running.

- Add a ConcurrencySafeSessionStore decorator and SessionUpdateScope:
  out-of-turn writers run under a short per-session snapshot lock and
  record the keys they change as {start, latest}; every other save takes
  the same lock and carries those edits forward into stale copies while
  keeping deliberate newer changes.
- The turn resets the overlay before its in-lock re-read and after its
  final save, and now persists primary-mode/approval preferences inside
  the turn lock on the fresh snapshot.
- SessionPreferenceService, WorkItemService, TodoService and
  PlanWorkflowService use the scope instead of the turn lock.
- Session bundle export skips lock and overlay files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011cFNZGvspeLaq3753UM5NR
Copilot AI balanced review requested due to automatic review settings November 26, 2026 10:30
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ad99f168-1f14-48f0-971b-46ded5369275

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Telli commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Entire Gates is failing on one gate only: Approvals ("No reviewers have approved this trail"). The Checks, Findings and Up-to-date gates all pass, and the GitHub Actions CI is green. A human reviewer has to approve, so no code change can fix this gate.


Generated by Claude Code

…uqka3b-session-concurrency

# Conflicts:
#	src/SharpClaw.Code.Runtime/Orchestration/ConversationRuntime.cs

This branch has not been deployed

No deployments
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.

3 participants