Skip to content

refactor(provider): share operation lock helper - #1535

Merged
skevetter merged 1 commit into
mainfrom
refactor/provider-share-operation-lock
Oct 18, 2026
Merged

skevetter merged 1 commit into
mainfrom
refactor/provider-share-operation-lock

Conversation

@skevetter

@skevetter skevetter commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds provider.LockProvider and provider.LockProviderNamed in pkg/provider/operationlock.go. Each acquires the provider operation lock and returns an unlock func. Migrates 9 duplicated GetProviderOperationLock -> Lock() -> defer Unlock() sites to them. Error strings are byte-identical.

Why

Nine call sites repeated the same 9-line lock block with the same error wrapping. The for <name> variant is kept only where it already existed (add.go, rename.go), via LockProviderNamed.

Skipped pkg/workspace/provider_update.go: it returns the get-lock error bare, so migrating would add a get operation lock: prefix and change error text.

Validation

  • mise run cli:format: no changes
  • mise run cli:lint:ci: 0 issues
  • go build ./...: ok
  • go vet on pkg/provider, cmd/provider, cmd/pro, cmd/mcp, pkg/workspace: clean
  • go test -count=1 ./pkg/provider/... ./cmd/provider/... ./cmd/pro/... ./cmd/mcp/... ./pkg/workspace/...: all ok
  • New TestLockProvider* tests: pass

CodeRabbit CLI

coderabbit review --agent --committed --base-commit e0fe773ad: completed, 0 findings, 11 files reviewed.

Auto-merge

Eligible: yes. Behaviour-preserving, no go.mod/go.sum, workflow, lint config, secret, or credential/auth changes, and no tests removed or weakened.

Summary by CodeRabbit

  • Reliability
    • Provider management commands now use consistent locking when adding, updating, deleting, renaming, initializing, selecting, or changing provider settings. This helps coordinate simultaneous operations on providers and ensures locks are released when commands finish or encounter an error.

@skevetter skevetter added the auto-refactor Automated refactor PR label Oct 18, 2026
@netlify

netlify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 980706a
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6ad40f60179f225ed99371cf

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 21b03dbb-50c3-4de6-acae-10f65afd08f5
📥 Commits

Reviewing files that changed from the base of the PR and between e0fe773 and 980706a.

📒 Files selected for processing: 11
  • cmd/mcp/tools_provider.go
  • cmd/pro/update_provider.go
  • cmd/provider/add.go
  • cmd/provider/delete.go
  • cmd/provider/init.go
  • cmd/provider/rename.go
  • cmd/provider/set.go
  • cmd/provider/set_source.go
  • cmd/provider/use.go
  • pkg/provider/operationlock.go
  • pkg/provider/operationlock_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Walkthrough

Provider operation-lock acquisition is now handled by shared helper functions. Provider commands use those helpers and defer the returned unlock callbacks. Tests cover lock lifetime and errors for invalid provider names.

Changes: Provider lock migration

Layer / File(s) Summary
Provider lock helpers
pkg/provider/operationlock.go, pkg/provider/operationlock_test.go
Added LockProvider and LockProviderNamed to acquire operation locks and return unlock callbacks. Tests check lock lifetime, invalid-name errors, and name context.
Command lock adoption
cmd/provider/*.go, cmd/mcp/tools_provider.go, cmd/pro/update_provider.go
Provider commands now use the shared helpers and defer the returned unlock callbacks. They return lock acquisition errors directly.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 98070

The provider lock refactor has no identified merge-blocking issue and is ready to merge after normal checks.

Security architecture risk: ⚪ Minimal · up to 98070

The shared helpers preserve the existing provider-name validation, lock identity, acquisition order, release timing, and error behavior. The reviewed changes do not expand tool authority or weaken provider-operation serialization. No introduced or worsened security concern was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed synchronization contract affects existing provider lifecycle operations addressed by context and provider name. The inspected MCP path retains the same tool input, configuration-selected context, and deletion delegation, so this refactor does not expand that tool's authority.

Trust Boundaries and Controls

  • observed — Caller-supplied provider names still pass through GetProviderOperationLock validation before lock-file construction. MCP deletion and provider use retain operation-lock acquisition before their protected provider-state operations; the new helper does not bypass that control.

Resilience and Maintainability Implications

  • observed — Release errors remain discarded, as they were in the duplicated caller blocks. This is pre-existing failure handling, not a newly introduced loss of release-error visibility.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: introducing a shared provider operation lock helper and migrating callers to it.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@netlify

netlify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 980706a
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6ad40f60bf220d2551086ad4

@skevetter
skevetter marked this pull request as ready for review October 18, 2026 01:14
@mergify

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@skevetter
skevetter merged commit bb77dd3 into main Oct 18, 2026
199 of 201 checks passed
@skevetter
skevetter deleted the refactor/provider-share-operation-lock branch October 18, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-refactor Automated refactor PR size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant