Skip to content

ClaudeSession: RLock so switch_model/restart don't self-deadlock#495

Merged
FidoCanCode merged 1 commit into
mainfrom
fix-session-lock-deadlock
Apr 14, 2026
Merged

ClaudeSession: RLock so switch_model/restart don't self-deadlock#495
FidoCanCode merged 1 commit into
mainfrom
fix-session-lock-deadlock

Conversation

@FidoCanCode
Copy link
Copy Markdown
Owner

session.prompt acquires self._lock via with self: then calls switch_model, which ALSO does with self._lock: to serialize the swap. threading.Lock is non-reentrant — the second acquire from the same thread blocks forever. restart() has the same shape.

Use threading.RLock so the inner acquire is allowed when called from the outer context. Other callers (external threads) still serialize correctly because the RLock counter only increments for the owning thread.

Unblocks set_status on phase-2 (emoji) when it needs to switch back to opus — every set_status after the first phase was wedging on this self-deadlock.

session.prompt acquires self._lock via ``with self:`` then calls
switch_model, which ALSO does ``with self._lock:`` to serialize the
swap.  threading.Lock is non-reentrant — the second acquire from the
same thread blocks forever.  restart() has the same shape.

Use threading.RLock so the inner acquire is allowed to succeed when
called from the outer context.  Other callers (external threads) still
serialize correctly because the RLock counter only increments for the
owning thread.

Unblocks set_status for phase-2 (emoji) when it needs to switch from
sonnet back to opus — previously every set_status after the first
phase hung because of this self-deadlock.
@FidoCanCode FidoCanCode requested a review from rhencke April 14, 2026 20:25
@FidoCanCode FidoCanCode merged commit 3b8ff2d into main Apr 14, 2026
2 checks passed
@FidoCanCode FidoCanCode deleted the fix-session-lock-deadlock branch April 14, 2026 20:29
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.

2 participants