Skip to content

flaky test: TestPythonProjectLayout - The "main" module could not be found #7662

Description

@sipsma

Saw this fail here: https://github.com/dagger/dagger/actions/runs/9509605842/job/26212800646?pr=7660

Don't have the cloud trace on hand because it got re-run and couldn't find it in the history. But ugly output extracted from GHA logs is:

2024-06-14T02:27:54.5780199Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m     module_python_test.go:306: 
2024-06-14T02:27:54.5781462Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	Error Trace:	/app/core/integration/module_python_test.go:306
2024-06-14T02:27:54.5782663Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	Error:      	Received unexpected error:
2024-06-14T02:27:54.5785058Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	input: container.from.withMountedFile.withWorkdir.withNewFile.withNewFile.withExec.withExec.stdout resolve: process "dagger --debug call hello" did not complete successfully: exit code: 1
2024-06-14T02:27:54.5787069Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	
2024-06-14T02:27:54.5787841Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	Stderr:
2024-06-14T02:27:54.5788940Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:46�[0m DBG frontend exporting �[2mspans=�[0m2
2024-06-14T02:27:54.5791159Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:46�[0m DBG frontend exporting span �[2mtrace=�[0ma9d4b5aa2511eee50f6d9555c85e5e64 �[2mid=�[0mc3b21a11941dfd56 �[2mparent=�[0m27c50ec63ed30b6a �[2mspan=�[0m"dagger --debug call hello"
2024-06-14T02:27:54.5793869Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:46�[0m DBG frontend exporting span �[2mtrace=�[0ma9d4b5aa2511eee50f6d9555c85e5e64 �[2mid=�[0m4e8279f79503e71d �[2mparent=�[0mc3b21a11941dfd56 �[2mspan=�[0minitialize
2024-06-14T02:27:54.5795699Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:46�[0m DBG recording span �[2mspan=�[0m"dagger --debug call hello" �[2mid=�[0mc3b21a11941dfd56
2024-06-14T02:27:54.5797829Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:46�[0m DBG recording span child �[2mspan=�[0m"dagger --debug call hello" �[2mparent=�[0m27c50ec63ed30b6a �[2mchild=�[0mc3b21a11941dfd56
2024-06-14T02:27:54.5799749Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:46�[0m DBG recording span �[2mspan=�[0minitialize �[2mid=�[0m4e8279f79503e71d
2024-06-14T02:27:54.5801770Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:46�[0m DBG recording span child �[2mspan=�[0minitialize �[2mparent=�[0mc3b21a11941dfd56 �[2mchild=�[0m4e8279f79503e71d
2024-06-14T02:27:54.5803766Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[95m1   : �[0m�[90m4e8279f79503e71d: �[0minitialize
2024-06-14T02:27:54.5805064Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG frontend exporting �[2mspans=�[0m2
2024-06-14T02:27:54.5807292Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG frontend exporting span �[2mtrace=�[0ma9d4b5aa2511eee50f6d9555c85e5e64 �[2mid=�[0m4e8279f79503e71d �[2mparent=�[0mc3b21a11941dfd56 �[2mspan=�[0minitialize
2024-06-14T02:27:54.5810043Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG frontend exporting span �[2mtrace=�[0ma9d4b5aa2511eee50f6d9555c85e5e64 �[2mid=�[0mc3b21a11941dfd56 �[2mparent=�[0m27c50ec63ed30b6a �[2mspan=�[0m"dagger --debug call hello"
2024-06-14T02:27:54.5811735Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG new end �[2mold=�[0m"1754-08-30 22:43:41.128654848 +0000 UTC" �[2mnew=�[0m"2024-06-14 02:27:52.726417174 +0000 UTC"
2024-06-14T02:27:54.5813395Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG recording span �[2mspan=�[0minitialize �[2mid=�[0m4e8279f79503e71d
2024-06-14T02:27:54.5815161Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG recording span child �[2mspan=�[0minitialize �[2mparent=�[0mc3b21a11941dfd56 �[2mchild=�[0m4e8279
2024-06-14T02:27:54.5816344Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m f79503e71d
2024-06-14T02:27:54.5817730Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG new end �[2mold=�[0m"2024-06-14 02:27:52.726417174 +0000 UTC" �[2mnew=�[0m"2024-06-14 02:27:52.727531297 +0000 UTC"
2024-06-14T02:27:54.5819583Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG recording span �[2mspan=�[0m"dagger --debug call hello" �[2mid=�[0mc3b21a11941dfd56
2024-06-14T02:27:54.5821527Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[2m02:27:52�[0m DBG recording span child �[2mspan=�[0m"dagger --debug call hello" �[2mparent=�[0m27c50ec63ed30b6a �[2mchild=�[0mc3b21a11941dfd56
2024-06-14T02:27:54.5823105Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[95m1   : �[0m�[90m4e8279f79503e71d: �[0minitialize�[33m ERROR�[0m�[90m [6.4s]�[0m
2024-06-14T02:27:54.5824784Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	�[95m1   : �[0m�[90m4e8279f79503e71d: �[0m�[33m! input: module.withSource.initialize resolve: failed to initialize module: failed to call module "test" to get functions: call constructor: process "/runtime" did not complete successfully: exit code: 1
2024-06-14T02:27:54.5826119Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	
2024-06-14T02:27:54.5826673Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	Stderr:
2024-06-14T02:27:54.5827746Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	╭─ Error ──────────────────────────────────────────────────────────────────────╮
2024-06-14T02:27:54.5829469Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	│ The "main" module could not be found. Did you create a "src/main.py" file in │
2024-06-14T02:27:54.5831275Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	│ the root of your project?                                                    │
2024-06-14T02:27:54.5833137Z �[95m122 : �[0m    �[90m[5m41.8s] �[0m�[90m|�[0m         	            	╰──────────────────────────────────────────────────────────────────────────────╯

I very highly doubt it's actually related to the PR, but haven't seen it before. The test itself also doesn't look like it has anything obviously wrong on first glance and has existed for a while.

No immediate guesses at what's happening; going to run the test in a loop locally to see if I can hit it for now.

Activity

  1. added
    kind/bug
    area/engine
    on Jun 14, 2024
  2. self-assigned this
    on Jun 14, 2024
  3. sipsma commented on Jun 14, 2024

    @sipsma
    ContributorAuthor

    Here's another one: https://dagger.cloud/dagger/traces/44e9cfefae2652e858b74d64e0c77cc6 https://github.com/dagger/dagger/actions/runs/9510535107/job/26215186140

    No luck reproing locally yet, been running all python module tests (TestModulePython) in a loop and passed 16 times in a row so far. I'll expand to running TestContainer|TestModule, in case that matters.

  4. jedevc commented on Jun 14, 2024

    @jedevc
    Contributor

    I've also seen this one in weird places: https://github.com/dagger/dagger/actions/runs/9514094855/job/26225547001.

    Hm, gonna chuck this onto the v0.11.8 milestone for the moment - think it's probably worth getting to the bottom of it before we cut that release (just an overabundance of caution at this point, sorry) 🎉

  5. added this to the v0.11.8 milestone on Jun 14, 2024
  6. sipsma commented on Jun 14, 2024

    @sipsma
    ContributorAuthor

    I've been running TestContainer|TestModule in a loop (clearing cache each iteration) for going on ~6 hours now and it just refuses to do anything but pass over and over...

    Whatever this is, I suspect it's very timing related or requires more parallelism. I'm gonna artificially bump --parallel beyond my number of CPUs to see if I can hit it that way, for lack of any better ideas.

  7. removed this from the v0.11.8 milestone on Jun 17, 2024
  8. helderco commented on Jun 17, 2024

    @helderco
    Contributor

    This error message incorrectly shows on any "import not found" error, but fixed in:

    However, the TestPythonProjectLayout test doesn't use any dependencies. You'd have to be in a state where the user package hasn't been installed. I don't know how you could get into exec /runtime successfully without having correctly installed the package.

  9. vito commented on Jun 24, 2024

    @vito
    Contributor

    Another one:

    I seem to be hitting this pretty often, not sure if it's something unique to my PR (#7532) or if it's also on main.

  10. jedevc commented on Jun 25, 2024

    @jedevc
    Contributor
  11. helderco commented on Jun 25, 2024

    @helderco
    Contributor

    Another one:

    I have no idea what's going on. According to this, there may be an issue with accessing a lock in uv's cache volume (concurrency), but then everything appears to be installed correctly:

    257	57  :     exec uv pip install --compile --strict --no-deps -e ./sdk -e .
    258	57  :     [0.1s] | warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf (lockfile: /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf/.lock)
    259	57  :     [0.1s] | warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/1de208056d3879b5 (lockfile: /root/.cache/uv/built-wheels-v3/editable/1de208056d3879b5/.lock)
    260	57  :     [1.6s] | Resolved 2 packages in 1.46s
    261	57  :     [1.6s] | warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf (lockfile: /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf/.lock)
    262	57  :     [1.6s] | warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/1de208056d3879b5 (lockfile: /root/.cache/uv/built-wheels-v3/editable/1de208056d3879b5/.lock)
    263	57  :     [3.8s] | Downloaded 2 packages in 2.22s
    264	57  :     [3.8s] | Installed 2 packages in 1ms
    265	57  :     [4.0s] | Bytecode compiled 1527 files in 237ms
    266	57  :     [4.0s] |  + dagger-io==0.0.0 (from file:///src/sdk)
    267	57  :     [4.0s] |  + main==0.0.0 (from file:///src)
    268	57  :     exec uv pip install --compile --strict --no-deps -e ./sdk -e . DONE [4.1s]
    271	59  :     exec uv pip check
    272	59  :     [0.1s] | Checked 36 packages in 0.78ms
    273	59  :     [0.1s] | All installed packages are compatible
    

    So I don't understand why main isn't found:

    ModuleNotFoundError: No module named 'main'
    
  12. changed the title [-]flakey test: `TestPythonProjectLayout` - `The "main" module could not be found`[/-] [+]flaky test: `TestPythonProjectLayout` - `The "main" module could not be found`[/+] on Jul 19, 2024
  13. sipsma commented on Jul 19, 2024

    @sipsma
    ContributorAuthor

    Hit a somewhat different variant on this (maybe separate issue entirely?): https://dagger.cloud/dagger/traces/6dcab88c1bf49c3e56b08e8f80b141aa?span=e8d33f81fe0b06fd

    	Error Trace:	/app/core/integration/module_python_test.go:325
    	            				/app/testctx/testctx.go:163
    	Error:      	Received unexpected error:
    	            	input: container.from.withMountedFile.withWorkdir.withNewFile.withNewFile.withExec.withExec.stdout resolve: process "dagger --debug call relaxed" did not complete successfully: exit code: 1
    	            	
    	            	Stderr:
    	            	1   : 4d015ed3e36cc5e4: initialize
    	            	2   : 5239679f718d87bf:   resolving module ref
    	            	2   : 5239679f718d87bf:   resolving module ref DONE [0.1s]
    	            	3   : 20dfd541f2dd8498:   installing module
    	            	3   : 20dfd541f2dd8498:   installing module ERROR [3.4s]
    	            	3   : 20dfd541f2dd8498:   ! input: module.withSource.initialize resolve: failed to initialize module: failed to call module "test" to get functions: call constructor: process "uv pip install -e ./sdk -e . --no-deps -r requirements.lock --compile-bytecode" did not complete successfully: exit code: 1
    	            	
    	            	Stderr:
    	            	warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf (lockfile: /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf/.lock)
    	            	warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/1de208056d3879b5 (lockfile: /root/.cache/uv/built-wheels-v3/editable/1de208056d3879b5/.lock)
    	            	  × No solution found when resolving dependencies:
    	            	  ╰─▶ Because the current Python version (3.10.14) does not satisfy
    	            	      Python==3.10.10 and main==0.0.0 depends on Python==3.10.10, we can
    	            	      conclude that main==0.0.0 cannot be used.
    	            	      And because only main==0.0.0 is available and you require main, we can
    	            	      conclude that the requirements are unsatisfiable.
    	            	1   : 4d015ed3e36cc5e4: initialize ERROR [3.5s]
    	            	1   : 4d015ed3e36cc5e4: ! input: module.withSource.initialize resolve: failed to initialize module: failed to call module "test" to get functions: call constructor: process "uv pip install -e ./sdk -e . --no-deps -r requirements.lock --compile-bytecode" did not complete successfully: exit code: 1
    

    @helderco does this happen to give any other hints on what might be going on here? Or still a mystery?


    On a general note, I had some mild hope that the fix for #7900 may also fix this one, but turns out to not be the case. TestLegacy is indeed seemingly gone after that fix but still hitting these python flakes.

    It's extremely frustrating because I cannot for the life me ever manage to repro these Python ones locally. May need to bite the bullet and do println debugging in CI at this point.

  14. helderco commented on Jul 19, 2024

    @helderco
    Contributor

    @helderco does this happen to give any other hints on what might be going on here? Or still a mystery?

    Uh, yeah that looks like cache related to me. It actually does give a bit more info than the other.

    The test that failed is requesting a Python 3.10 version (latest patch):

    t.Run("relaxed requires-python", func(ctx context.Context, t *testctx.T) {
    c := connect(ctx, t)
    out, err := daggerCliBase(t, c).
    With(pyprojectExtra(`requires-python = ">=3.10"`)).

    uv seems to think that the requirement is ==3.10.10 but that's only pinned on the next test:

    t.Run("pinned requires-python", func(ctx context.Context, t *testctx.T) {
    c := connect(ctx, t)
    out, err := daggerCliBase(t, c).
    // NB: This is **not** the latest version.
    // Space after `==` is intentional.
    With(pyprojectExtra(`requires-python = "== 3.10.10"`)).

    Since this problem seems to hapen more on Python, I wonder if the issue is with uv's cache volume. If that's true, we need to then figure out if it's uv's concurrent cache handling or with our cache volumes. \cc @charliermarsh in case it rings a bell.

    There's things we can do to debug:

    • Increase uv's verbosity with --verbose
    • Make uv's cache volume sharing mode private
    • Disable uv and try with pip
    • t.Logf the contents of pyproject.toml and the source file
  15. helderco commented on Jul 27, 2024

    @helderco
    Contributor

    @sipsma, I think I understand what's going on now. Let's merge this and see if the problem persists or not:

  16. helderco commented on Jul 29, 2024

    @helderco
    Contributor

    This was closed automatically but I'm not 100% sure it'll solve the issue so let's just look out for it and re-open if it happens again.

  17. jedevc commented on Aug 27, 2024

    @jedevc
    Contributor

    @sipsma, I think I understand what's going on now. Let's merge this and see if the problem persists or not:

    Hm, this could definitely still be the issue. But surely the UV cache is computed based on the absolute path inside the module container - and the workdir at this point won't have an effect?

    How did you realize the cache key is computed based on absolute path? Trying to understand that part. I guess that's the Identifier interface?

    I wonder if the warnings here indicate something's wrong? If we're somehow clashing the paths, that would explain the issue 🤔

    warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf (lockfile: /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf/.lock)
    warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/1de208056d3879b5 (lockfile: /root/.cache/uv/built-wheels-v3/editable/1de208056d3879b5/.lock)
    Resolved 36 packages in 3.84s
    warning: Waiting to acquire lock for /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf (lockfile: /root/.cache/uv/built-wheels-v3/editable/bc7503338cafbbaf/.lock)
    Prepared 1 package in 481ms
    warning: Failed to hardlink files; falling back to full copy. This may lead to degraded performance. If this is intentional, use `--link-mode=copy` to suppress this warning.
    
    hint: If the cache and target directories are on different filesystems, hardlinking may not be supported.
    Installed 36 packages in 107ms
    Bytecode compiled 2277 files in 1.56s
     + anyio==4.4.0
     + attrs==24.2.0
     + backoff==2.2.1
     + beartype==0.18.5
     + cattrs==23.2.3
     + certifi==2024.7.4
     + dagger-io==0.0.0 (from file:///src/sdk)
     + deprecated==1.2.14
     + googleapis-common-protos==1.64.0
     + gql==3.5.0
     + graphql-core==3.2.3
     + grpcio==1.66.0
     + h11==0.14.0
     + httpcore==1.0.5
     + httpx==0.27.0
     + idna==3.8
     + importlib-metadata==8.0.0
     + main==0.0.0 (from file:///src)
     + markdown-it-py==3.0.0
     + mdurl==0.1.2
     + multidict==6.0.5
     + opentelemetry-api==1.26.0
     + opentelemetry-exporter-otlp-proto-common==1.26.0
     + opentelemetry-exporter-otlp-proto-grpc==1.26.0
     + opentelemetry-proto==1.26.0
     + opentelemetry-sdk==1.26.0
     + opentelemetry-semantic-conventions==0.47b0
     + platformdirs==4.2.2
     + protobuf==4.25.4
     + pygments==2.18.0
     + rich==13.8.0
     + sniffio==1.3.1
     + typing-extensions==4.12.2
     + wrapt==1.16.0
     + yarl==1.9.4
     + zipp==3.20.1
    
  18. jedevc commented on Aug 27, 2024

    @jedevc
    Contributor

    Hm, yup I've become pretty convinced this is part of the issue. Here's an example structure of a uv cache:

    > tree ~/.cache/uv/built-wheels-v3
    /home/jedevc/.cache/uv/built-wheels-v3
    ├── editable
    │   ├── 18aab9498669cd11
    │   │   ├── revision.rev
    │   │   └── VFxCRALSXxahNRjQzTd6B
    │   │       ├── main-0.0.0-py2.py3-none-any -> /home/jedevc/.cache/uv/archive-v0/VMBusBPSEsXXxNd575yCm
    │   │       ├── main-0.0.0-py2.py3-none-any.whl
    │   │       └── metadata.msgpack
    │   └── 509c79eeadbaa62a
    │       ├── nXgOLuApBG6Zpc4dAa4S8
    │       │   ├── main-0.0.0-py2.py3-none-any -> /home/jedevc/.cache/uv/archive-v0/cMvE_KdcRsri03FwCiVCb
    │       │   ├── main-0.0.0-py2.py3-none-any.whl
    │       │   └── metadata.msgpack
    │       ├── revision.rev
    │       └── u23lOAWXOAALBwpx5Zatd
    │           ├── main-0.0.0-py2.py3-none-any -> /home/jedevc/.cache/uv/archive-v0/V-nWfTE5QjLJFoW07VGN0
    │           ├── main-0.0.0-py2.py3-none-any.whl
    │           └── metadata.msgpack
    

    The editable is the source name. Then, we have a hash of the absolute path to the place where the project is installed from at the next level. Then, we have a content hash of the pyproject.toml (and maybe other things). Alongside those hashes, we also have revision.rev which indicates the latest one. Finally, we have the actual data.

    Now. The fix here is that we need to change the absolute paths. There's not really another good option, we could try and apply some change to pyproject.tomls before installing, but this will really screw up revision.rev.

  19. helderco commented on Aug 30, 2024

    @helderco
    Contributor

    @jedevc, wow I really botched that one. Obviously the fix couldn't be on the container that runs dagger call in the tests, but rather in the runtime 🤦 😅. Thanks for looking into it, and great work!

    There's another possible solution here. We can see if the folks from uv can figure out a solution in the tool itself since people using docker could also hit this problem (i.e., reusing the same cache volume accross different projects in the same path).

    I reached out on Discord a while ago, but I'll create a GH issue for it. \cc @charliermarsh

  20. added
    kind/flake
    on Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/enginekind/bugkind/external-helpkind/flake

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions