Skip to content

fix(envs): stop false "env was not loaded" warning on partial loads - #10713

Merged
davidfirst merged 5 commits into
masterfrom
fix/false-env-not-loaded-warning
Sep 18, 2026
Merged

davidfirst merged 5 commits into
masterfrom
fix/false-env-not-loaded-warning

Conversation

@davidfirst

@davidfirst davidfirst commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Closes #10505.

Bit showed this warning on a healthy workspace:

⚠ environment with ID: <env> configured on component <comp> was not loaded (run "bit install")

The workspace was correct. bit install did not remove the warning.

Two different causes give the same message.

1. Partial loads. The workspace loads components in groups. A group with seeders: false holds components that the user did not request. Bit loads them only because another component uses them as an aspect or an env. Bit schedules the env of such a component only when the user requests that component. Thus the env is correctly absent from the slot during this pass, and the warning is incorrect. For example, bit show <comp> warned about the env of the env of <comp>. bit status did not warn, because it requests all components.

2. The install flow. _installModules loads the components before it loads the envs as aspects. install() sets inInstallContext to mute the warning during this time. But uninstallDependencies and updateDependencies called _installModules directly, and they did not set the flag. Thus bit uninstall and bit update showed the warning while they did the install that the warning recommends.

Changes

  • EnvsMain.skipNotLoadedWarnings(fn) mutes the warning for the time of fn. Use a scope, not a parameter: five aspects calculate the env during the load slot (tester, docs, pkg, compositions, dev-files). If you mute one caller, the warning moves to the next caller.
  • Non-seeder load groups run in that scope.
  • uninstallDependencies and updateDependencies set inInstallContext, as install() does.

Results

A healthy workspace shows no warning for bit show <comp>, bit uninstall, bit status, bit list.

A broken env keeps its report. bit status shows the warning and the component issues. bit show <the env> shows the warning.

bit show <comp> no longer warns when the env of the env is broken. The env of <comp> loads correctly in this condition. Bit reports the broken env where the user can correct it.

New unit tests in environments.main.runtime.spec.ts.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Prevent false env-not-loaded warnings during partial and install loads

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Suppresses false missing-environment warnings while loading dependency-only component groups.
• Applies install context to update and uninstall module installation paths.
• Tests warning suppression, normal reporting, and exception-safe scope restoration.
Diagram

graph TD
  CMD["Workspace Commands"] --> CL["Component Loader"] --> GROUP{"Seeder Group?"}
  GROUP -- "yes" --> ENV["Env Calculation"] -- "genuine failure" --> REPORT["Warning Reporting"]
  GROUP -- "no" --> SCOPE["Warning Scope"] --> ENV
  CMD --> INSTALL["Install Main"] --> CONTEXT["Install Context"] --> CL
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Propagate skip-warning options
  • ➕ Avoids mutable suppression state in EnvsMain.
  • ➕ Makes suppression explicit at each calculation call.
  • ➖ Requires threading options through multiple aspects and load-slot callers.
  • ➖ New callers could accidentally reintroduce the warning.
2. Use async-local suppression context
  • ➕ Isolates suppression to the active asynchronous operation.
  • ➕ Prevents unrelated concurrent calculations from inheriting muted state.
  • ➖ Adds runtime and conceptual complexity for a narrowly scoped loader behavior.
  • ➖ Provides limited benefit while load groups execute serially.

Recommendation: Keep the scoped depth counter and centralized loader integration. It covers nested scopes, restores state through failures, and avoids fragile option propagation across multiple aspects; async-local state would only become preferable if component groups are loaded concurrently.

Files changed (4) +132 / -8

Bug fix (3) +56 / -8
environments.main.runtime.tsAdd scoped suppression for missing-env warnings +29/-1

Add scoped suppression for missing-env warnings

• Introduces a nesting-safe, exception-safe suppression scope around environment calculations. Missing-env warnings and failed-load registration are skipped only while that scope is active.

scopes/envs/envs/environments.main.runtime.ts

install.main.runtime.tsRun update and uninstall installs in install context +18/-2

Run update and uninstall installs in install context

• Routes dependency update and uninstall module installation through a shared helper that sets and reliably restores the workspace install context, preventing premature environment warnings.

scopes/workspace/install/install.main.runtime.ts

workspace-component-loader.tsMute warnings for dependency-only load groups +9/-5

Mute warnings for dependency-only load groups

• Wraps non-seeder component groups in the environment warning-suppression scope because their own environments are not scheduled during partial loads. Seeder groups retain normal missing-env reporting.

scopes/workspace/workspace/workspace-component/workspace-component-loader.ts

Tests (1) +76 / -0
environments.main.runtime.spec.tsTest scoped missing-env warning suppression +76/-0

Test scoped missing-env warning suppression

• Adds workspace-backed tests verifying that muted calculations do not register failed envs, ordinary calculations still do, and suppression is restored after exceptions.

scopes/envs/envs/environments.main.runtime.spec.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Cached environments hide load failures 🐞 Bug ≡ Correctness
Description
getAndLoadSlotOrdered() executes an environment component's load slot under
skipNotLoadedWarnings() and then caches that partially loaded component without recording its
missing environment. When a daemon or API client later explicitly requests that environment, the
cache fallback returns and promotes the partial entry without rerunning the load slot, so neither
the warning nor the failed-environment state appears.
Code

scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[242]

+        const res = seeders ? await loadGroup() : await this.envs.skipNotLoadedWarnings(loadGroup);
Evidence
Non-seeder groups now run their load slots under suppression, while the loader caches components
loaded without extensions and later permits cache fallback across load variants. An explicit request
therefore accepts and promotes the prior partial cache entry instead of executing the load slot
again; that slot is the path that calls calculateEnv(), whose warning handler also populates
failedToLoadEnvs.

scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[147-194]
scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[239-245]
scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[718-765]
scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[861-882]
scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[1057-1108]
scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[1139-1162]
scopes/envs/envs/environments.main.runtime.ts[701-740]
scopes/envs/envs/environments.main.runtime.ts[1084-1091]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A non-seeder load can cache an environment after its missing environment warning was suppressed. A later explicit request reuses that partial cache entry without recalculating the environment, permanently hiding the failure in a long-lived workspace process.
## Fix Focus Areas
- scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[147-194]
- scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[239-242]
- scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[1091-1108]
- scopes/envs/envs/environments.main.runtime.ts[731-740]
## Recommended Fix
Track when a component's load slot was executed with missing-environment warnings muted, and rerun the relevant load-slot/environment calculation without suppression when that component is subsequently requested as a seeder. Add a sequential-load test that first loads a component whose environment has a broken environment, then explicitly loads that environment in the same workspace instance and verifies the warning and failed-environment state are produced.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Parallel loads hide broken environments ✓ Resolved 🐞 Bug ☼ Reliability
Description
skipNotLoadedWarnings() stores suppression in the singleton
EnvsMain.notLoadedWarningsMutedDepth, so the flag is visible to every asynchronous load rather
than only to fn. When GraphQL fans multiple uncached workspace IDs into parallel host.get()
calls, one request's non-seeder group can overlap another request's seeder group and prevent
calculateEnv() from warning or recording that requested component's genuinely missing environment.
Code

scopes/envs/envs/environments.main.runtime.ts[R231-234]

