Repository navigation
Treat a blank providers.json as empty - #185
Merged
Merged
Conversation
The first mutation creates providers.json with an exclusive open and then writes the seed through that descriptor. A process stopped between the two, such as an extension host killed by a window reload, leaves an empty file. Every reader then reported it as invalid JSONC, mutations aborted until the file was fixed, and nothing ever reseeded it, because the exclusive open sees the file exists. An empty or whitespace-only file holds no configuration, so readers now treat it as missing and the next mutation seeds it as if it had created it. This also repairs files that are already blank.
costrouc
marked this pull request as ready for review
November 8, 2026 19:00
Label a blank file as empty rather than missing, since it exists, which is what a settings report shows. Note that a comments-only file stays invalid, document that repairing a blank file reports true, and test that loading a blank file raises no issue or warning and that repairing one with an unchanged config still writes the seed.
sharon-wang
removed their request for review
November 11, 2026 15:29
parseProvidersConfig and parseProvidersConfigTolerant now read blank text
as {}, so the loader, the custom-entry reader, and the mutation no longer
each repeat the check. The mutation still checks blank text to decide
whether to seed.
Also: correct the raceSafeEnsureFile comment (readers report a blank file
as empty, and other processes can see it blank during a normal creation),
test that a comment-only file stays invalid, and update the ai-config
memory bank, which still said a zero-byte file is invalid.
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.
Fixes #184.
This fixes a race condition that we caught in our emulator tests in Posit Team. This actually occurred quite frequently. Granted our playwright tests are written to go really fast to encourage race conditions.
Problem
The first mutation creates
providers.jsonwith an exclusive open, then writes the seed through that descriptor. A process stopped between the two leaves an empty file. From then on:Change
isBlankConfigText()insrc/node/parse-jsonc.ts: the text is empty or whitespace only. A file holding only comments is still invalid, since a user wrote it.readFileConfig(load and watch): a blank file is theemptylayer, as{}is, with no issue.readUserCustomProviderEntries: a blank file gives an empty map.mutateProvidersConfig: a blank file reads as{}, and the mutation seeds it as if this call had created it. The seed is$schemaandversion, and the whole file is written throughatomicWrite. Repairing a blank file reportstrue, even when the mutation changes nothing.readCurrentConfigandraceSafeEnsureFilesay so.This makes the interrupted creation harmless and repairs files that are already blank, with nothing deleted by hand.
Not changed: creating the file atomically. This change also repairs files that are already blank, which atomic creation alone would not. A follow-up could drop
raceSafeEnsureFileand take the lock on the path before the file exists (proper-lockfilewithrealpath: false), so the first writer goes straight throughatomicWriteand no blank file is ever visible.Testing
New tests:
mutate-config.test.ts: an empty file and a whitespace-only file are seeded, and the mutation is applied. A blank file is repaired when the mutation changes nothing.load-config.test.ts: loading a blank file raises no issue and logs no warning, and the file reads asempty.read-user-custom-provider-entries.test.ts: a blank file gives an empty map.Results:
vitest runinpackages/ai-configpasses 800 of 800, aftertsc -p .so the CJS tests finddist.oxfmt --checkis clean.