Fix diamond dependency double-import handling#553
Merged
philmillman merged 7 commits intomainfrom Apr 7, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: b89789c The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
When the same schema directory is imported via multiple paths (diamond dependency), the schema file was being loaded twice. This caused plugin init decorators (like @initAws) to run twice, throwing "Instance with id '_default' already initialized". Fix: Add _loadedImportPaths Set to EnvGraph to track already-loaded import paths. Before adding a new DirectoryDataSource or DotEnvFileDataSource for an import, check if the path was already imported. If so, skip the duplicate import. Also adds a test plugin (test-plugin-with-init) and three new tests in import.test.ts covering the diamond dependency pattern for directory imports, directory imports with plugins, and file imports. Agent-Logs-Url: https://github.com/dmno-dev/varlock/sessions/a36fdb26-ef5a-41af-a057-cfa6d4d04f7c Co-authored-by: philmillman <3722211+philmillman@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dmno-dev/varlock/sessions/a36fdb26-ef5a-41af-a057-cfa6d4d04f7c Co-authored-by: philmillman <3722211+philmillman@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix instance with id '_default' already initialized error
Fix "Instance with id '_default' already initialized" with diamond dependency imports
Apr 4, 2026
commit: |
|
@philmillman, I tried out this PR package (super cool, by the way!) and it fixes #552! Thank you very much. Looking forward to this getting merged. |
Member
Ok thanks for testing! We'll get it out today or tomorrow at the latest |
…and importKeys handling The previous approach skipped duplicate imports entirely, which lost importKeys from the second import and placed definitions at the wrong precedence position. Now, duplicate imports create lightweight ImportAliasSource nodes in the tree. These alias nodes share the original source's definitions but carry their own importMeta/parent, giving them the correct position in the precedence chain. A new sortedDefinitionSources list (derived from sortedDataSources by expanding aliases) is used by ConfigItem.defs for item resolution, while sortedDataSources remains unchanged for plugin init, error collection, and serialization. Also adds type field to serialized source entries and updates the Next.js integration to filter by type instead of label prefix. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
PR titles containing quotes broke the bash conditional. Using env vars instead of inline interpolation prevents shell parsing issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The plugin tsconfig was missing node type definitions, causing typecheck failures for any plugin importing node built-ins. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
theoephraim
approved these changes
Apr 7, 2026
philmillman
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the same schema directory is reachable via multiple import paths (diamond dependency), it was being fully loaded multiple times. This caused plugin init decorators (e.g.
@initAws) to execute twice, crashing with "Instance with id '_default' already initialized".Example topology that triggers the bug:
Changes
EnvGraph— adds a private_loadedImportPaths: Set<string>and acheckAndRecordImportPath(path): booleanhelper that atomically checks-and-records a path (returnstrue= already seen, skip it)_processImports()— calls the helper before creating anyDirectoryDataSourceorDotEnvFileDataSourcefor all four import variants (virtual dir, virtual file, real dir, real file); skips withcontinueif the path was already loadedtest-plugin-with-init) — minimal plugin that registers an@initTestPlugin()root decorator with module-level singleton tracking, mirroring how real plugins like@varlock/aws-secrets-pluginbehaveimport.test.ts— three new diamond-dependency tests: directory dedup, directory dedup with a plugin init decorator, and file dedupWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.iconify.design/opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/varlock/varlock/node_modules/.bun/vitest@4.1.0+9d5cb286dd4627aa/node_modules/vitest/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/varlock/varlock/node_modules/.bun/vitest@4.1.0+9d5cb286dd4627aa/node_modules/vitest/dist/workers/forks.js(dns block)If you need me to access, download, or install something from one of these locations, you can either: