Skip to content

Implement file-based locking system #3

@t3chn

Description

@t3chn

Task: Implement file-based locking system

Description

Create lock script that provides file-based locking with TTL (time-to-live) functionality to prevent concurrent access to shared resources like GitHub issues and sync operations.

Acceptance Criteria

  • Script supports acquire|release <name> [ttl_s] interface
  • Default TTL is 1800 seconds (30 minutes)
  • Lock files stored in .claude/locks/ directory
  • Acquire returns exit code 16 if resource already locked
  • Acquire returns exit code 0 if lock successfully acquired
  • Release removes lock file and returns exit code 0
  • Automatic lock expiration based on TTL timestamp
  • Lock files contain timestamp for TTL validation
  • Directory .claude/locks/ is created if it doesn't exist
  • Handles concurrent lock attempts safely

Technical Details

Implementation approach:

  • Use filesystem operations for atomic lock creation
  • Store timestamp in lock file for TTL validation
  • Check TTL on acquire attempts and clean expired locks
  • Use trap handlers for cleanup on script interruption

Key considerations:

  • Race condition handling for concurrent acquire attempts
  • Atomic file operations to prevent partial lock states
  • Performance: lock operations must complete in < 100ms
  • TTL cleanup prevents permanent lock situations

Code locations/files affected:

  • Create: .claude/scripts/pm/lock
  • Create: .claude/locks/ directory structure
  • Make executable: chmod +x .claude/scripts/pm/lock

Dependencies

  • Understanding of filesystem lock semantics
  • Testing environment for concurrent lock scenarios
  • Shell scripting experience with file operations

Effort Estimate

  • Size: M
  • Hours: 2 hours
  • Parallel: true (independent from validation system)

Definition of Done

  • Lock script implements acquire/release interface
  • TTL functionality works correctly with automatic cleanup
  • Concurrent lock attempts handled safely (race conditions tested)
  • Exit codes match specification (0 for success, 16 for already locked)
  • Performance validated (< 100ms for lock operations)
  • Manual testing with various TTL values and concurrent scenarios
  • Error handling for permission issues and disk space

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions