Repository navigation
Description
Preflight
- I searched existing issues and discussions for this behavior.
- This report is not an unpatched security vulnerability.
- The report and attachments contain no credentials or private/internal material.
Issue origin
Observed or reproduced in a real environment
LoopX version or commit
main at 17b2a0f9b (also reproduced at 2236b1473). The regression starts at b8b9c1d77 (#7191).
Host or runtime surface
Not host-specific — the shared Chat runtime. Dashboard, desktop and Lark/manager conversations all stop a Turn through ChatRuntimeController.interrupt_turn.
LoopX area
Control plane (goals, todos, quota, scheduler, registry, runtime)
Problem
ChatRuntimeController.interrupt_turn (loopx/chat_runtime.py) reads the Turn, appends the durable turn.interrupt_requested event, and only then compare-and-sets the status to interrupting. If the Turn reaches a terminal state between that read and the append, the status CAS correctly refuses the change — but the stop-intent event has already been written into the completed Turn's event ledger.
Before #7191 the event was appended only after the admitted status transition, so a refused interrupt left no trace. #7191 moved the intent ahead of the status write for crash safety ("Persist stop intent before changing status ... so a service crash cannot turn an interrupted stop into an automatic review"), but dropped the terminal-state check that the status write used to provide.
Consequences:
- A completed Turn can end up with
turn.queued, turn.interrupt_requested, turn.completed.tests/test_chat_session_active_turn.py::test_interrupt_does_not_overwrite_a_completed_turnpins the opposite invariant and fails deterministically onmainin the requiredtest-shardlane, contributing to a redmerge-gatefor every PR. ChatExternalConversations._context_recovery_plan(loopx/capabilities/native_chat/external_conversations.py) derivesstop_observedfrom anyturn.interrupt_requested/turn.interruptedevent, andplanUnfinishedWork(loopx/control_plane/collaboration/conversation_binding.ts) admits the one automatic continuation of a completed Turn only whenstop_observed === false. A completed managed Turn that reportedunfinished_worktherefore loses that continuation, with no diagnostic that says why.
Minimal reproduction
python -m pytest -q tests/test_chat_session_active_turn.py::test_interrupt_does_not_overwrite_a_completed_turn --assert=plain- At
main17b2a0f9b:1 failed—['turn.queued', ..., 'turn.interrupt_requested'] != ['turn.queued', 'turn.completed']attests/test_chat_session_active_turn.py:1305. - At
b8b9c1d77^(3a1800b18):1 passed.
The test pauses the interrupt's load_turn read, lets the adapter complete the Turn, then resumes the interrupt, so the interleaving is deterministic rather than timing-dependent.
Expected behavior
A stop request that loses the race leaves the completed Turn's terminal event history untouched. Stop intent is recorded only when the interrupt transition is admitted, and it is still durable before the status change.
Actual behavior
The stop-intent event is appended for a Turn that already completed; the completed Turn's ledger reports a stop it never accepted.
Sanitized diagnostics
FAILED tests/test_chat_session_active_turn.py::test_interrupt_does_not_overwrite_a_completed_turn - AssertionError:
assert ['turn.queued...pt_requested'] == ['turn.queued...rn.completed']
Additional context
Evidence links:
- Hosted main run: https://github.com/loopx-project/loopx/actions/runs/40423008279/job/121922355088 —
FAILED tests/test_chat_session_active_turn.py::test_interrupt_does_not_overwrite_a_completed_turn,AssertionErrorat line 1305. - Introduced by
b8b9c1d77(fix(chat): review interrupted results without replaying business effects #7191): its diff addsself.store.append_event(session_id, turn_id, kind="turn.interrupt_requested", payload={})beforeself.store.update_turn(..., status="interrupting"); the same test passes at the parent commit3a1800b18. - Affected code:
loopx/chat_runtime.py::interrupt_turn,loopx/capabilities/native_chat/external_conversations.py::_context_recovery_plan,loopx/control_plane/collaboration/conversation_binding.ts::planUnfinishedWork.
A fix should keep the crash-safe ordering (intent before the status change) while making the status check, the intent event and the status write one atomic Turn transition under the existing Turn write lock.
Activity
fix(chat): keep a completed Turn's event history when a stop races it
fix(chat): keep a completed Turn's event history when a stop races it