Skip to content

fix(config): let openscience.json win over openscience.jsonc globally - #821

Merged
Ishaan Gangwani (ishaan1124) merged 4 commits into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/config-global-precedence
Sep 29, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 4 commits into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/config-global-precedence

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What

Config.global() merged the two global config files in the reverse of the documented order:

let result: Info = pipe(
  {},
  mergeDeep(await loadFile(path.join(Global.Path.config, "config.json"))),
  mergeDeep(await loadFile(path.join(Global.Path.config, "openscience.json"))),   // merged first
  mergeDeep(await loadFile(path.join(Global.Path.config, "openscience.jsonc"))),  // wins
)

mergeDeep is later-wins, so the jsonc file had the final say. The filename list at the top of the same file documents the opposite:

// Config filenames, oldest first: later merges win, so the legacy names load
// as the base and openscience.json(c) overrides them.
const CONFIG_FILES = ["synsc.jsonc", "synsc.json", "openscience.jsonc", "openscience.json"]

and the project-config loader iterates exactly that list — so a project already resolved openscience.json over openscience.jsonc. The global loader was the only place that disagreed. The legacy TOML migration below it re-read the same list in the same wrong order.

Why it matters

openscience.json is what the app writes when you change a setting; openscience.jsonc is the hand-maintained, comment-friendly variant. Someone who keeps a commented openscience.jsonc — the entire point of the format — and lets the app manage openscience.json gets their stale jsonc value silently winning, and the setting they just changed in the UI appears not to have applied.

Same "global and project disagree" class as the .openscience directory precedence, and the two disagree in the same direction.

Verification

New test — it writes both files into the test-isolated Global.Path.config and cleans up after itself. Fails before, passes after:

Expected: "model-from-the-json-file"
Received: "model-from-the-jsonc-file"
(fail) openscience.json overrides openscience.jsonc in the global config
 0 pass  1 fail
(pass) openscience.json overrides openscience.jsonc in the global config
 1 pass
 0 fail

test/config/config.test.ts and test/config/synced-merge.test.ts are unchanged by this: the same 4 pre-existing Windows failures before and after (loads agents from .openscience/agents (plural), loads commands from .openscience/command (singular), loads commands from .openscience/commands (plural), resolves scoped npm plugins in config) — 63 pass / 4 fail either way.

The change

-      mergeDeep(await loadFile(path.join(Global.Path.config, "openscience.json"))),
-      mergeDeep(await loadFile(path.join(Global.Path.config, "openscience.jsonc"))),
+      // Same order as CONFIG_FILES and the project-config path: the jsonc file is
+      // the commented-out base and the plain json file is what the app writes, so
+      // json has to merge last. Reading them the other way round let a stale
+      // jsonc shadow the file the UI had just saved.
+      mergeDeep(await loadFile(path.join(Global.Path.config, "openscience.jsonc"))),
+      mergeDeep(await loadFile(path.join(Global.Path.config, "openscience.json"))),

and in the legacy TOML migration, so a migration that rewrites config.json carries the same values the live loader would pick:

-          const files = ["config.json", "openscience.json", "openscience.jsonc"].map((name) =>
+          // Same order as the merge above, so a migration that rewrites
+          // config.json carries the same values the live loader would pick.
+          const files = ["config.json", "openscience.jsonc", "openscience.json"].map((name) =>

Left alone on purpose

global() uses mergeDeep where the rest of the loader uses mergeConfigConcatArrays (which unions plugin and instructions rather than replacing them). That inconsistency is real, but it is a separate behaviour change, so it is not folded into a precedence fix.

bun run typecheck clean; touched files are Prettier-clean (checked on LF-normalized copies — this checkout has core.autocrlf=true, which makes Prettier flag every file in the repo).

Fixes #820

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

CONFIG_FILES documents the order as oldest first with later merges
winning, and the project-config path follows that list, but the global
loader merged openscience.json before openscience.jsonc. A leftover
commented-out file therefore shadowed the one the app writes. The
legacy TOML migration re-read the same list, so it is reordered too.
… read

`Config.global` is a lazy singleton shared by every test file in the worker,
so a file earlier in the same shard can resolve it against an empty config
directory and the read below then returns that cached value instead of the
files just written — CI saw `global.model` come back undefined. Reset before
the read and again in the teardown, the same way the global-writes block in
config.test.ts does, so a later file in the shard is not handed this file's
fixture either.
The loaders merge openscience.json after openscience.jsonc, but both
writers picked the jsonc first when both existed. With the new global read
order that shadowed every global save, and at project level it already
shadowed Config.update, setMcp and setProvider on main. Writers now prefer
the plain json file; a lone jsonc is still written in place and a fresh
config is still created as jsonc.
@ishaan1124

Copy link
Copy Markdown
Member

I pushed one commit (28c9c5e) on top of yours. The app writes to openscience.jsonc first when both files exist (globalConfigFile() / projectConfigFile()), so with json now winning on read, every global save was shadowed on the next load. Both writers now prefer the file that wins on read. A lone .jsonc is still written in place, and a fresh config is still created as .jsonc. The new tests save and reload with both files present. CI is green.

@ishaan1124
Ishaan Gangwani (ishaan1124) merged commit a46ac3b into synthetic-sciences:main Sep 29, 2026
8 of 9 checks passed
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.

openscience.jsonc overrides openscience.json in the global config

2 participants