+    this.notLoadedWarningsMutedDepth += 1;
+    try {
+      return await fn();
+    } finally {
Evidence
The GraphQL resolver explicitly runs per-ID host loads through Promise.all; workspace cache misses
delegate each request to a separate getMany() execution. Non-seeder groups hold the new shared
counter above zero while awaited, and calculateEnv() skips the only path that warns and adds the
missing environment to failedToLoadEnvs whenever that counter is nonzero.

scopes/component/component/component.graphql.ts[282-294]
scopes/workspace/workspace/workspace.ts[792-801]
scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[938-947]
scopes/workspace/workspace/workspace-component/workspace-component-loader.ts[226-242]
scopes/envs/envs/environments.main.runtime.ts[230-236]
scopes/envs/envs/environments.main.runtime.ts[735-742]
scopes/envs/envs/environments.main.runtime.ts[1085-1090]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The warning suppression depth is shared by all asynchronous component loads using the singleton `EnvsMain`, so a non-seeder load can suppress legitimate missing-environment reporting in an unrelated concurrent load.
## Fix Focus Areas
- scopes/envs/envs/environments.main.runtime.ts[123-127]
- scopes/envs/envs/environments.main.runtime.ts[230-236]
- scopes/envs/envs/environments.main.runtime.spec.ts[38-74]
## Recommended Fix
Replace the shared depth counter with execution-local state, such as `AsyncLocalStorage`, so suppression propagates through work started by the wrapped callback without affecting concurrent loads. Add a concurrency test that holds a muted scope open while calculating an environment outside that scope and verifies the outside failure is still recorded.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Later installs compile too early ✓ Resolved 🐞 Bug ≡ Correctness
Description
runInstallModulesInInstallContext() sets inInstallContext but does not reset
inInstallAfterPmContext, even though _installModules() sets the latter to true after its
package-manager phase and a normal install() only resets it at the start of the next run. After
any prior install in the same process, a subsequent update or uninstall therefore enters its
pre-package-manager phase with both flags true, allowing onAspectLoadFail() to compile components
against the old dependency state.
Code

scopes/workspace/install/install.main.runtime.ts[R1421-1423]

+    this.workspace.inInstallContext = true;
+    try {
+      return await this._installModules(options);
Evidence
A normal install initializes the phase flag to false, while _installModules() sets it to true only
after package-manager installation and leaves it there when the main context ends. The new helper
does not perform that initialization, and the compiler explicitly treats both flags being true as
permission to compile after an aspect-load failure.

scopes/workspace/install/install.main.runtime.ts[204-206]
scopes/workspace/install/install.main.runtime.ts[461-485]
scopes/workspace/install/install.main.runtime.ts[1358-1361]
scopes/workspace/install/install.main.runtime.ts[1407-1425]
scopes/compilation/compiler/workspace-compiler.ts[381-399]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new update and uninstall installation wrapper starts a fresh install context without resetting the flag that indicates the package-manager phase has already completed, so state left by a previous install permits premature recovery compilation.
## Fix Focus Areas
- scopes/workspace/install/install.main.runtime.ts[1420-1426]
## Recommended Fix
Save both existing install-context flags, set `inInstallContext` to true and `inInstallAfterPmContext` to false before invoking `_installModules`, and restore both prior values in `finally`. Add coverage for an update or uninstall executed after a completed install in the same workspace instance.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 202da92

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f68c0a2

the `seeders` flag marks which components are returned to the caller, not which were
requested - groups built from extension ids carry it too. key the mute on the requested
ids instead, and let `_installModules` own the install-context flags so every caller gets
them. reuse the existing AsyncLocalStorage idiom.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 767ac42

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit d4b2749

@davidfirst
davidfirst enabled auto-merge (squash) September 18, 2026 16:46
@davidfirst
davidfirst merged commit e79885a into master Sep 18, 2026
20 checks passed
@davidfirst
davidfirst deleted the fix/false-env-not-loaded-warning branch September 18, 2026 16:46
davidfirst added a commit that referenced this pull request Sep 28, 2026
…-> 63)

Merging master brings in the workspace-root aspect (#10698), which snapping and
component-writer import and which imports @teambit/workspace - so it joins the
workspace cycle. Its new specs, and the envs spec from #10713, import
mock-workspace, which imports e2e-helper, pulling both in as well. Against that,
removing the core envs from the workspace takes aspect and node out. Net +1.
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.

bit uninstall incorrectly reports detached environments and produces bit-env-specific installation warnings

2 participants