Skip to content

[Bug]: a stop request racing Turn completion writes turn.interrupt_requested after turn.completed and suppresses unfinished-work recovery #7476

Description

@JasonBuildAI

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:

  1. 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_turn pins the opposite invariant and fails deterministically on main in the required test-shard lane, contributing to a red merge-gate for every PR.
  2. ChatExternalConversations._context_recovery_plan (loopx/capabilities/native_chat/external_conversations.py) derives stop_observed from any turn.interrupt_requested/turn.interrupted event, and planUnfinishedWork (loopx/control_plane/collaboration/conversation_binding.ts) admits the one automatic continuation of a completed Turn only when stop_observed === false. A completed managed Turn that reported unfinished_work therefore 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 main 17b2a0f9b: 1 failed — ['turn.queued', ..., 'turn.interrupt_requested'] != ['turn.queued', 'turn.completed'] at tests/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:

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

  1. added 2 commits that reference this issue on Oct 27, 2026
    c423ec3
    7836bee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions