Repository navigation
fix(learning): hold the partition publication lock across the full skill write - #1230
Merged
Merged
Conversation
…ill write buildProcedureProcessor only acquired the per-partition assets.skillPublication lock inside the publishable branch, but skillmaterialize.Materialize (which creates the draft version) and skilllifecycle.Pipeline.Process both write assets.learnedSkills regardless of publishable. A non-publishable write (e.g. an untrusted workspace, demoted to Review) therefore ran fully unlocked, letting it race the foreground ListLearnedSkills RPC's own lock-guarded read (learnedSkillPublisher.publishPartition), which detects a mid-read generation change via a sentinel error and previously surfaced it as an opaque internal error to the caller. Reproduced reliably (~15-20% of runs) via: go test ./internal/app/... -run TestUsableAutoSkillsStockBuildPolicyMatrix -count=30 -race Fix: acquire the lock unconditionally, before any partition-mutating call in the closure, closing the actual synchronization gap instead of retrying past it. An earlier retry-based approach was reviewed and rejected because it silently changed the behavior TestADR_0259_DelayedPublicationCannotRevokeNewerGeneration pins; this version leaves that contract untouched (confirmed still green). Adds TestBuildProcedureProcessorHoldsPublicationLockForNonPublishablePartition, a deterministic regression test that fails if the lock's scope is ever narrowed again, rather than relying solely on the probabilistic e2e reproduction. Co-Authored-By: Claude Sonnet 5 <[email protected]>
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TestUsableAutoSkillsStockBuildPolicyMatrix/untrusted_project_ignored,internal/app/usable_auto_skills_matrix_e2e_test.go), reproduced ~15-20% of the time viago test -run TestUsableAutoSkillsStockBuildPolicyMatrix -count=30 -race, surfacing as an opaqueserver: internal error: learned skill operation failed.buildProcedureProcessor(internal/app/learned_skills.go) only acquired the per-partitionassets.skillPublicationlock inside thepublishablebranch.skillmaterialize.Materialize(creates the draft version) andskilllifecycle.Pipeline.Processboth write the sharedassets.learnedSkillsrepository regardless ofpublishable, so a non-publishable write (e.g. an untrusted workspace, demoted to Review) ran fully unlocked — racing the foregroundListLearnedSkillsRPC's own lock-guarded read (learnedSkillPublisher.publishPartition), which detects a mid-read generation change via a sentinel error (errLearnedSkillGenerationChanged) and surfaced it as a hard internal error.Path not taken
An earlier version retried on the read side instead of fixing the lock. It was rejected in review because it silently changed the contract
TestADR_0259_DelayedPublicationCannotRevokeNewerGenerationpins (a stale publisher must hard-error, never silently revive). This version leaves that test's contract untouched — confirmed still green.New coverage
Adds
TestBuildProcedureProcessorHoldsPublicationLockForNonPublishablePartition, a deterministic regression test (forces the write to pause mid-flight, asserts a concurrentlock()attempt on the same partition blocks until it finishes) — it caught an intermediate version of this fix that scoped the lock only aroundPipeline.Processand missedMaterialize's earlier write, so it's proven to fail if the lock's scope narrows again, not just probabilistically flake.Review
This is a concurrency fix (not test-only), so it went through three rounds of independent review (go-architect + test-adequacy + standards + duplication + library-reuse across the iterations) before opening this PR — including one round that caught the rejected retry-based approach, and a final round that caught the
Materializegap in an earlier version of this same fix. Final pass: no blockers; one advisory addressed (the lock now also spansPipeline.Process'sEvaluator.Evaluate, a possible LLM call, and the lock isn't ctx-aware — noted inline as aponytail:-flagged ceiling, not treated as a regression since correctness wins here).Test plan
go test ./internal/app/... -run TestBuildProcedureProcessorHoldsPublicationLockForNonPublishablePartition -count=3 -race— passes; fails without the fix (proven during development)go test ./internal/app/... -run 'TestADR_0259|TestLearnedSkillPublicationFailureQuarantinesOnlyOwnedPartitionsAndReconciles' -count=5 -race— all pass, no regressiongo test ./internal/app/... -run TestUsableAutoSkillsStockBuildPolicyMatrix -count=30 -race— 30/30 pass (was ~15-20% failure rate before)go test ./internal/app/... -run 'Skill|Learn|Reflection|Procedure' -count=3— all passtask lint— 0 issuesgo build ./...Co-Authored-By: Claude Sonnet 5 [email protected]