rrrrrredy/research-toolkit / plugins/research-toolkit
research-toolkit
FlaggedUse for source-backed long-form research and writing in English or Chinese across fields, including revisions and continuation. Understand requirements, develop analysis through substantive research collaboration, and deliver a complete report after independent review, audit and acceptance.
scripts/task_lock.py
View on GitHub"""Fail-fast, process-owned locks for cooperating local task operations."""
from contextlib import contextmanager
import os
from pathlib import Path
import threading
from task_storage import file_io_path
_held = threading.local()
@contextmanager
def task_lock(root: Path):
# Reentrant only for this thread/process (start may read its own status).
root = file_io_path(root)
identity = (os.getpid(), str(root.resolve()))
held = getattr(_held, "paths", set())
if identity in held:
yield
return
# Keep the inode/file in place: unlinking after release could split waiters
# across two independent locks. OS ownership, not file existence, is the lock.
lock_path = (root / ".research-toolkit.lock").resolve()
lock_path.relative_to(root.resolve())
with lock_path.open("a+b") as stream:
try:
if os.name == "nt":
import msvcrt
stream.seek(0)
msvcrt.locking(stream.fileno(), msvcrt.LK_NBLCK, 1)
else:
import fcntl
fcntl.flock(stream.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError as exc:
raise ValueError("This task already has an active operation or its lock is unavailable. "
"Wait for that operation to finish; do not start duplicate reviews.") from exc
_held.paths = held | {identity}
try:
yield
finally:
_held.paths = held
if os.name == "nt":
stream.seek(0)
msvcrt.locking(stream.fileno(), msvcrt.LK_UNLCK, 1)
else:
fcntl.flock(stream.fileno(), fcntl.LOCK_UN)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |