Skip to content

docs: add session file locking guidance to HARNESS.md#59

Open
JasonOA888 wants to merge 1 commit intoHKUDS:mainfrom
JasonOA888:docs/add-session-locking-guidance
Open

docs: add session file locking guidance to HARNESS.md#59
JasonOA888 wants to merge 1 commit intoHKUDS:mainfrom
JasonOA888:docs/add-session-locking-guidance

Conversation

@JasonOA888
Copy link

Summary

Following PR #52 (file locking fix), adds documentation to prevent similar bugs in future harness implementations.

Changes

Added new subsection "Session File Locking for Concurrency" to Critical Lessons Learned:

  • Code example showing proper fcntl.flock() usage
  • Explains why locking matters (concurrent CLI invocations)
  • Documents common pitfalls:
    • Use fcntl.flock(), not flock directly
    • Always release lock with LOCK_UN
    • Handle IOError/OSError for unsupported filesystems

Context

PR #52 fixed a race condition in anygen/agent-harness/session.py. This PR documents the pattern so future contributors don't make similar mistakes.

Testing

  • Documentation-only change
  • No code changes to test

Related: #51, #52

Following PR HKUDS#52, add a new subsection to 'Critical Lessons Learned'
documenting best practices for session file locking:

- Use fcntl.flock() for exclusive locking during writes
- Prevent race conditions in multi-session scenarios
- Handle filesystems that don't support flock
- Document common pitfalls (use fcntl.flock, not flock directly)

This prevents future contributors from making similar mistakes when
implementing session persistence.

Co-authored-by: yuh-yang <yuh-yang@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant