Skip to content

[SDK Sentinel] Fix sandbox importer module-lock race - #1889

Open
sdk-sentinel-bot wants to merge 1 commit into
temporalio:mainfrom
sdk-sentinel-forks:automation/sdk-sentinel/ci-flake/python/35546651673-1-6355e8c30a3b
Open

sdk-sentinel-bot wants to merge 1 commit into
temporalio:mainfrom
sdk-sentinel-forks:automation/sdk-sentinel/ci-flake/python/35546651673-1-6355e8c30a3b

Conversation

@sdk-sentinel-bot

Copy link
Copy Markdown
Contributor

Caution

This PR contains untrusted AI-generated code. Do not approve or run CI until a maintainer has reviewed the diff. SDK Sentinel verified that GitHub Actions remained approval-gated with zero executable jobs when this PR was opened.

Summary

Fix intermittent Python 3.10 sandbox workflow validation failures seen in the [first captured target-branch failure](https://github.com/temporalio/sdk-python/actions/runs/35488741770/job/106019795452). No preceding equivalent success was captured.

Root cause

The sandbox importer routed ordinary imports of already-completed modules back through importlib. On CPython 3.10/3.11, a garbage-collection finalizer import can re-enter _ModuleLock.acquire, remove the outer acquisition's thread bookkeeping, and raise KeyError.

Fix

Return completed modules from the sandbox's sys.modules view for plain absolute imports. Relative, fromlist, missing, and still-initializing modules continue through importlib. Tests cover the fast path, fallback conditions, and module-lock reproduction.

Validation

The causal test failed before and passed after the change. The focused importer suite passed with the runtime-specific test skipped on Python 3.14, both affected transfer tests passed, and fixed repository validation passed. Python 3.10 CI remains required. A separate Windows full-suite timeout is unresolved.

Validation status: ci-validation-required

  • Flake confidence: high
  • Fix confidence: high
  • Value: medium
  • Patch scope: standard — 3 changed files; 9.5 KiB
  • Local reproduction: unavailable — The exact failure requires CPython 3.10/3.11, which is not installed locally. The causal importlib re-entry behavior was demonstrated on Python 3.14.
  • Regression coverage: fail-before-pass-after — The loaded-module fast-path test failed before the source change and passed afterward; the exact module-lock test is present but skips on Python 3.14.
  • Unchanged baseline (Poe lint, bridge lint, and editable build) — passed
  • Independent candidate (Poe lint, bridge lint, and editable build) — passed

Investigator-run checks

  • poe test -s -k workflow_sandbox_importer_repeat_import_skips_import_machinery — passed; 2 attempt(s). The causal check failed before the source change because repeated imports re-entered importlib, then passed after the fast path was added.
  • poe test -s -k 'workflow_sandbox_importer_repeat_import_skips_import_machinery or loaded_module_fast_path_requires_completed_modules or workflow_sandbox_importer_loaded_module_import_inside_module_lock' — passed; 1 attempt(s). Two tests passed; the Python 3.10/3.11-specific module-lock test skipped on Python 3.14.
  • poe test -s -k workflow_sandbox_importer — passed; 1 attempt(s). Seven tests passed and the runtime-specific regression test skipped.
  • poe test -s -k transfer_types_workflow_signal — passed; 1 attempt(s). Both workflow-signal parameterizations passed on Python 3.14.
  • .ci-flake-runtime/input/validate.sh — passed; 1 attempt(s). Lint, type checks, docstyle, bridge clippy, and editable bridge build passed.

Required target CI

  • Continuous Integration / check-protos (Python 3.10, protobuf 3.x)
  • Continuous Integration / build-lint-test (3.10, ubuntu-latest)
  • Continuous Integration / build-lint-test (3.10, windows-latest)
  • Continuous Integration / build-lint-test (3.10, macos-arm)

Residual risks

  • The exact CPython 3.10 module-lock path was not executed locally.
  • The fast path intentionally bypasses importlib hooks only for completed ordinary absolute imports; CI should confirm no platform-specific import behavior changes.
  • The separate Windows Python 3.14 hard timeout remains unresolved.

Automation provenance

If this finding should not be fixed, apply the sdk-sentinel:false-positive label and close the PR. Sentinel will suppress the finding until its affected source changes.

SDK Sentinel recurrence history

  • Unique failed CI run attempts: 1
  • First occurrence: 2026-09-20 04:25 UTC
  • Latest occurrence: 2026-09-20 04:25 UTC
  • Recent occurrences:

@sdk-sentinel-bot
sdk-sentinel-bot requested a review from a team as a code owner September 21, 2026 00:43
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.

1 participant