Skip to content

fix(selfhost): use ownership tokens for transient PR actuation locks - #2991

Closed
RealDiligent wants to merge 1 commit into
JSONbored:mainfrom
RealDiligent:fix/transient-lock-ownership-release
Closed

fix(selfhost): use ownership tokens for transient PR actuation locks#2991
RealDiligent wants to merge 1 commit into
JSONbored:mainfrom
RealDiligent:fix/transient-lock-ownership-release

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Problem

Self-host PR actuation (maintenance merge/close, draft-dodge, reopen-reclose) and AI-review dedup mutexes use SELFHOST_TRANSIENT_CACHE.claim() for atomic acquisition, but release was an unconditional del(). The code documented this as a KNOWN LIMITATION: if holder A runs past the TTL, holder B claims the lock, and A's stale finally runs, A deletes B's live lock — reopening the exact race #2129/#2135 exists to close.

Root cause

claimTransientLock() stored a constant "1" and releasePrActuationLock / releaseAiReviewLock called blind del(key) with no ownership check.

Solution

  • Add releaseIfValue(key, token) to createRedisCache (Redis Lua compare-and-delete)
  • Extend SELFHOST_TRANSIENT_CACHE with optional releaseIfValue
  • Claim with randomUUID() owner tokens; release only when token still matches
  • Fail-open paths (ownerToken: null) skip release; adapters without releaseIfValue rely on TTL instead of blind del()

Testing

  • npm run typecheck
  • npx vitest run test/unit/selfhost-redis-cache.test.ts (7/7)
  • Lock regression suite in test/unit/queue.test.ts (claim/release + concurrent claim + stale-holder regression)
  • Updated ai-review-advisory.test.ts for new claim return shape
  • CI (Linux) green including codecov/patch ≥ 99%

Compatibility

  • Exported lock helpers now return TransientLockClaim { acquired, ownerToken } instead of boolean (internal/test surface; all call sites updated)
  • release*Lock functions take an additional ownerToken argument

Per-PR actuation and AI-review mutexes claimed Redis keys with a constant
value and released via blind del(). A holder running past the TTL could
delete a successor's live lock in finally, reopening merge/close races the
mutex exists to prevent (JSONbored#2129/JSONbored#2135).

Store a per-holder UUID at claim time and release with compare-and-delete
(releaseIfValue) on the Redis cache adapter. Skip release when fail-open
(no cache) or when the adapter lacks compare-and-delete (TTL backstop).

Co-authored-by: Cursor <cursoragent@cursor.com>
@RealDiligent
RealDiligent requested a review from JSONbored as a code owner July 4, 2026 08:50
@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 4, 2026
@loopover-orb

loopover-orb Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Caution

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

🛑 Gittensory review result - fixes required

Review updated: 2026-07-04 08:55:21 UTC

7 files · 1 AI reviewer · no blockers · readiness 80/100 · CI failing · unstable

🛑 Suggested Action - Fix Blockers

  • Touches a guarded path — held for manual review

Review summary
The change replaces blind transient-lock deletion with owner-token claims and compare-and-delete release, which directly closes the stale-holder race described in the PR. The queue call sites correctly retain the returned token through their finally blocks, and adapters without `releaseIfValue` now fail safe by relying on TTL instead of deleting an unverified key. The Redis implementation uses a single Lua eval for atomicity, and the added regression test exercises the successor-token preservation path.

Nits — 5 non-blocking
  • nit: `src/env.d.ts:34` still says callers fall back to a non-atomic get/set pair when `claim` is absent, but `claimTransientLock` now intentionally fails open instead, so that comment should be updated to match the current contract.
  • nit: `test/unit/queue.test.ts:5156` simulates TTL expiry by overwriting the key with `set`, which proves compare-and-delete behavior but does not show the real successor claim path; a short comment would keep future readers from mistaking this for an end-to-end expiry test.
  • In `src/env.d.ts:34`, revise the `claim` doc to say absence means no serialization/fail-open, matching `src/queue/processors.ts:3378`.
  • In `test/unit/queue.test.ts:5156`, either comment that the overwrite is deliberately standing in for TTL expiry plus successor acquisition, or model it through the cache primitive if the helper can support expiry manipulation later.
  • Touches a guarded path — held for manual review — A maintainer must review and merge this change.

CI checks failing

  • codecov/patch — 96.15% of diff hit (target 99.00%)
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ No-issue rationale PR body explains why no issue is linked.
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (no linked issue context).
Validation posture ❌ 5/25 Preflight is holding this PR: the review lane is unavailable, so it is not ready for automated review.
Contributor workload ✅ 10/10 Author activity: 123 registered-repo PR(s), 13 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 123 PR(s), 0 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Official Gittensor activity: 123 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Await review-lane availability.
  • Refresh registry data or choose a registered active repo.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.06%. Comparing base (706d1c1) to head (510f5c1).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/queue/processors.ts 95.83% 0 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (96.15%) is below the target coverage (99.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2991      +/-   ##
==========================================
- Coverage   96.06%   96.06%   -0.01%     
==========================================
  Files         260      260              
  Lines       28687    28699      +12     
  Branches    10436    10439       +3     
==========================================
+ Hits        27558    27569      +11     
  Misses        493      493              
- Partials      636      637       +1     
Files with missing lines Coverage Δ
src/selfhost/redis-cache.ts 100.00% <100.00%> (ø)
src/queue/processors.ts 92.73% <95.83%> (-0.02%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb

loopover-orb Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Gittensory is closing this pull request on the maintainer's behalf (CI is failing (codecov/patch)). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant