Skip to content

fix(config): let the nearest .openscience directory win - #799

Merged
Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/config-project-merge-order
Sep 29, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/config-project-merge-order

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What

Two facts collided in Config.get():

  • Filesystem.up walks from start upwards, so it yields the nearest directory first.
  • mergeConfigConcatArrays is later-wins.

The collected list was walked as returned, so the farthest .openscience was applied last and won:

const projectDirectories = await Array.fromAsync(
  Filesystem.up({ targets: [".openscience", ".synsc"], start: Instance.directory, stop: Instance.worktree }),
)
...
for (const dir of unique(directories)) {
  result = mergeConfigConcatArrays(result, config)   // later wins
}

The project openscience.json block a few lines above already reverses its list for exactly this reason (found.toReversed()), which is why the two disagreed with each other.

Why it matters

A repo can carry a shared .openscience/ at its root and a more specific one in a subtree. The subtree's settings are the ones a user writes to change behaviour for that part of the tree — and they are silently ignored.

The sharpest symptom: a model set for a subtree always reports the repository default, so an experiment under src/tool/ runs against a different model than the one configured for it, with nothing in the output to say so.

Verification

Fails before, passes after:

Expected: "model-from-this-directory"
Received: "model-from-the-worktree-root"
(fail) a nested .openscience overrides the one above it
(pass) a nested .openscience overrides the one above it
(pass) with no nested .openscience the worktree-wide one applies
 2 pass
 0 fail

The control case pins the other half of the contract: with no nested .openscience, the worktree-wide file still applies. The first test also asserts a key set only by the outer directory (theme) still comes through, so this is precedence between levels, not a filter.

The fixture creates a .git directory at the outer level, because the worktree is discovered by walking up for .git — without it the two levels are not in the same run.

The change

-    const projectDirectories = !Flag.OPENSCIENCE_DISABLE_PROJECT_CONFIG
-      ? await Array.fromAsync(
-          Filesystem.up({
-            targets: [".openscience", ".synsc"],
-            start: Instance.directory,
-            stop: Instance.worktree,
-          }),
-        )
-      : []
+    // Filesystem.up yields the nearest directory first and the merge below is
+    // later-wins, so walking the list as returned let the worktree-wide
+    // .openscience override the one written for the directory the run is in.
+    const projectDirectories = !Flag.OPENSCIENCE_DISABLE_PROJECT_CONFIG
+      ? (
+          await Array.fromAsync(
+            Filesystem.up({
+              targets: [".openscience", ".synsc"],
+              start: Instance.directory,
+              stop: Instance.worktree,
+            }),
+          )
+        ).toReversed()
+      : []

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).

Pre-existing failures in this area

test/config/config.test.ts fails 4 tests on main in this checkout (loads agents from .openscience/agents (plural), loads commands from .openscience/command (singular), loads commands from .openscience/commands (plural), resolves scoped npm plugins in config) — 58 pass / 4 fail both before and after this change. test/config/markdown.test.ts is 22 pass / 15 fail on main. Both look Windows-specific and are untouched here.

Fixes #798

@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.

Filesystem.up yields nearest first and the merge is later-wins, so walking the list as returned let the worktree-wide .openscience override the one written for the directory the run is in. The project config files a few lines above already reverse their list for the same reason.
@ishaan1124
Ishaan Gangwani (ishaan1124) merged commit e978ec2 into synthetic-sciences:main Sep 29, 2026
1 of 2 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.

A worktree-wide .openscience overrides the one in the directory you are working in

2 participants