fix(#6448): add flock serialization to ImportProfiles - #6449
Conversation
|
🤖 Finished Review · ✅ Success · Started 12:38 PM UTC · Completed 12:52 PM UTC Commit: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ReviewFindingsLow
Previous runLooks good to me Previous run (2)ReviewFindingsLow
Previous run (3)ReviewFindingsLow
|
maruiz93
left a comment
There was a problem hiding this comment.
2 findings (2 medium). Production code logic looks correct — the flock + double-check pattern mirrors ImportProfile. Issues are test coverage gaps.
|
/fs-fix |
|
🤖 Finished Fix · ✅ Success · Started 1:02 PM UTC · Completed 1:13 PM UTC Commit: |
- Extract profileDirTempPath(dir, ext) shared helper to eliminate duplicated abs-resolve + hash + join logic between profileCachePath and profileDirLockPath, mirroring the existing profileTempPath pattern - Add TestImportProfiles_DoubleCheckCacheHit covering the double-check cache path after lock acquisition - Add TestImportProfiles_LockOpenFailure covering the lock open error path - Patch coverage for changed functions now meets the 80% threshold Addresses review feedback on #6449
🔧 Fix agent — iteration 1 (human-triggered)Addressed 3 of 4 review findings. Extracted profileDirTempPath shared helper to eliminate DRY violation. Added two new tests covering the double-check cache hit path and lock open failure error path, raising patch coverage for ImportProfiles to 87.5% and profileDirTempPath to 80%. Disagreed with adding a .feature behaviour test (out of scope for this PR). Fixed (3):
Disagreed (1):
Tests: passedNext steps:
|
|
🤖 Review · ❌ Terminated · Started 1:14 PM UTC · Ended 1:28 PM UTC Commit: |
|
/fs-fix rebase onto main first, then add the missing behaviour test — the inline comment on sandbox_test.go requesting a .feature scenario was not addressed in the last iteration |
|
🤖 Finished Fix · ✅ Success · Started 1:17 PM UTC · Completed 1:33 PM UTC Commit: |
ImportProfiles (batch) performed delete+reimport without flock protection, causing races under parallel execution. When multiple processes saw a hash cache miss simultaneously, each deleted and reimported the same profiles, and concurrent EnsureProvider calls hit "unsupported provider type or profile" during the delete window. Add the same flock serialization pattern that ImportProfile (singular) already uses: acquire an exclusive file lock keyed by directory path, double-check the hash cache after acquisition, then perform delete+reimport inside the critical section. This is the third instance of this race class, after #6421 and #6437. Add profileDirLockPath helper for directory-keyed lock paths and a concurrent-safety test using the same marker-file technique as TestImportProfile_FlockSerializesConcurrent. Note: pre-commit could not run (sandbox network policy blocked git fetch). go vet passed. golangci-lint was not available in the sandbox. Closes #6448
- Extract profileDirTempPath(dir, ext) shared helper to eliminate duplicated abs-resolve + hash + join logic between profileCachePath and profileDirLockPath, mirroring the existing profileTempPath pattern - Add TestImportProfiles_DoubleCheckCacheHit covering the double-check cache path after lock acquisition - Add TestImportProfiles_LockOpenFailure covering the lock open error path - Patch coverage for changed functions now meets the 80% threshold Addresses review feedback on #6449
|
🤖 Finished Review · ✅ Success · Started 1:14 PM UTC · Completed 1:28 PM UTC Commit: |
Add a .feature file exercising ImportProfiles through the real openshell gateway via provider-backed harnesses. Two scenarios declare providers: [github], triggering the providers-v2 code path that calls ImportProfiles. Under GODOG_CONCURRENCY > 1 both scenarios run alongside others, exercising the flock serialization added in #6448 at the e2e level. Addresses review feedback on #6449
🔧 Fix agent — iteration 2 (human-triggered)Rebased onto main and added the missing behaviour test. Created e2e/behaviour/features/sandbox/profile-import.feature with two provider-backed harness scenarios that exercise ImportProfiles against the real openshell gateway under concurrent execution. Fixed (2):
Tests: passedNext steps:
|
19bb8b9 to
dcfe0a1
Compare
|
🤖 Finished Review · ✅ Success · Started 1:35 PM UTC · Completed 1:50 PM UTC Commit: |
maruiz93
left a comment
There was a problem hiding this comment.
The behaviour test runs each scenario on a separate gateway — it can't reproduce the race. Drop it.
|
/fs-fix |
|
🤖 Finished Fix · ✅ Success · Started 2:09 PM UTC · Completed 2:15 PM UTC Commit: |
The profile-import.feature scenarios each run on a separate gateway via AllocateRepo, so they cannot reproduce the concurrent-delete race that the flock serialization fixes. The unit-level concurrency tests and the functional test suite (parallelism=4) already cover this. Addresses review feedback on #6449
🔧 Fix agent — iteration 3 (human-triggered)Dropped the e2e behaviour test file per reviewer feedback — it cannot exercise the concurrent-delete race because each scenario runs on a separate gateway. Fixed (1):
Tests: passedNext steps:
|
|
🤖 Finished Review · ✅ Success · Started 2:17 PM UTC · Completed 2:32 PM UTC Commit: |
|
🤖 Finished Retro · ✅ Success · Started 2:51 PM UTC · Completed 3:04 PM UTC Commit: |
|
PR #6449 (
If the fix agent had provided an architecture-based disagreement ("this can't work because scenarios are gateway-isolated"), the human would likely have accepted it, saving iterations 2 and 3. One proposal addresses this. Evidence for existing issues (not re-proposed):
Autonomy note: The review agent's initial approval with only 1 low finding (vs. 2 human medium findings) is a review quality gap for coverage awareness. However, the human's behaviour test suggestion was itself architecturally invalid — the agent's instinct not to add it was correct in substance. Proposals filed |
Summary
Add flock serialization to
ImportProfiles(batch) to prevent races under parallel execution. This mirrors the existing flock pattern inImportProfile(singular), which was fixed in #6421 and #6437. Withparallelism=4in functional tests, all processes could simultaneously see a cache miss, each deleting and reimporting the same profiles, causing concurrentEnsureProvidercalls to hit "unsupported provider type or profile" during the delete window.Related Issue
Closes #6448
Changes
profileDirLockPath(dir)helper for directory-keyed flock pathsImportProfiles' delete+reimport critical section insyscall.Flock(LOCK_EX)with double-check cache patternImportProfilesdoc comment to document concurrency safetyTestProfileDirLockPath_DeterministicAndUniqueunit testTestImportProfiles_FlockSerializesConcurrentconcurrency test (12 goroutines, marker-file overlap detection)Testing
TestImportProfiles_*tests passTestImportProfiles_FlockSerializesConcurrentproves serialization (12 goroutines, marker file detects overlap)TestProfileDirLockPath_DeterministicAndUniqueverifies lock path propertiesgo test -race ./internal/sandbox/...passesChecklist
!for breaking changes)Closes #6448
Post-script verification
agent/6448-importprofiles-flock)9c4ca5c656fbe3e587f03827443517b6188cd442..HEAD)