Skip to content

Conversation

@elias-ba
Copy link
Contributor

@elias-ba elias-ba commented Dec 10, 2025

Description

This PR fixes two bugs in create_checkpoint/1 that would crash the PersistenceWriter after 500 document updates:

  1. Used .data instead of .state_data when accessing DocumentState records
  2. Used string "checkpoint" instead of atom :checkpoint for the Ecto.Enum version field

Closes #4176

Validation steps

mix test test/lightning/collaboration/document_supervisor_test.exs:818

Additional notes for the reviewer

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

Pre-submission checklist

  • I have performed a self-review of my code.
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

@github-project-automation github-project-automation bot moved this to New Issues in v2 Dec 10, 2025
@elias-ba elias-ba changed the title Fix incorrect field access in create_checkpoint fix: incorrect field access in create_checkpoint Dec 10, 2025
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.10%. Comparing base (9722ea3) to head (93aeff0).
⚠️ Report is 1 commits behind head on 4164-fix-nil-lock-version-crash.

Additional details and impacted files
@@                         Coverage Diff                         @@
##           4164-fix-nil-lock-version-crash    #4178      +/-   ##
===================================================================
+ Coverage                            89.04%   89.10%   +0.06%     
===================================================================
  Files                                  425      425              
  Lines                                19658    19658              
===================================================================
+ Hits                                 17504    17516      +12     
+ Misses                                2154     2142      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@elias-ba elias-ba force-pushed the 4176-checkpoint-state-data-field branch 2 times, most recently from bd14d5b to 6fd1ec1 Compare December 10, 2025 15:23
@elias-ba elias-ba requested a review from stuartc December 10, 2025 15:27
@elias-ba elias-ba requested a review from midigofrank December 10, 2025 15:32
elias-ba added a commit that referenced this pull request Dec 10, 2025
Move duplicated checkpoint and update query logic from Persistence and
PersistenceWriter into DocumentState module where data access belongs.

- Add get_checkpoint_and_updates/1, get_latest_checkpoint/1,
  get_updates_since/2, apply_to_doc/3, and load_into_doc/2 functions
- Update Persistence to use shared DocumentState functions
- Update PersistenceWriter.merge_updates/2 to use DocumentState.load_into_doc/2
- Remove duplicated load_persisted_state_into_doc/2 from PersistenceWriter
- Add @type t and proper @SPEC annotations to DocumentState

This eliminates code duplication while keeping the fix focused and
avoiding conflicts with #4178.
The create_checkpoint/1 function was using .data instead of .state_data
when accessing DocumentState records. This would cause a KeyError crash
when a document reached 500 updates and triggered checkpoint creation.

Closes #4176
Two bugs fixed in create_checkpoint/1:
1. Used .data instead of .state_data when accessing DocumentState records
2. Used string "checkpoint" instead of atom :checkpoint for Ecto.Enum

Added tests to verify checkpoint creation works correctly:
- Test creating checkpoint from multiple updates
- Test merging existing checkpoint with new updates

Both bugs would cause crashes when a document reached 500 updates
and triggered automatic checkpoint creation.

Closes #4176
@elias-ba elias-ba force-pushed the 4176-checkpoint-state-data-field branch from 6fd1ec1 to 93aeff0 Compare December 10, 2025 16:11
@elias-ba elias-ba changed the base branch from main to 4164-fix-nil-lock-version-crash December 10, 2025 16:12
@midigofrank midigofrank merged commit 7578dd2 into 4164-fix-nil-lock-version-crash Dec 11, 2025
8 checks passed
@midigofrank midigofrank deleted the 4176-checkpoint-state-data-field branch December 11, 2025 07:03
@github-project-automation github-project-automation bot moved this from New Issues to Done in v2 Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

create_checkpoint uses non-existent .data field instead of .state_data

3 participants