Skip to content

Concurrent parallel invocations can lose worker-options files #21974

Description

@adamtheturtle

Crash

On Ubuntu 24.04 with Python 3.12 and Mypy 2.3.1, four concurrent Mypy
invocations using --num-workers=4 intermittently failed to start their build
workers. Several workers reported:

FileNotFoundError: [Errno 2] No such file or directory: '.mypy_cache/.worker_options.<id>.data'
Failed to establish connection with worker: No status file found

Full GitHub Actions log:
https://github.com/adamtheturtle/literalizer/actions/runs/34489393511/job/102911865600

The four commands shared the working directory and default .mypy_cache, but
each checked a different temporary Python file. The failure is intermittent;
an unchanged rerun passed. Serializing the invocations and using one Mypy
worker avoids it.

This resembles #21393, but that report is specifically a macOS test failure;
this occurrence was on Linux with concurrent consumer invocations.

Activity

  1. ilevkivskyi commented on Sep 13, 2026

    @ilevkivskyi
    Member

    This indeed looks very similar to #21393. Maybe it is actually the same issue. How often do you see this?

    Btw, running mypy with pre-commit requires extra care, see #13916 (in particular parallelizing mypy invocations is usually a bad idea, unless you invoke mypy on completely independent groups of files). Finally, GitHub usually gives very cheap machines for actions, with just few cores, so likely by trying to force more parallelism you may make things slower.

    For the issue itself, I think it may be possible to fix it by adding a bit of retry/back-off logic in the workers. I could be that there is a tiny delay before a file is visible to the other process.

  2. changed the title [-]Concurrent parallel invocations can lose worker-options files on Linux[/-] [+]Concurrent parallel invocations can lose worker-options files[/+] on Sep 13, 2026
  3. adamtheturtle commented on Sep 13, 2026

    @adamtheturtle
    ContributorAuthor

    Thank you @ilevkivskyi for taking a look at this so quickly.

    In 434 runs on one project in the last week, it appears I have hit this four times:

    Thanks also for the thoughts on pre-commit - I'll keep those in mind and maybe reconsider my setup.

  4. Shoryamishra61 commented on Sep 14, 2026

    @Shoryamishra61

    I investigated the worker startup path and have a small fix ready following the retry/backoff direction suggested above.

    The coordinator already bounds worker startup using WORKER_START_TIMEOUT / WORKER_START_INTERVAL, while the worker currently treats an initial FileNotFoundError reading --options-data as immediately fatal. My patch adds a bounded retry only for FileNotFoundError at that read boundary; other filesystem and deserialization errors still propagate normally.

    I also added deterministic tests covering immediate success, transient recovery, timeout exhaustion, unrelated filesystem errors, and options serialization, and the existing parallel checks, mypy self-check, and lint suite are passing.

    I'll do one final collision/rebase check and open the PR.

  5. ilevkivskyi commented on Sep 14, 2026

    @ilevkivskyi
    Member

    @adamtheturtle Note I merged couple PRs that should help with this. Can you try the current mypy master and see if the flakiness improved? If you can't use the mypy master, these fixes should be available in mypy v2.4.0 next week.

  6. adamtheturtle commented on Sep 14, 2026

    @adamtheturtle
    ContributorAuthor

    Wow thank you @ilevkivskyi ! I'll move the high-traffic literalizer project to mypy master and I'll update this issue if there are any failures.

  7. adamtheturtle commented on Sep 14, 2026

    @adamtheturtle
    ContributorAuthor

    (and thank you @Shoryamishra61 )

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions