Skip to content

[Fix] Refuse to overwrite an existing engagement during creation - #769

Closed
rudycelekli wants to merge 2 commits into
Z4nzu:masterfrom
rudycelekli:fix/data-create-preserve-20260929
Closed

rudycelekli wants to merge 2 commits into
Z4nzu:masterfrom
rudycelekli:fix/data-create-preserve-20260929

Conversation

@rudycelekli

Copy link
Copy Markdown

Summary

Calling create twice with the same name currently silently resets persisted engagement metadata and run history. Stage the complete initial document and publish it with a same-filesystem hard link, which atomically fails with FileExistsError if the name already exists. This also protects concurrent creators. get_or_create remains the explicit reuse path. The project targets Linux/macOS; publication requires a filesystem supporting hard links.

Reproduction and verification

A saved engagement with scope exclusions and run history remains byte-for-byte identical after a rejected duplicate create; get_or_create reuses it. A deterministic two-thread barrier proves exactly one concurrent creator succeeds, the winning document loads intact, and staging directories are cleaned.

  • Focused regression fails on upstream master ef5334f8d37e5be2eecbf56e334f5e3f0f6817ec: persistent before log records the failure.
  • Focused regression after fix: 2 passed in 0.03s.
  • Full make check on this branch: ruff gate passes; 280 passed in 3.58s.
  • Tests use temporary local workspaces and mocks/local Python subprocesses.

Type of change

  • Bug fix

Checklist

  • Title uses [Fix]
  • One logical change
  • Ran full make check locally
  • Added regression coverage
  • New tool/catalog checklist: not applicable.

Combined batch validation

The exact clean integration 52e549a68214d81ed2f5dad0130a241aeeb14375 containing all 20 independent fixes passed make check: 401 tests passed, full required Ruff gate, and catalog/taxonomy conformance. Individual branch results above are separate from this combined result. Overlapping configuration hunks were combined preserving atomic persistence, error handling, shape validation and UTF-8 encodings. No production state, external security scans or paid model calls were used. GitHub CI will run separately after publication.

@rahul05ranjan

Copy link
Copy Markdown

Good — create() previously did e.save() which would happily overwrite an existing engagement with the same name. Using os.link for an atomic "fail if exists" is a clean trick, and the concurrent-creators test with a Barrier is a genuinely good test.

One portability concern: os.link (hard link) isn't supported on all filesystems — notably some network mounts and Windows (though this is a Linux tool, so probably fine). If the target filesystem doesn't support hard links, create() will raise OSError even when no engagement exists. os.open with O_CREAT | O_EXCL would be more portable and equally atomic. Worth considering.

Also, create() now raises FileExistsError on a duplicate — is the caller (get_or_create?) handling that, or does it propagate to the user as a traceback? The test expects the raise, but I'd want to confirm the CLI catches it and prints a friendly message.

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
@rudycelekli

Copy link
Copy Markdown
Author

Confirmed sequential get_or_create() reuses the saved engagement, but a concurrent creation or a filesystem without hard-link support could still escape through the CLI. Fixed that error path in 0153810: the CLI now prints a workspace error and exits with status 1. Two actual-main regressions exercise unsupported links and a competing completed publication; neither replaces saved data, and staging is cleaned. Full make check passes (282 tests, Ruff, catalog validation). Hard-link publication deliberately remains fail-closed on unsupported filesystems: opening the final JSON with O_EXCL would reserve the name atomically but expose the document before its contents were complete. No portability fallback is claimed.

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.

3 participants