fix(ttsc): fence source-plugin lock generations#460
Merged
Conversation
Replace path deletion with generation-fenced directory retirement. A non-empty current generation is acquired by atomic rename, and every release or reclaim leaves a deterministic non-empty tombstone that rejects delayed finalizers and stale observers. Constraint: Ownership fencing must work across processes and supported platforms without read-compare-delete. Rejected: Recursive lock-path deletion | a stale observer can delete a successor generation. Confidence: high Scope-risk: moderate Directive: Keep retired generation directories non-empty; they are the atomic fencing record. Tested: Diff integrity only before the requested post-PR review sequence. Not-tested: Targeted lock tests pending three exhaustive reviews. Related: #452
Publish each legacy fence as a complete non-empty directory through atomic rename. A process killed while preparing its unique candidate can leave only an ignorable candidate, never a truncated canonical fence. Constraint: Legacy observation must retain the original directory age while adding a shared generation. Rejected: Exclusive direct file write | a crash can leave a partial canonical record. Confidence: high Scope-risk: narrow Directive: Publish canonical ownership metadata only after its candidate is complete. Tested: Review round 1 and diff integrity; runtime tests remain deferred until round 3. Not-tested: Local build and targeted tests pending. Related: #452
Prepare legacy fence candidates beside the observed lock so contender setup cannot advance the lock directory mtime. The winning canonical fence therefore retains the pre-observation age even when multiple processes race. Constraint: Stale legacy classification must remain deterministic without timing hooks or process-local coordination. Rejected: Candidate directories inside the legacy lock | their creation mutates the age being measured. Confidence: high Scope-risk: narrow Directive: Do not create pre-publication artifacts inside an unfenced legacy lock. Tested: Exhaustive review round 2 and diff integrity; v2 timeout assertions added. Not-tested: Runtime tests remain deferred until review round 3. Related: #452
Stage the two observer processes so the first successor remains current at a build barrier while the second acts with its stale fence. This removes scheduler luck from the core survival assertion and proves only one successor publishes. Constraint: Multi-process regression tests must use explicit filesystem barriers, not timing assumptions or monkeypatches. Rejected: Releasing both stale observers together | a vulnerable implementation can pass under a favorable schedule. Confidence: high Scope-risk: narrow Directive: Keep observer B blocked until observer A's successor lease is externally visible. Tested: Exhaustive review round 3 and diff integrity. Not-tested: Runtime tests pending the required clean review round. Related: #452
Legacy holders delete the entire historical lock path, so v2 generations now live in an orthogonal persistent coordination directory. Protocol initialization is atomically published, legacy reclaim revalidates its fence, and abandonment is reported only after successful retirement. Constraint: Legacy holders remove the whole .lock directory by pathname Rejected: Reuse .lock for v2 ownership | no cross-platform conditional rename can close the legacy release/reclaim TOCTOU Confidence: high Scope-risk: moderate Directive: Keep legacy .lock and v2 .lock.v2 ownership namespaces disjoint Tested: pnpm --filter ttsc build; 18 targeted source-plugin lock, handoff, GC, and CLI E2E tests Not-tested: Full repository test suite Related: #452
This was referenced Jul 15, 2026
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.
Intent
Prevent stale source-plugin lock observers, delayed holder finalizers, and legacy pathname cleanup from deleting a successor generation.
Scope
<key>.lockseparate from persistent v2 ownership at<key>.lock.v2Verification
pnpm --filter ttsc buildCloses #452