Skip to content

Feature/bwdo 809 implement lock clone cache#68

Open
BenjiMilan wants to merge 3 commits into
developfrom
feature/BWDO-809_Implement_lock_clone_cache
Open

Feature/bwdo 809 implement lock clone cache#68
BenjiMilan wants to merge 3 commits into
developfrom
feature/BWDO-809_Implement_lock_clone_cache

Conversation

@BenjiMilan

Copy link
Copy Markdown
Contributor

Implement cache locking. Went with a timeout of 10 minutes where if a user is waiting for more than 10 mins it will error out for them.

The previous version waited for 5 minutes and if it was still locked beyond then it bypassed it for the user. This does mean it never gets hard locked but also could cause a long clone (that is locking the cache) to then error which could be frustrating for users.

I'm thinking of keeping the hardline solution of the cache is locked unless you go and delete the lockfile and see if any users get stuck and if so we can look at alternatives. But open to suggestions.

@BenjiMilan
BenjiMilan requested a review from TB-1993 July 15, 2026 11:01
@BenjiMilan BenjiMilan self-assigned this Jul 15, 2026
Copilot AI review requested due to automatic review settings July 15, 2026 11:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR implements an inter-process lock around the local repo cache so that only one clone/cache refresh runs at a time, with a hard timeout (10 minutes) after which the waiting process exits.

Changes:

  • Add a filelock-based lock around cache creation/usage in RepoCloner with periodic wait logging and a hard timeout.
  • Refactor clone flow to route cached clones through a new _clone_with_cache() path and pass the cache reference into _clone().
  • Add filelock as an installation dependency.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/sc/clone/cloners/repo_cloner.py Adds cache locking + timeout logic and refactors clone flow to use a cache reference safely under a lock.
setup.py Adds filelock dependency required for cache locking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sc/clone/cloners/repo_cloner.py
Comment thread src/sc/clone/cloners/repo_cloner.py
Copilot AI review requested due to automatic review settings July 15, 2026 12:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +89 to +107
started = time.monotonic()
lock = FileLock(CACHE_LOCK_PATH)

logger.info("Acquiring cache lock.")
while True:
try:
lock.acquire(timeout=20)
break
except Timeout:
waited = int(time.monotonic() - started)
if waited < CACHE_MAX_WAIT:
logger.info(
f"Cache is in use by another process, waited {waited} seconds..."
)
else:
logger.error(
f"Cache remained locked past the set wait time of {CACHE_MAX_WAIT} seconds."
)
sys.exit(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm pretty sure old SC would clear the lock if you reached the 5 min timeout. We should probably do that. Also does this library handle the lock if it was there since before the start of the sc process, like when a clone gets killed halfway through and the lock is never cleared. Then the user tries to clone again?

Comment on lines +89 to +107
started = time.monotonic()
lock = FileLock(CACHE_LOCK_PATH)

logger.info("Acquiring cache lock.")
while True:
try:
lock.acquire(timeout=20)
break
except Timeout:
waited = int(time.monotonic() - started)
if waited < CACHE_MAX_WAIT:
logger.info(
f"Cache is in use by another process, waited {waited} seconds..."
)
else:
logger.error(
f"Cache remained locked past the set wait time of {CACHE_MAX_WAIT} seconds."
)
sys.exit(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm pretty sure old SC would clear the lock if you reached the 5 min timeout. We should probably do that. Also does this library handle the lock if it was there since before the start of the sc process, like when a clone gets killed halfway through and the lock is never cleared. Then the user tries to clone again?

logger = logging.getLogger(__name__)

REPO_CACHE_DIR = Path.home() / ".caches"
CACHE_LOCK_PATH = REPO_CACHE_DIR / ".lock"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Might be better to call the lock .sc_lock. I doubt we'll ever re-use the cache in the future, but alwaty nicer to know where the lock came from.

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.

3 participants