Repository navigation
Checkpoint reading positions before lifecycle shutdown - #219
Merged
Merged
Conversation
Owner
Author
|
@codex help me resolve the conflicts |
|
To use Codex here, create an environment for this repo. |
Owner
Author
|
@codex help me resolve the conflicts |
Summary
Testing
|
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.
Summary
Reading positions previously depended on leaving the editor or delivering a lifecycle callback, then waiting for an asynchronous full-document SHA-256 digest. A task removal or process shutdown could interrupt that last operation. The editor now saves foreground checkpoints after activity settles and during continuous activity, so a completed position exists before shutdown begins.
Behavior
Design and responsibility boundaries
The resume session controller owns the two bounded timers, one completed-capture cache, and one reference to pending fingerprint work. Scroll handlers only mark activity and schedule work; they do not read DOM geometry, serialize Markdown, or hash the document on every event. A checkpoint flushes pending editor operations, reads current Markdown, and then captures the current structural block/ratio anchor in the same JavaScript turn.
Fingerprint reuse requires exact equality with the cached or pending Markdown, including same-length edits. It reuses only identity metadata: the anchor, display text, and timestamp are captured anew. Cached synchronous writes and asynchronous hash completions share the existing per-document sequence tokens, so even an undo to cached content supersedes an older in-flight edited-content digest. Sharing the pending digest avoids repeatedly invalidating hashes that take longer than the checkpoint interval. Failed digests release the pending reference so a later capture can retry. Both references are session-local and reset with the editor; a late outgoing write cannot populate the next session's cache or clear its pending hash.
Document replacement and teardown cancel both timers. Explicit persistence also clears timers scheduled reentrantly by flushing pending editor operations. No new storage schema, dependency, setting, native service, or document-content save path is introduced. Resume-card presentation and exact-content validation remain unchanged.
Scope and integration
This PR targets
main, which includes the source-mode safety fix from merged #218. Its diff and sole fix target are #216. The main-branch integration preserves the reviewed checkpoint implementation and regression coverage.The timing bounds govern checkpoint initiation, not guaranteed disk durability or hash-completion deadlines. Abrupt termination can still lose activity newer than the last completed checkpoint, and changed content must complete a new digest. This does not change document autosave or promise recovery of unsaved Markdown.
Verification
pnpm build(includes TypeScript typecheck), ESLint on all 259 tracked JavaScript/TypeScript/Vue files, changed-file ESLint, andgit diff --checkpassed.cap sync androidand AndroidassembleDebugpassed.scrollTop=3000; Android Home/resume in source mode preserved the WYSIWYG block; foregroundam force-stopconfirmed process termination, then cold restart restoredscrollTop=5000from the completed checkpoint. The swipe left a cached process alive, so process termination was tested separately rather than inferred from task removal.The Android checks used a fresh isolated AVD. They do not establish behavior on every OEM or guarantee a final write during abrupt termination; recovery is from the last completed checkpoint. The unfiltered workstation
pnpm lintsees pre-existing untracked archive files, so tracked-file lint was used without changing the lint rules.Closes #216