Skip to content

Add snapshot file locking - #2

Merged
Mattie merged 6 commits into
mainfrom
codex/snapshot-locked
Jul 4, 2026
Merged

Add snapshot file locking#2
Mattie merged 6 commits into
mainfrom
codex/snapshot-locked

Conversation

@Mattie

@Mattie Mattie commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

Adds cooperative per-file snapshot locking for local cross-process writers.

  • Adds snapshot.locked(reload=True) using a sidecar .lock file and OS-level locking on Windows/POSIX.
  • Adds require_lock=True for manual persisted models so saves must happen inside a snapshot lock.
  • Updates collection creation, Model.Meta, create_model, and sync surfaces to respect the lock requirement.
  • Documents the shared-file pattern and updates packaged snapclass fluency guidance.
  • Bumps the package version to 0.1.3.

Why

Shared snapclass instances can lose updates when multiple local processes load the same stale file, mutate independently, and save. The new pattern gives writers an explicit critical section: acquire the file lock, reload, mutate, save, and release.

Validation

  • python.exe -m pytest tests/test_snapshot_locking.py
  • python.exe -m pytest

Full suite result: 333 passed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds cooperative, cross-process snapshot file locking via a .lock sidecar file, and introduces an opt-in require_lock mode to enforce “save only while locked” for manual/persisted models—backed by new tests and updated documentation.

Changes:

  • Add Snapshot.locked(reload=True) and OS-level per-file locking (Windows/POSIX) via new _locks.py.
  • Add require_lock configuration through snapclass, Model.Meta, create_model, and sync, and enforce it on snapshot writes.
  • Add/extend tests and docs (README + fluency skill docs), and bump version to 0.1.3.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_sync.py Verifies sync(..., require_lock=True) enforces locked saves for manual snapshots.
tests/test_snapshot_locking.py New test suite covering reload-under-lock, cross-process coordination, and lock release behavior.
tests/test_model_meta.py Ensures Model.Meta.snapshot_require_lock wiring and enforcement works, plus create_model(..., require_lock=True) support.
src/snapclass/skills/snapclass-fluency/SKILL.md Documents the intended snapshot.locked(reload=True) + require_lock=True shared-file pattern.
src/snapclass/schemas.py Implements require_lock, adds Snapshot.locked(), and routes write locking through the new lock module.
src/snapclass/collections.py Updates get_or_create to use snapshot locking when require_lock is enabled.
src/snapclass/_locks.py New locking implementation combining per-path re-entrant thread locks and OS-level file locks.
skills/snapclass-fluency/SKILL.md Duplicates the fluency guidance update in the non-packaged skills path.
README.md Adds shared-file coordination documentation and recommended usage pattern.
pyproject.toml Bumps package version to 0.1.3.
.gitignore Adds .todo/ ignore entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/snapclass/schemas.py
Comment thread src/snapclass/schemas.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e4c5118e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/snapclass/schemas.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c7f0dc263

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/snapclass/sidecar.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Comment thread src/snapclass/_locks.py
Comment thread src/snapclass/_locks.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 379b9cf214

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/snapclass/_locks.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Comment thread src/snapclass/_locks.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57ae8c542c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/snapclass/_locks.py
Comment thread src/snapclass/sidecar.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5a5911df3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/snapclass/schemas.py
@Mattie
Mattie merged commit e524a8b into main Jul 4, 2026
4 checks passed
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.

2 participants