Skip to content

fix(roadmap): import refine at module level to avoid deadlock (#2535) - #2599

Merged
dan-petty merged 1 commit into
mainfrom
fix/2535-service-worker-imports
Oct 29, 2026
Merged

dan-petty merged 1 commit into
mainfrom
fix/2535-service-worker-imports

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

The roadmap run Service starts two LaneWorker threads that each call _run_refine_adapter. That function lazily imported devops_cli.roadmap.refine inside the thread. The import chain reaches pydantic_ai (via refine_investigation.py). On Python 3.14, two threads importing pydantic_ai simultaneously trigger _DeadlockError because the import lock is reentrant.

This change moves the refine import to module level in run.py. The serve command imports run.py in the main thread before the LaneWorker threads start (serve.py:170), so pydantic_ai is already in sys.modules by the time the threads run. The import lock is acquired once, in the main thread, and the workers skip it.

Fail-to-pass

$ uv run devops ci fail-to-pass --base origin/main
  failed on base: tests.test_roadmap_run::test_the_refine_import_is_at_module_level_not_lazy_in_the_adapter
  passed on base: tests.test_roadmap_run::test_a_job_that_reads_the_clone_fails_without_one_rather_than_reading_the_cwd[refine-_run_refine_adapter]
  (44 passed, 1 failed)

Test

New structural test test_the_refine_import_is_at_module_level_not_lazy_in_the_adapter in tests/test_roadmap_run.py asserts that run.py contains a module-level ImportFrom for devops_cli.roadmap.refine and that no Import/ImportFrom of that module appears inside any function body.

Closes #2535

…e its worker threads start, so two lanes no longer deadlock on the pydantic_ai import (#2535)
@dan-petty dan-petty changed the title fix(roadmap): the Service imports the refine job's dependencies before its worker threads start, so two lanes no longer deadlock on the pydantic_ai import (#2535) fix(roadmap): import refine at module level to avoid deadlock (#2535) Oct 29, 2026
@dan-petty
dan-petty marked this pull request as ready for review October 29, 2026 02:28
@dan-petty
dan-petty merged commit 3731dff into main Oct 29, 2026
17 of 18 checks passed
@dan-petty
dan-petty deleted the fix/2535-service-worker-imports branch October 29, 2026 02:32
dan-petty pushed a commit that referenced this pull request Oct 29, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.13.1](v0.13.0...v0.13.1)
(2026-10-29)


### Bug Fixes

* **roadmap:** import refine at module level to avoid deadlock
([#2535](#2535))
([#2599](#2599))
([3731dff](3731dff))


### Code Refactoring

* **review:** retire the unread review guards file
([#2595](#2595))
([6ae7123](6ae7123)),
closes [#1916](#1916)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(service): the first refine rounds of a new pod deadlock when two worker threads import pydantic_ai at the same time

1 participant