Skip to content

Conversation

@iHildy
Copy link
Owner

@iHildy iHildy commented Jan 1, 2026

Summary

Introduce a file-based sync lock to coordinate concurrent sync operations and a safe chmod helper to gracefully handle missing files. Refactors across apply, config, and service to adopt the new utilities. Added tests for new features.

Changes

  • Add chmodIfExists utility in src/sync/config.ts and use it in writeJsonFile, replacing direct fs.chmod calls; export/import adjusted; tests extend to cover behavior.
  • Integrate chmodIfExists into src/sync/apply.ts:
    • Use in copyFileWithMode and copyDirRecursive
    • Use in applyExtraSecrets
  • Add new locking layer:
    • New file src/sync/lock.ts with tryAcquireSyncLock, withSyncLock, and related logic
    • New tests src/sync/lock.test.ts covering acquisition, busy state, and stale lock handling
  • Refactor src/sync/service.ts:
    • Introduce lock path and locking helpers (runExclusive, skipIfBusy)
    • Wrap key operations (startupSync, init, link, pull, push, enableSecrets, resolve) with locking
    • Provide clear busy-state messaging and behavior
  • Tests
    • Add tests for chmodIfExists in src/sync/config.test.ts
    • Ensure imports reflect new chmodIfExists export

Testing

  • Run tests: bun test (or mise run test per project setup)
  • Specifically verify:
    • chmodIfExists ignores missing paths without error
    • Locking prevents concurrent sync runs and handles stale/busy scenarios
    • Existing sync flows still function with the new locking and chmod handling

Next steps (if you want): I can run the test suite, report results, and adjust any failing tests.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @iHildy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the stability and reliability of the synchronization process. It introduces a robust file-based locking system to prevent concurrent operations from interfering with each other, and refines file permission handling to gracefully manage non-existent paths, thereby improving overall system resilience.

Highlights

  • File Locking Mechanism: A new file-based synchronization lock has been introduced to coordinate concurrent sync operations, preventing race conditions and ensuring data integrity. This includes logic for acquiring, releasing, and handling stale locks.
  • Improved Chmod Handling: A chmodIfExists utility was added to gracefully handle attempts to change file permissions on non-existent files, preventing errors and making file operations more robust.
  • Core Logic Refactoring: Key synchronization operations across src/sync/apply.ts and src/sync/service.ts have been refactored to integrate the new chmodIfExists helper and to wrap critical functions with the file locking mechanism, ensuring exclusive execution.
  • New Test Coverage: Dedicated unit tests have been added for both the file locking functionality and the chmodIfExists utility, verifying their correct behavior, including scenarios for busy locks and missing files.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@iHildy iHildy changed the title Add file locking and improved chmod handling feat: Add file locking and improved chmod handling Jan 1, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a robust file-based locking mechanism to prevent concurrent sync operations and a chmodIfExists utility for safer file permission changes. The changes are well-structured, with new logic for locking and its tests in dedicated files. The core sync service is cleanly refactored to adopt this locking, using wrapper functions to separate concerns. The new chmodIfExists function is also a good addition for robustness.

I've made a couple of suggestions for minor improvements:

  • In src/sync/lock.ts, there's a piece of unreachable code that can be removed.
  • In src/sync/service.ts, there's an opportunity to simplify the code by removing some redundant async/await keywords when wrapping service methods with the new locking functions.

@iHildy iHildy merged commit 4a143a0 into main Jan 1, 2026
3 checks passed
@iHildy iHildy deleted the feat/sync-locking branch January 1, 2026 08:17
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.

2 participants