siyuan-note/siyuan · error

encrypted snapshot document is missing valid notebook…

Error message

encrypted snapshot document is missing valid notebook context

What it means

When snapshot bytes are detected as ciphertext, the loader needs the notebook ID as the first path segment of the repo file path (<boxID>/<relative path>) to look up the notebook DEK. If the path has fewer than 2 segments, the first segment is not a node-ID-style notebook ID, or that notebook is not a registered encrypted box, decryption context is missing and this error is thrown.

Solutions

  1. Verify the snapshot file's repo path is <boxID>/<relative doc path> with a valid node-ID notebook as the first segment.
  2. Check that the notebook still exists and is flagged encrypted; if its encryption state changed, restore or re-encrypt consistently.
  3. Rebuild/re-sync the snapshot index from the source workspace so paths are recorded correctly.
  4. If the snapshot predates encryption support, load it via the legacy path or re-create it as a new snapshot.
Defensive patterns

Strategy: validation

Validate before calling

// Go: validate snapshot path has boxID/docPath with a valid encrypted box
parts := strings.SplitN(strings.TrimPrefix(file.Path, "/"), "/", 2)
if len(parts) < 2 || !ast.IsNodeIDPattern(parts[0]) || !model.IsEncryptedBox(parts[0]) {
    return errors.New("snapshot lacks valid encrypted notebook context")
}

Try / catch

catch (e) { if (e.message.includes("missing valid notebook context")) { resyncRepoIndex(); } else { throw e; } }

Prevention

When it happens

Trigger: loadDocVersion on an encrypted snapshot whose repo file path lacks the notebook-ID segment, has a malformed first segment, or references a notebook that is no longer (or never was) registered as encrypted (IsEncryptedBox false).

Common situations: Snapshot paths recorded by an older/foreign format; docs synced from a notebook whose encryption was toggled after snapshotting; corrupted repo index entries; manually imported snapshot data with wrong path layout.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/97f9b54598edafa8. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/history_diff.go:424

		return nil, err
	}
	file, err := repo.GetFile(fileID)
	if err != nil {
		return nil, err
	}
	if !strings.HasSuffix(strings.ToLower(file.Path), ".sy") {
		return nil, errors.New("snapshot version is not a document")
	}
	repoPath := strings.TrimPrefix(file.Path, "/")
	pathParts := strings.SplitN(repoPath, "/", 2)
	data, err := repo.OpenFile(file)
	if err != nil {
		return nil, err
	}
	ciphertext := util.IsCiphertext(data)
	if ciphertext {
		if len(pathParts) < 2 || !ast.IsNodeIDPattern(pathParts[0]) || !IsEncryptedBox(pathParts[0]) {
			return nil, errors.New("encrypted snapshot document is missing valid notebook context")
		}
		HoldBoxReadLock(pathParts[0])
		defer ReleaseBoxReadLock(pathParts[0])
		dek, unlockErr := GetDEKIfUnlocked(pathParts[0])
		if unlockErr != nil {
			return nil, errors.New(Conf.Language(314))
		}
		data, err = DecryptFile(pathParts[0], pathParts[1], dek, data)
		if err != nil {
			return nil, err
		}
	} else if len(pathParts) > 0 && IsEncryptedBox(pathParts[0]) {
		return nil, fmt.Errorf("encrypted notebook snapshot document is plaintext [%s]", pathParts[0])
	}
	rootID := strings.TrimSuffix(filepath.Base(file.Path), filepath.Ext(file.Path))
	tree, err := parseDocVersionTree(data, rootID)
	boxID := ""
	if 0 < len(pathParts) && ast.IsNodeIDPattern(pathParts[0]) {

View on GitHub (pinned to 9f775e8a12)