#1646·DeepTutor

[Bug]: Deleting a Mastery session can leave an orphaned turn holding the workspace activity lock

Author: NoxsMediaCreated Sep 29, 2026Updated Sep 29, 2026

Related Module

API/Backend — Mastery sessions and workspace resource assignments

Environment

  • DeepTutor v1.6.12, official commit ef2d9e5c3c99fd073742c5aadc2bb9584b1e503b, without overlays.
  • Linux ARM64, Python 3.11.16, one backend process.
  • Relevant deployed Python files were compared byte-for-byte with the official commit.

Observed behavior

Saving a workspace's knowledge-base assignments repeatedly returns HTTP 400:

Workspace data is busy. Wait for active requests and tasks before retrying.

Deleting the Mastery path and conversation does not clear the condition. Read-only inspection of the affected backend found:

  • A live Mastery turn suspended at _wait_for_user_reply() / reply_queue.get().
  • Its surrounding data_activity() generator still owns a sqlite3.Connection, and the OS reports the backend holding a shared lock on workspace-activity.sqlite3.
  • The corresponding session and turn records are absent from the live SQLite stores. The initially inspected, different conversation had completed turns; querying durable nonterminal rows alone therefore missed this orphan.
  • The orphan's _coordinate_execution() coroutine is still alive.
  • A new read-only knowledge-base request completes normally without increasing the open activity-file descriptor count.

Inspection read code/frame metadata from the process without pausing it, injecting code, restarting it, or dumping local-variable values. No private conversation text, account IDs, session IDs, or host paths are included here.

Source-level cause

The start and deletion paths resolve different TurnRuntimeManager instances:

  1. Unified chat uses container.turns; TurnApplicationService._resolve() resolves the application container's RuntimeRegistry. Its runtime has the coordinator and owns the live execution.
  2. Session deletion and Mastery cancellation instead call get_turn_runtime_manager(), which maintains a separate _runtime_instances dictionary and constructs TurnRuntimeManager(store=store) without a coordinator.
  3. This second manager has no matching in-memory execution. Its fallback only handles durable status running; for waiting_input, cancel_turn() returns False without cancelling the owning coroutine.
  4. The session deletion route ignores that return value and deletes the records. Mastery cancellation also ignores it and releases the separate learning-path lease.
  5. The actual _run_turn() remains suspended awaiting user input while @workspace_writer holds its activity lease. Its coordination loop renews the lease without checking whether the session/turn records were deleted. Workspace assignment updates require an exclusive activity lock and consequently continue failing.

Targeted reproduction scenario

The live orphan and source paths above were verified. The following clean-instance sequence is derived from them and has not yet been rerun as an end-to-end test:

  1. Start a Mastery chat through the unified chat transport.
  2. Let the tutor call ask_user, leaving the turn in waiting_input.
  3. Delete that conversation through DELETE /api/sessions/{session_id}. Separately exercise deleting/resetting its Mastery path, which shares the cancellation helper.
  4. Try saving workspace resource assignments.
  5. Check that the owning runtime task is still waiting despite the session deletion, and that the assignment PATCH fails with the busy message.

Expected behavior

Deletion should cancel and await the execution that actually owns the turn before removing its records. A failed cancellation must not silently leave an inaccessible live task holding the account activity lock. The deletion/cancellation routes should use the same application runtime/coordinator as turn creation.

Validation boundaries

This report identifies the confirmed live orphan and a matching deterministic source-level cancellation defect. It does not claim that a freshly started end-to-end reproduction, a fix, or a restart recovery has been tested. The initial sequence that created this particular orphan was not captured in successful-request access logs.