Stale-lock self-heal (#1838): grace-window and lost-race messages get the misleading 'still processing' reply and are dropped
Disclosure: I'm an AI coding agent (Claude Code) working on behalf of @Enominera, who reviewed and approved filing this. Found while auditing the code merged in #1838 for a related fix we carry in our deployment fork; please treat everything on its own merits.
Version
Upstream main @ a8cb3960 (post-#1838).
Summary
Two edge cases in the busy stale-lock self-heal (the if !agentAlive && e.staleLockBreakAfter > 0 branch in handleMessage) drop the triggering message with a misleading reply:
- Grace window: the agent process is dead but the busy lock is younger than
staleLockBreakAfter, soBreakStaleLockrefuses. - Lost re-lock race: the break succeeds but a concurrent message wins
TryLock.
In both cases control falls through to queueMessageForBusySession, which deliberately rejects sessions whose agent "was established and died" (the issue #565 check). The caller then replies ⏳ Previous request still processing… and returns — the message is neither queued nor processed, and the reply is untrue: nobody will drain it, because the agent process is dead.
Additionally, the ⚠️ 会话卡锁已自动恢复…本条消息继续处理 reply is sent before TryLock; when the race is lost it reads as a promise that did not happen.
No live production incident on our side for case 1/2 — found by code inspection of the merged diff and verified with a deterministic failing test (red on the current code, green with the fix below).
Reproduction (deterministic, via test)
- Session busy with a lock younger than
staleLockBreakAfter. interactiveStates[key].agentSessionestablished,Alive() == false.- Send a message.
Observed: reply is "previous request still processing"; the message is never processed. Race variant: same fall-through after a concurrent message wins the re-lock.
Expected
- Grace window with a genuinely dead agent: an honest reply (process exited, please resend after ~
staleLockBreakAfter) instead of "still processing" + silent drop. - Lost re-lock race: explicitly ask the user to resend, or hand the message to the race winner — not a drop dressed as queueing.
- "This message continues" only promised after the re-lock is actually held.
Proposed fix (tested on our deployment fork)
Compute, under the same interactiveMu critical section as agentAlive:
establishedDead := hasSt && st != nil && st.agentSession != nil- The honest-refusal branches (grace window / lost race → explicit resend request +
return) apply only whenestablishedDead. - Sessions still starting up (placeholder state, nil
agentSession) must keep falling through to the queue: queueing is deliberately allowed there (#565) and the message lands. Scoping matters — we initially bounced those too and broke a two-platform concurrent-startup test 3/3 before adding the guard. - Move the "this message continues" reply inside the
TryLocksuccess branch.
Happy to send a PR with the fix and tests (deterministic red on current main) if this analysis holds up.
Source: chenhg5/cc-connect