← Back to Craft
AgentCraft

Skill · Version 1.0.0

Autosave and recovery

Protects editing work through ordered saves, isolated drafts and recovery that respects newer server versions instead of silently overwriting them.

autosave-recovery

See how it helps

When is it useful?

Use it when people edit documents over unreliable connections or reopen the app after an interrupted save.

What does it help you do?

  • Separates editing, saving, saved and failed states.
  • Rejects stale responses and scopes drafts by user and document.
  • Compares local drafts with server versions before recovery.

Try asking this

Recover offline edits without overwriting a newer server document. Edit the same paragraph offline and on another device. Offer a comparison before restoring the draft, and never label an unconfirmed upload as saved.

Detailed documentation

Read the skill’s original instructions, examples and checks in their authored language.

Details…Show less

Autosave & Recovery

Use this skill when building saving, autosaving, offline draft caching, network interruption handling, and version conflict recovery for editors.

Explicit Save State Machine & Sequencing

  1. Never Equate Request Dispatch with "Saved":
    • Model persistence with explicit states: saved (clean), modified (dirty, awaiting debounce), saving (request in flight), error (save failed, retry pending), and conflict (server has a newer version).
    • Display these states honestly in the UI so users always know whether their latest edits are on the server.
  2. Monotonic Sequence Numbers & Out-of-Order Guards:
    • Tag every outgoing save with the local revision counter (clientSeq) and last known server version (baseVersion).
    • If the user edits while save $S_1$ is in flight, keep the state modified after $S_1$ resolves (only transitioning to saved when acknowledgedClientSeq === currentClientSeq), and trigger a follow-up save.
    • Ignore or abort stale responses ($S_1$ arriving after $S_2$) so an older response never overwrites newer local state.
  3. Never Rely Solely on Unload Events:
    • Page close (beforeunload / pagehide) requests can be dropped by the browser. Combine debounced server autosave with immediate local draft persistence and warn on navigation when unsaved changes exist.

Local Draft Isolation & Safe Recovery

  • Scope Local Drafts by User, Workspace, and Document:
    • Key local drafts in IndexedDB/storage by (workspaceId, userId, documentId) with baseVersion, updatedAt, and schema version.
    • Purge or isolate sensitive local drafts on logout, workspace revocation, or TTL expiration.
    • Handle storage quota errors (QuotaExceededError) gracefully without crashing the editor or falsely promising offline recovery.
  • Conflict-Safe Reload & Recovery:
    • On load, compare the server's version against any local un-synced draft's baseVersion:
      • If localDraft.baseVersion === server.version and localDraft has un-synced edits, offer to restore the draft.
      • If server.version > localDraft.baseVersion (or a save returns 409 Conflict), never silently overwrite the newer server document. Pause autosave and let the user inspect, merge, or copy their local draft changes safely.

Checklist

  • Does the UI distinguish modified, saving, saved, error, and conflict accurately?
  • Do monotonic sequence/version checks prevent stale in-flight save responses from overwriting newer edits?
  • Are local drafts scoped to (workspaceId, userId, documentId) and cleared on logout?
  • Does recovery check baseVersion against the server so newer server versions are never silently overwritten?

Included files 1

  • SKILL.md