Catch up journals from Chronicle's change feed; versions only move forward - #125
Merged
Merged
Conversation
…rward On connect, read GET /sync/changes from a saved per-campaign cursor and refetch only the pages it lists, instead of walking every page. The cursor (with its own created-after floor) is saved only after the changes applied, so a failed catch-up replays. Without a feed (older Chronicle, a player's key) journals rescan as before. A journal's recorded Chronicle version never moves backwards: stale copies are ignored, identical permission pushes are skipped, and a real one reads the page back for the version it stamped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018uKa2E5HNdeubwBSD9Jn4n
keyxmakerx
marked this pull request as ready for review
October 3, 2026 05:41
This was referenced Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: none
Security implication: none. One new read (
GET /sync/changes, owner and co-DM keys only on the server; a player's key gets 403 and falls back to the old rescan) and one read-backGET /entities/:idafter a permissions push. No new writes.Consumer-verified: Chronicle
internal/plugins/syncapi/sync_changes_handler.goListChanges(response{changes:[{seq,type,resourceId,op}], next, hasMore, resetRequired}),sync_change_repository.goList(holds back rows younger than 2 s),sync_change_bus.go(entity events recorded as typeentity);entities/service.goSetEntityPermissions(bumpsupdated_at, answers{"status":"ok"}).Foundry compatibility: no new Foundry APIs; uses the settings, document and flag calls the module already uses (v12–v14). Not run in a live world.
Mockup: n/a. Nothing on screen changes.
What this changes
Before:
After:
Why
This is step 3 of the approved sync rebuild (keyxmakerx/Chronicle#907, module #114), journals first, on the change feed from keyxmakerx/Chronicle#927. Key Maker's hard requirements were no duplicate copies, idempotent changes, and the two-sided bench before anything is called ready. Refs #114.
Load-bearing lines:
scripts/_change-feed.mjs(pure):walkChangeFeedfollowshasMore, returnsresetRequired, and stops on no progress or after 200 pages (complete: false).collapseChangesgives one outcome per page.cursorForreads a per-campaign cursor{campaignId, seq, areas, createdAfter}.feedForAreagives an area the delta only if the cursor was saved while that area was syncing.scripts/sync-manager.mjs_performInitialSync/_readChangeFeed:scripts/journal-sync.mjs_catchUpFromFeed:deletedor a 404, with the same checks as before (_setAsideIfGone, now shared with the full walk).created_atis after the cursor'screatedAfter.createdAftermoves only with the cursor, so a failed catch-up still treats a new page as new on retry. The review caught that one._olderThanRecorded):_recordPushand the "kept your unsent edit" path never roll the version back._pushPermissions):pushedPermissionsflag).Honest deviations:
Test plan
node --test tools/test-*.mjs: 994 of 994 pass. New:test-change-feed.mjs(feed walk, collapse, cursor rules including the failed-catch-up replay and the cut-short walk, journal delta apply) andtest-journal-versions.mjs(stale copy ignored, version never rolls back, permissions read-back and skip).node tools/check-package-descriptor.mjs: OKCHRONICLE_DIR=../Chronicle bench/run.sh(Chronicle main plus #957): 12 of 12 scenarios, run 3 times. The new scenario "a reopen reads only what changed" checks five things:Sync benchincluded)Tenet self-check
.ai.md(change feed, versions),API-CONTRACT.md(GET /sync/changes, permissions save),CLAUDE.mdconvention🤖 Generated with Claude Code
https://claude.ai/code/session_018uKa2E5HNdeubwBSD9Jn4n
Generated by Claude Code