Skip to content

test_opening_a_session_does_not_cancel_a_delete hangs intermittently under load #20

Closed

Description

@junxit

tests/test_tui_workers.py::test_opening_a_session_does_not_cancel_a_delete sometimes hangs, and the suite's 120-second hang guard stops the run. It passes on an idle machine, which is why it went unnoticed before CI existed.

Seen so far

  • CI, Ubuntu 24.04, pytest-asyncio 1.4.0: hung. This is the run described in Make the test suite pass on Linux and run it there in CI #17.
  • CI, macOS 26, pytest-asyncio 1.5.0 (Dependabot chore: bump pytest-asyncio from 1.4.0 to 1.5.0 #19): hung. All 1615 tests before it passed.
  • Locally on macOS, under heavy CPU load (two loops of this test plus eight busy loops):
    • 2 of 15 runs hung on 1.4.0, and 1 of 15 on 1.5.0.
    • Under lighter load, 0 of about 150 runs hung, including two probes that timed each step out or logged it, so the race is sensitive to timing.
  • Every failure was a hang, not an assertion failure. The thread dumps show the event loop and both default-executor threads idle, with nothing blocked at the test's gate. Some coroutine is waiting for a result that never arrives.

Not yet known: which await hangs. The candidates:

  • app.open_session(fast).wait();
  • app.workers.wait_for_complete();
  • the app shutting down as run_test exits after _until gives up waiting for the dialog. That would turn an assertion failure into a hang.

What the test exercises. A delete starts on one session; its transcript parse runs through asyncio.to_thread and waits at a gate. Meanwhile another session is opened, as a thread worker in the exclusive load group, which hands its result back with call_from_thread. The test then opens the gate, waits for the delete dialog, confirms it, and waits for every worker.

Impact. CI runs fail intermittently. If the cause is in the app rather than the test, a delete started while another session loads could stall in the TUI. No data is at risk: every await in the delete flow comes before the delete itself.

Activity

  1. junxit commented on Nov 16, 2026

    @junxit
    OwnerAuthor

    Handoff prompt (paste into a new Claude Code session in this repo):

    Goal. Find why tests/test_tui_workers.py::test_opening_a_session_does_not_cancel_a_delete hangs under load, and fix the cause, whether it's in the test or the app. Done when:

    • the test passes 200 runs in a row under heavy CPU load locally;
    • CI runs stop hanging on it.

    Background. The issue lists where it hung. The relevant code:

    • src/sx/tui/app.py:
      • SxApp.action_delete_session and _delete_flow, which call asyncio.to_thread(adapter.load_transcript, ...) and then push_screen_wait;
      • SxApp.open_session and _load_into_pane, which run as @work(exclusive=True, thread=True, group=_LOAD_GROUP) and hand back their result with call_from_thread.
    • The test file's _Gated adapter and its helpers.
    • The hang guard in tests/conftest.py (SX_TEST_TIMEOUT).

    Approach.

    1. Reproduce. Loop the single test (about 1.5 s per run) while loading the CPU. Two loops of the test in parallel, plus a few busy shell loops, reproduced it in roughly 1 run in 10. Probes that add awaits (asyncio.wait_for) or log every step hid it, so prefer passive evidence.
    2. Capture coroutine-level evidence at the moment of the hang. For example, extend the hang guard temporarily so it dumps every task of the test's event loop with its stack.
    3. Check these suspects:
      • a thread worker blocked in call_from_thread while the app shuts down after a failed _until;
      • Worker.wait() on a worker that was cancelled or never started;
      • app.workers.wait_for_complete() waiting on a worker parked in push_screen_wait.
    4. Fix it.
      • If the test is at fault, make its waits event-driven and bounded rather than polling pilot.pause.
      • If the app is at fault, fix it and add a regression test that fails on the old code.

    Constraints.

    • Never read or write the real stores (~/.claude, ~/.codex, ~/.gemini, ~/.pi, ~/.omp, /private/tmp/claude-<uid>). Tests use tmp_path plus the guards in tests/conftest.py.
    • Never run pi or omp; only the user does.
    • Run the full suite with -W error. ruff check and ruff format --check must be clean.
    • Use US English, Google-style docstrings and exact dependency pins. Update changelog.txt.

    Verification. 200 consecutive passes under load, the full suite, and a green CI run.

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions