Repository navigation
fix(config): load custom parameter configs after restart - #568
Merged
Merged
Conversation
Mechanical reformat only, no behavior change. The lint-staged pre-commit hook applies it to any commit that touches this file, so it is kept apart from the fix that follows.
After a restart the custom parameter dialog failed with "Error invoking remote method 'config-manager:get': Configuration migration failed: Migration failed: object is not iterable (cannot read property Symbol(Symbol.iterator))", and retrying never helped. The main-process bundle is built by nextron's Babel preset with @babel/plugin-transform-runtime (corejs: 3), so `Map` there is core-js-pure's wrapper class. performMigrations() copied the stored configurations with structuredClone(map) (3ce55dd, first released in 3.9.0), which turns that wrapper into a plain `{}`; migrateConfigurations() then threw in Object.fromEntries({}). Since 3.9.0 a failed migration is fatal, so every provider's parameters failed to load. Any config whose metadata.version is not 1.2.0 triggers it: every config created in the UI (configVersion '1.0.0') and everything saved by 3.8 or earlier. Copy the entries one by one into a new Map instead; each entry is plain JSON. Behaviour is otherwise unchanged: migrate a copy and swap it in only after it was persisted. The failed attempts never wrote anything, so existing installs recover on upgrade. The persistence test now runs the manager with the same core-js-pure Map as the production bundle and gains a relaunch scenario (save a 1.0.0 config, restart, load). Without the fix, that scenario and the existing 0.9.0 migration assertion both fail with the error above.
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.
Summary
Since 3.9.0 the custom parameter dialog can fail with "无法读取参数配置" after the app is restarted:
Reproduction: create a provider, add one request-body parameter, quit and relaunch. Retrying never helps, and every provider's parameters are affected, not only the new one.
Root cause
@babel/plugin-transform-runtimewithcorejs: 3. In the shipped bundleMapis core-js-pure's wrapper class, not the native one.performMigrations()copied the stored configurations withstructuredClone(this.configurations)(3ce55dd, first released in v3.9.0).structuredCloneturns that wrapper into a plain{}.migrationManager.migrateConfigurations()then callsObject.fromEntries({}), which throws the error above.config-manager:getrejects for every provider.metadata.versionis not1.2.0: every config created in the UI (the renderer savesconfigVersion: '1.0.0') and everything saved by 3.8 or earlier.Why the tests missed it: the persistence unit test ran the manager with the native
Map, and the e2e test seeds a1.2.0config and only reloads the renderer, so the main process never restarts.What changed
Two commits:
style(config): the mechanical Prettier reformat ofgetTaskSnapshot, which thelint-stagedpre-commit hook applies to any commit touchingconfigurationManager.ts. Kept apart so the fix stays focused; no behavior change.fix(config):performMigrations()copies the entries one by one into a newMap(each entry is plain JSON, sostructuredCloneis fine per entry). Behaviour is otherwise unchanged: migrate a copy, swap it in only after it was persisted.scripts/test-parameter-persistence.cjsruns the manager with the same@babel/runtime-corejs3/core-js-stable/mapthe production bundle imports, and gains a relaunch scenario: save a1.0.0config with a body parameter, restart the manager from the same files, load it, expect1.2.0, parameter intact and the migrated version persisted.I went through the other
structuredClonecalls inmain/. They clone IPC payloads or JSON-shaped state; none receives aMaporSet.Existing installs recover on upgrade: the failed migration throws before anything is written, so the stored configs are intact. Checked with a profile left stuck by the old build; it loads and migrates with the fix.
Verification
ConfigurationManagercompiled by nextron's Babel config, run as separate processes (save, quit, relaunch). Before: the exact error from the report, again on every relaunch. After: it loads, is migrated once, and later relaunches are no-ops. The same steps on the v3.8.0 sources also load (control).typecheck,test:parameter-persistence,test:custom-parameters,test:task-submissionand the parameter editor jest tests (useParameterConfig,CustomParameterEditor) pass.Not in this PR
emptyConfig()usesconfigVersion: '1.0.0'while the current version is1.2.0. The first save of a new provider's parameters is therefore migrated on the next launch, and each migration writes apre-migration-backup-*.jsonwith the full configs (headers included) that is never pruned.background.tsonly go toconsole.error, not the log files, which made this hard to diagnose from user reports.