Skip to content

fix: correct unlock key format to match lock key format#5781

Merged
jamengual merged 6 commits intomainfrom
fix/issue-5722-unlock-key-format
Sep 11, 2025
Merged

fix: correct unlock key format to match lock key format#5781
jamengual merged 6 commits intomainfrom
fix/issue-5722-unlock-key-format

Conversation

@jamengual
Copy link
Contributor

Summary

Problem

PR #5570 added logic to preserve apply locks after plan when no changes are detected. However, it introduced a bug where the unlock key format didn't match the lock key format:

  • Lock key: repo/path/workspace
  • Unlock key (buggy): repo/pullnum/projectname/workspace

This mismatch caused locks to never be released, blocking subsequent operations on projects in the same directory.

Solution

This PR corrects the unlock key to use the same format as the lock key, ensuring locks can be properly released when changes are detected.

Test plan

  • Updated existing test to expect the correct lock format
  • Manual testing with multiple projects in same directory
  • Verify locks are released when changes are detected
  • Verify locks are preserved when no changes are detected

Fixes #5722

🤖 Generated with Claude Code

When PR #5570 added logic to preserve apply locks after plan when no
changes are detected, it introduced a bug in the unlock key format.

The lock key uses: repo/path/workspace
But the unlock key was using: repo/pullnum/projectname/workspace

This mismatch caused locks to never be released, blocking subsequent
operations on projects in the same directory.

This commit fixes the unlock key to match the lock key format.

Fixes #5722

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added go Pull requests that update Go code size/s labels Sep 10, 2025
@dosubot dosubot bot added the bug Something isn't working label Sep 10, 2025
// delete lock only if there are changes
ctx.Log.Info("Deleting lock for project '%s' (changes detected)", projCtx.ProjectName)
lockID := projCtx.BaseRepo.FullName + "/" + strconv.Itoa(projCtx.Pull.Num) + "/" + projCtx.ProjectName + "/" + projCtx.Workspace
lockID := fmt.Sprintf("%s/%s/%s", projCtx.BaseRepo.FullName, projCtx.RepoRelDir, projCtx.Workspace)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this lockID used only for unlocking, effectively making it an unlockID? If so, and if we want to match the actual lock key format, could we create a function that enforces the same format for both locking and unlocking IDs? Or am I misunderstanding the underlying problem here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is a great idea, jus pushed the changes

jamengual and others added 3 commits September 11, 2025 11:34
Address review feedback by introducing generateLockID() function that ensures
consistent lock key format between lock acquisition and release. This function
uses models.NewProject() internally to apply consistent path cleaning logic.

The lock ID format is: repo/path/workspace where path is cleaned via path.Clean()
and empty paths become "." as per Go's path package behavior.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…separate strings

- Changed generateLockID to accept command.ProjectContext instead of 3 separate strings
- Added validation to ensure required fields (BaseRepo.FullName, Workspace) are not empty
- Made function exportable (GenerateLockID) for better testability
- Updated test to use the actual GenerateLockID function instead of hard-coded expected format
- This prevents passing arbitrary strings that could break lock format consistency

Addresses feedback on PR #5781 to enforce consistent lock format generation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
The BaseRepo.FullName and Workspace fields are guaranteed to be valid
by the time ProjectContext reaches GenerateLockID, as they are populated
from validated VCS pull request data during the BuildPlanCommands process.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
bschaatsbergen
bschaatsbergen previously approved these changes Sep 11, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 11, 2025
- Added GenerateLockKey function to models package for consistent lock key format
- Updated all lock key generation to use the centralized function:
  - BoltDB backend now uses models.GenerateLockKey
  - Redis backend now uses models.GenerateLockKey (preserving "pr/" prefix)
  - Locking client uses models.GenerateLockKey
  - NoOpLocker uses models.GenerateLockKey
- Modified GenerateLockID to use models.GenerateLockKey internally
- This ensures all locking operations use the exact same key format
- Removed duplicate fmt.Sprintf implementations across different components

All tests pass, maintaining backward compatibility while improving consistency.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
@jamengual jamengual force-pushed the fix/issue-5722-unlock-key-format branch from 998d9eb to 7b33ae0 Compare September 11, 2025 22:03
@jamengual jamengual merged commit 1ef63c5 into main Sep 11, 2025
40 of 41 checks passed
@jamengual jamengual deleted the fix/issue-5722-unlock-key-format branch September 11, 2025 22:26
@jamengual jamengual restored the fix/issue-5722-unlock-key-format branch September 11, 2025 22:38
ramonvermeulen pushed a commit to bschaatsbergen/atlantis that referenced this pull request Oct 13, 2025
…5781)

Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Ramon Vermeulen <ramonvermeulen98@gmail.com>
dimisjim pushed a commit to dimisjim/atlantis that referenced this pull request Oct 29, 2025
…5781)

Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: dimisjim <dimitris.moraitidis@gmail.com>
aidansteele pushed a commit to aidansteele/atlantis that referenced this pull request Mar 12, 2026
…5781)

Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code lgtm This PR has been approved by a maintainer size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected change in locking behaviour

2 participants