Skip to content

Conversation

@AdaInTheLab
Copy link
Owner

🧿 Prevent FS Sync from Overwriting Admin-Edited Notes

This PR hardens the Lab Notes sync pipeline so filesystem imports never silently overwrite admin-authored content, while still allowing explicit overrides when intended.

✨ What Changed

Ownership-aware sync

  • Treats filesystem (import) and admin UI (web) as distinct truth channels
  • Pointer updates are now guarded based on revision source, not status

Safe by default

  • If the current revision is admin-authored (source='web'), FS sync:
    • Still ingests the import revision (ledger completeness preserved)
    • Does not advance current_revision_id or published_revision_id
  • Prevents accidental clobbering of drafts and published notes

Explicit override

  • Added force option to sync:
    • POST /admin/notes/sync?force=1
    • Allows filesystem content to intentionally replace admin revisions
  • Force mode also advances pointers even when content is unchanged

Visibility

  • Sync results now report:
    • pointersSkippedProtected
    • pointersForced
    • Optional capped list of protected notes (slug, locale, reason)

🔒 Guard Logic (Summary)

Pointer updates are allowed only if:

  • force === true, or
  • The note has no current revision (new note), or
  • The current revision source is already import

Otherwise, admin-owned revisions are protected.


🧪 Tests

Added coverage to assert:

  • Admin (web) revisions are not overwritten by FS sync
  • Force sync correctly advances pointers to import revisions
  • Idempotent sync + force still updates pointers as expected

🧠 Why This Matters

This change prevents a subtle but high-impact failure mode where:

  • Admin edits (including published content) could be silently replaced by repo syncs

The result is a clear, intentional content model:

  • Source ownership > status
  • Imports are safe by default
  • Overrides are explicit and auditable

📌 No Schema Changes

This PR is backend-only and uses existing fields (lab_note_revisions.source) to enforce correctness.


co-authored-by: Lyric lyric@thehumanpatternlab.com
co-authored-by: Carmel carmel@thehumanpatternlab.com

- Guard pointer updates when current revision source is 'web'
- Allow force sync to explicitly override protection
- Handle force pointer advance even when content is unchanged
- Track protected admin drafts and forced pointer updates for visibility

co-authored-by: Lyric <lyric@thehumanpatternlab.com>
co-authored-by: Carmel <carmel@thehumanpatternlab.com>
@AdaInTheLab AdaInTheLab merged commit ef906aa into main Jan 10, 2026
1 check passed
@AdaInTheLab AdaInTheLab deleted the bugfix/sync-overwrite branch January 10, 2026 14:25
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