Skip to content

feat(delegates): restore-from-snapshot API and CLI for delegate secrets #4036

@sanity

Description

@sanity

Problem

PR #4034 added per-secret snapshot-on-write retention so prior values survive an accidental overwrite. The snapshots are encrypted, decryptable, and bounded — but there is no API or CLI to actually restore one. Today users must manually move files in {delegate_dir}/.snapshots/{secret_id}/ over the active path.

Proposal

A read API on SecretsStore:

pub fn list_snapshots(&self, delegate: &DelegateKey, key: &SecretsId)
    -> Result<Vec<SnapshotMetadata>, SecretStoreError>;

pub fn restore_snapshot(&mut self, delegate: &DelegateKey, key: &SecretsId,
                        timestamp_ms: u64) -> Result<(), SecretStoreError>;

And an fdev wrapper:

fdev delegate snapshots list <delegate_key> <secret_id>
fdev delegate snapshots restore <delegate_key> <secret_id> <timestamp_ms>

Restore semantics: copy the chosen snapshot back through the same hard-link + atomic rename path that store_secret uses, taking a fresh snapshot of the value being replaced first (so restore is itself recoverable).

Why a separate issue

The base PR scoped to "preserve prior values, don't lose data". User-facing recovery UX has its own design questions (timestamp display, partial restores, dry-run). Worth its own review cycle.

Related

[AI-assisted - Claude]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-contractsArea: Contract runtime, SDK, and executionA-developer-xpArea: developer experienceE-mediumExperience needed to fix/implement: Medium / intermediateP-mediumMedium priorityS-needs-designStatus: Needs architectural design or RFCT-featureType: New functionality request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions