Fix atomic writes and fs.constants flags in InitCommand and ConfigService#19
Merged
naheel0 merged 2 commits intoInitCommandfrom Mar 23, 2026
Merged
Fix atomic writes and fs.constants flags in InitCommand and ConfigService#19naheel0 merged 2 commits intoInitCommandfrom
naheel0 merged 2 commits intoInitCommandfrom
Conversation
… in InitCommand and ConfigService Co-authored-by: jaseel0 <225665919+jaseel0@users.noreply.github.com> Agent-Logs-Url: https://github.com/BeyteFlow/git-ai/sessions/53acba39-daa6-4e19-91d9-07b21288984a
Copilot
AI
changed the title
[WIP] Refactor config file handling in InitCommand
Fix atomic writes and fs.constants flags in InitCommand and ConfigService
Mar 23, 2026
naheel0
approved these changes
Mar 23, 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.
Description
Three issues with config file writes: a TypeScript build failure from using non-existent
fs.O_CREAT/O_EXCL/O_RDWR(should befs.constants.*), a missingtry/finallythat could leak file descriptors, and non-atomicwriteFileSynccalls in both the backup/overwrite branches andConfigService.saveConfig()that risk file corruption on interruption.src/commands/InitCommand.tsfs.O_CREAT | fs.O_EXCL | fs.O_RDWR→fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_RDWR(fixes CI build)writeFileSync/fsyncSyncintry/finallyto guarantee fd is always closedatomicWriteFileSynchelper: opens a.tmp-<pid>-<ts>file in the same directory withO_CREAT | O_EXCL | O_WRONLY, writes, fsyncs, closes, thenrenameSyncs into place; cleans up temp on rename failureatomicWriteFileSyncsrc/services/ConfigService.tssaveConfig()rewritten with the same temp-file + fsync + rename pattern, consistent temp naming (.tmp-<pid>-<ts>in config directory)Related Issue
Closes #
Type of Change
Checklist
How Has This Been Tested?
npm run build(previously failing, now passes) andnpm test(lint +tsc --noEmit). CodeQL returned 0 alerts.Screenshots (if applicable)
Additional Notes
The atomic write pattern mirrors the existing
ConflictResolver.applyResolution()already in the codebase. Temp files are created in the same directory as the target to ensurerenameis a same-filesystem operation.📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.