Skip to main content

Overview

A state snapshot is a complete copy of a Genesis instance: its metadata database, its bot storage (uploads, threads, wiki, context graph, scheduler, apps, datasets) and its git repositories. It is written to an S3 or Google Cloud Storage (GCS) bucket in the layout of the Genesis Helm chart’s volume, so it can be restored onto any Kubernetes install of the chart. The same mechanism serves three purposes: Taking a snapshot pauses the instance: the server stops, the snapshot is copied while nothing writes to the state, and the server starts again on its own. Plan for the instance to be unavailable for the whole copy plus a few minutes of boot; an 8 GB instance of about 100,000 files took 30 minutes the first time. The snapshot_ctrl script takes, watches and restores snapshots with one command each; the API calls it makes are documented below for automation that cannot run it.

What a snapshot contains

Each snapshot is a folder of ordinary objects under the location you choose:
The manifest lists every file of the three trees with its size and SHA-256, every directory, the file modes, the source’s version, a fingerprint of the source’s master encryption key, and a signature made with that key. A snapshot without a manifest never finished and is ignored. Use one location per instance and keep reusing it. Every snapshot is a new, complete folder next to the earlier ones; no bucket or location is created per snapshot, and a restore from the location picks the newest complete folder:
Files of 1 MiB or more that are unchanged since the previous complete snapshot in the same location are copied inside the bucket instead of uploaded again, and so are files an aborted attempt had already uploaded there. Files under 1 MiB are always uploaded, because that is faster than copying them, so how much a repeat snapshot saves depends on how much of the state sits in large files. On a lab copy of a real instance (70,568 files, 7.8 GB), the first snapshot copied for 19 minutes and a repeat one for 7; measure your own before sizing a maintenance window. Do not delete the earlier folders before a snapshot; you lose the reuse and the resume of an aborted attempt. Each folder is self-contained, so you can delete old ones once a newer snapshot has finished. Changing kms_key_id between snapshots to the same location is safe. Each snapshot’s objects are encrypted with the key named in its own request. Copying an unchanged file from the previous folder needs kms:Decrypt on that folder’s key; without it, the copy is refused, the file is uploaded again under the new key instead, and the snapshot still succeeds. The exporter’s log then shows one AccessDenied ... kms:Decrypt error per such file, followed by a successful retry. Grant decrypt on the old key to keep the reuse. A snapshot holds every credential Genesis has stored, still encrypted with the instance’s master key. On S3, objects are always written with KMS encryption; on GCS they take the bucket’s default encryption, so give the bucket a customer-managed key if you need one. Treat the bucket like the instance itself.

Before you start

  • A bucket. Private. On S3, with KMS encryption; to restore in a different AWS account, use a customer-managed KMS key (kms_key_id) and grant the target account use of it, because the AWS-managed aws/s3 key cannot be shared across accounts. On GCS, with uniform bucket-level access (the default for new buckets) and public access prevention; kms_key_id does not apply.
  • Credentials for the source, GCS. The exporter lists, reads, writes and deletes objects (it finds the previous snapshot, copies unchanged files from it, and removes a failed or aborted attempt), so grant roles/storage.objectAdmin on the bucket; roles/storage.objectCreator alone makes snapshots fail. On GKE, use the pod’s Workload Identity: annotate the chart’s service account with iam.gke.io/gcp-service-account for a Google service account holding that role (or bind the Kubernetes service account directly). On Snowflake SPCS, create a GCP connection in Genesis with that service account’s key, and name it in the request as gcp_connection. A restore only reads, so roles/storage.objectViewer is enough for the restoring cluster.
  • Credentials for the source, S3. These are AWS credentials, and they need s3:ListBucket on the bucket, s3:GetObject, s3:PutObject, s3:DeleteObject and s3:AbortMultipartUpload on the location, and, with a customer-managed key, kms:GenerateDataKey and kms:Decrypt on it. Without s3:DeleteObject the request fails before anything stops (“accepted a write but refused its deletion”). On EKS, use the pod’s identity (IRSA). On other clusters (GKE, AKS), GKE Workload Identity and Azure identities grant nothing on AWS: either trust the cluster’s OIDC issuer in AWS IAM and give the pod AWS_ROLE_ARN and a projected token at AWS_WEB_IDENTITY_TOKEN_FILE, or name a Genesis AWS connection in the request. On Snowflake SPCS there is no pod identity: create an AWS connection in Genesis with an access key that can write to the prefix, and name it in the request.
  • Network egress from SPCS. The Native App’s external access integration must allow the bucket’s endpoints: for S3, <bucket>.s3.<region>.amazonaws.com; for GCS, storage.googleapis.com and oauth2.googleapis.com.
  • The master key. The target must use the same master key as the source, or it cannot decrypt any stored credential. Note the source’s key before migrating; on SPCS it is the Snowflake secret behind CORE.GET_ENCRYPTION_KEY().

The snapshot_ctrl script

snapshot_ctrl.py ships in the Genesis Helm chart, next to values.yaml (helm pull <chart> --untar puts it in genesis/). It needs python3 (3.8 or later) and kubectl pointed at the cluster, nothing else. It talks to Genesis from inside its pod, so it works while the pod is 0/1 during a snapshot and needs no ingress URL, and it reads the API token from GENESIS_API_TOKEN or a file (--token-file), never from the command line.
verify checks the last restore that reached the volume. A restore that stops before it replaces anything leaves the restore before it in place, and verify still reports that one; --expect <snapshot id> fails unless the instance was restored from that snapshot. Given an API token (GENESIS_API_TOKEN or --token-file), restore runs this check itself when it ends; without one it stops once Genesis is up, and you run verify --expect yourself. restore also stops when something scales Genesis back up while it waits for Genesis to stop, such as a service that wakes idle installs on a request, an autoscaler, or a GitOps tool restoring the replica count: pause it, and keep users off the install, before retrying. snapshot refuses to start when the liveness probe would kill the snapshot (see Health probes during a snapshot), then asks for the instance’s name, because it stops Genesis. While the snapshot runs it prints a progress line at least every 30 seconds. The remaining-time estimate uses the longer of the average file-rate estimate and the bytes left at the current transfer rate, so it accounts for both many small files and a few large ones. It is omitted until there is enough progress or a transfer rate to estimate; restore progress labels transferred bytes as received rather than sent:
After either a successful or failed snapshot, the command waits for Genesis to become ready before returning, so a pipeline can retry against a running instance. It exits 0 when the snapshot succeeded and Genesis is back, 1 when it failed (with the reason) and Genesis is back, and 2 when --timeout (minutes, default 180) ran out. A succeeded snapshot ends with a SNAPSHOT_ID=<id> line. For a pipeline, see Snapshot before every upgrade. list and restore are described in Restore over an existing install. list and the restore preview run inside the Genesis pod, under its master key and cloud credentials, so they need no token but do need the pod running. Pass --release <name> when the namespace holds more than one Genesis install, and --context to pick a kubectl context.

Snapshot before every upgrade

Make a snapshot the first step of your upgrade pipeline, and upgrade only when it succeeded. If the new release misbehaves, restore that snapshot (see Roll back an upgrade).
In a pipeline the step asks nothing: with --yes and --confirm it never prompts, and without them it fails at once instead of waiting for an answer. When the pod is not ready (a restart, a node move), it waits up to --ready-timeout minutes (default 10) and fails without starting a snapshot if the pod does not become ready. It returns only once the manifest is written and Genesis is back, so helm upgrade starts on a ready pod. Its exit codes: 0 the snapshot succeeded, 1 it failed or was refused (the reason is printed), 2 a timeout. Any non-zero code stops the pipeline before the upgrade. Expect Genesis to be unavailable while the snapshot runs. On the lab, an instance with 70,568 files and 7.8 GB took 19 minutes for its first snapshot and 7 minutes for the next one under the same prefix, which copies unchanged large files server-side. Use the same destination every time: one prefix per instance keeps those copies cheap and lets list show every snapshot. The token needs the permissions in Take a snapshot, and the writer the S3 permissions in Before you start. Snapshots are not deleted automatically; remove old ones with your bucket’s lifecycle rules, never the newest.

Take a snapshot

This is the API snapshot_ctrl.py snapshot calls. It requires an administrator: config panel access, viewing agents, users and connections, and managing secrets, all connections and the scheduler, because the snapshot carries every stored secret and stops the server. Listing jobs needs only the viewing permissions. The confirm field must equal the instance’s name, because the call pauses the instance. The destination must be an s3:// or gs:// prefix; local paths are accepted only by the export-state command inside the container. Name a Genesis connection for the destination’s cloud: aws_connection for s3://, gcp_connection for gs://; a connection for the other cloud is refused.
Omit the connection on Kubernetes to use the pod’s identity. The request first checks everything it can while the instance still runs (a write probe at the destination, the master key, and free space for the database copy); a failure is returned and nothing stops. A Snowflake-mode instance has no local database to measure, so its space check is skipped: if the scratch volume cannot hold the converted database, the export fails after the instance has stopped, and the instance then starts again. On success it returns 202 with a job id, then the instance stops. On a Helm chart install the container then ends and Kubernetes restarts it, so the startup probe, not the liveness probe, covers Genesis’s boot; the pod’s restart count goes up by one per snapshot. The snapshot survives only if the pod’s liveness probe reads /api/health/live: see Health probes during a snapshot. While the snapshot runs, the instance answers only its health checks and a progress endpoint, without authentication. Once the readiness probe fails, the pod is 0/1 and an ingress stops routing to it (nginx answers 503 Service Temporarily Unavailable), so ask the pod itself:
When it is back, list jobs and their outcome:
Each job reports its status (succeeded, failed or aborted), the snapshot id, its size, and any error.
If the server has not finished shutting down two minutes after the request, it is stopped anyway and the snapshot proceeds. A container restart during a snapshot aborts that job (the usual cause is a liveness probe on /api/health; see below). When Kubernetes stopped the container, the job’s error says so, with the time the stop arrived and how far the copy had got; otherwise it says when and where the copy stopped and what the container’s memory counters showed. The instance comes back without the snapshot. The next request to the same location copies inside the bucket the large files the aborted one had already uploaded. Once a snapshot’s manifest is written, it deletes the folders of aborted snapshots that started more than a day earlier; a younger one could still be in progress from another export to the same location.

Health probes during a snapshot

While a snapshot runs, the Genesis server is stopped and the snapshot exporter answers on its port instead. Kubernetes probes see this: Between the server stopping and the exporter starting, nothing listens on the port, for up to two minutes while the server shuts down. Configure the probes so that only liveness decides whether the container is restarted, and liveness passes throughout:
Do not point the liveness probe at /api/health, at /api/health/startup, or at any check that requires Genesis to be ready. /api/health answers 503 for the whole snapshot, so Kubernetes restarts the container after failureThreshold × periodSeconds (with 10 × 30s, five minutes in), and the snapshot is aborted however much memory or time it has. The same probe also restarts a pod whose first boot outlasts it, which is what the startup probe is for. The Genesis Helm chart has used /api/health/live for liveness since its startup probe was added; check this if you render your own manifests or override livenessProbe.
helm upgrade --reuse-values keeps the probe settings of the release it upgrades, including an older chart’s default of failureThreshold: 3, so upgrading the chart alone does not raise the budget. The chart prints a warning on install and upgrade when the liveness probe would abort a snapshot, and snapshot_ctrl.py check reports the same. Check the probes on the running pod before taking a snapshot:
If a snapshot was aborted, the pod’s events show what restarted it. Kubernetes keeps events for about an hour, so read them soon after:
Liveness probe failed: HTTP probe failed with statuscode: 503 followed by Container genesis failed liveness probe, will be restarted means a liveness probe on /api/health. lastState.terminated.reason: OOMKilled means the memory limit is too low. A load balancer health check on /api/health (for example an ALB healthcheck-path) marks the target unhealthy during the snapshot. That only stops traffic to an instance that is not serving anyway.

Restore onto Kubernetes

What a restore needs

  • Read access to the snapshot’s location: s3:ListBucket on the bucket, s3:GetObject on the location, and kms:Decrypt on the KMS key the snapshot’s objects were encrypted with (the snapshot’s kms_key_id, or the bucket’s default key). A restore only reads; it never writes to the bucket.
  • The source instance’s master key (GENESIS_MASTER_KEY), which is not the KMS key. The snapshot is signed with it and every stored credential is encrypted with it; under another key the restore refuses.
  • An image newer than v1.19.93, and not older than the release that took the snapshot.
No setting names the KMS key: S3 records the key on every object and decrypts with it, as long as the reading identity may use that key. The target install’s own bucket and its key play no part in a restore. To restore in a different AWS account, either:
  • Read the snapshot where it is. Both accounts have to allow it. In the source account, grant the target account’s role read access in the bucket’s policy and kms:Decrypt in the key’s policy. In the target account, give that role an IAM policy allowing s3:ListBucket and s3:GetObject on the source location and kms:Decrypt on the source key’s ARN. This needs a customer-managed key: the AWS-managed aws/s3 key cannot be shared across accounts.
  • Copy one snapshot folder first, then restore from the copy. Copied objects take the destination bucket’s encryption, so the target account’s own key applies; the copying identity needs read and decrypt on the source and write on the destination. Copy a whole folder and check that the counts match before restoring:
    S3 replication is a poor fit for a one-off move: it copies existing objects only through Batch Replication, and objects arrive in no particular order, so a restore that starts early finds manifest.json before all the files it lists and refuses with missing files.

Restore a new install

Set restore.from on a new install of the Genesis Helm chart. An init container fills the empty volume from the snapshot before Genesis first starts:
The init container restores only into an empty volume, on the install’s very first start. If Genesis has already started on the volume, even once, the restore is skipped without an error and the pod starts with the state it has; only Verify the restore shows it (not_restored). Keep users off a new install until it has been restored and verified, and restore over a volume that already holds state with Restore over an existing install.
The image must be a release after v1.19.93; earlier releases do not ship the restore. The chart refuses to render restore.from with a release tag (vX.Y.Z) at or below v1.19.93. A tag it cannot order, such as a build id, is not checked, and an image without the restore then fails in the init container.
Without a client name and an instance name the chart refuses the install before the restore starts (“identity.clientName and identity.instanceName are required for a new install”). Set them with identity.clientName and identity.instanceName, or with GENESIS__SERVER__CLIENT_NAME and GENESIS__SERVER__INSTANCE_NAME in config.extraEnv. They name the install on what it reports to the vendor. When the new install replaces the source, give it the source’s names; when the source keeps running, as in a test restore, give the new install its own instanceName so the two can be told apart. On GKE with a gs:// snapshot, the restore reads the bucket through the pod’s Workload Identity: annotate the service account with iam.gke.io/gcp-service-account: <gsa>@<project>.iam.gserviceaccount.com for a Google service account that can read it, and let that account be impersonated by serviceAccount:<project>.svc.id.goog[<namespace>/<ksa>]. For an s3:// snapshot the restore reads the bucket with the pod’s AWS credentials, which the chart’s init container takes from the standard AWS chain. The service account annotation above is the EKS way. On GKE or AKS the cluster identity grants nothing on AWS: trust the cluster’s OIDC issuer in AWS IAM, mount a projected service-account token with that audience through extraVolumes and extraVolumeMounts, and set AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE in config.extraEnv. The init container receives the same environment and extra mounts as Genesis. The signed manifest identifies the master key used to take the snapshot. Genesis accepts a signature made with the current key or its bound previous key; the published development key is not trusted as a previous key. If requires_previous_key_fingerprint is present, secrets in the snapshot may still be sealed with the source’s previous key, so that matching key must also be bound here as the current or previous key. Restoring a snapshot signed under the previous key restarts secret re-sealing; keep any previous key needed by the restored secrets bound until those secrets have been re-sealed. The restore refuses, and Genesis does not start, if:
  • the manifest signature does not verify under the current or bound previous key, or a key named by requires_previous_key_fingerprint is not bound here;
  • the snapshot comes from a newer Genesis release than the image (a development build, which has no release number, accepts a snapshot from any release);
  • the manifest lists a path outside the volume’s trees, or the same path twice;
  • any file is missing, unexpected or does not match its checksum, or the database fails its integrity check.
Files are downloaded into staging directories on the volume and verified there before being moved into place, so a failed restore leaves the volume as it was and removes its staging directories. Only files the signed manifest lists are downloaded. If the pod restarts while the verified trees are being moved into place, the next start finishes the move rather than restoring again. A volume that already holds state (any non-empty tree, or a file or symlink where a tree belongs) is never touched by the init container, so pod restarts and upgrades do not restore again. When durable SQLite is enabled, restoring into an empty volume leaves the existing Lakebase copies intact; they are restored over the snapshot’s database files at the next startup. A forced restore, such as the one below, replaces the Lakebase copies with the snapshot’s durable databases. See Durable SQLite stores on Databricks.

Restore over an existing install

This replaces everything on the install’s volume with the snapshot, for a rollback, or for an install that started before it was restored. Run it from a machine with kubectl access to the cluster:
Without --snapshot it takes the newest complete snapshot under the prefix, and then restores exactly the one the preview showed, even if a newer one finishes meanwhile. First, while Genesis keeps running, it previews the restore inside the Genesis pod:
The preview runs every check the restore runs before it downloads anything: the snapshot’s format and release, that it was taken under this install’s master key, that its manifest’s signature holds, and that every file it lists is at the destination with the listed size. It does not hash the files; the restore does. When a check fails it prints PROBLEM: lines and the restore stops there, with Genesis untouched. On a release without the preview, or when the Genesis pod is not running (a broken install you are rolling back), the restore goes ahead without one; --no-preview skips it on purpose. --dry-run prints the preview and stops: it exits 0 when a restore would go ahead, 1 when it would be refused, and 3 when the running release has no preview, so nothing was checked. The preview is a Python process beside Genesis in its container, using about 600 MB of memory for a few seconds to a minute; on a container with a tight memory limit, run it when the instance is quiet. After the preview it asks for the release name, then:
  1. Scales the Genesis StatefulSet to 0 and waits for the pod to go, so nothing writes to the volume.
  2. Starts a one-off pod, <statefulset>-restore, from the StatefulSet’s own image, service account, environment (master key, CA bundles, cloud credentials) and mounts, with the whole volume at /genesis-data, and streams its log. The pod runs the restore with --force.
  3. Deletes that pod and scales the StatefulSet back, whether the restore succeeded or not. A failed restore leaves the volume as it was, so Genesis comes back with its old state.
  4. Waits for Genesis to be ready and, with a token, runs verify.
The restore is a decision for a person, so the script asks before it stops anything; --yes skips the question, and without a terminal to ask on, it refuses instead of waiting. The pod runs the same command as the chart’s init container, which you can also run yourself in any pod that mounts the volume while Genesis is stopped:
The restore also rewrites absolute file paths the source stored (uploaded files, SQLite connections, app registries) so they point where the chart mounts the volume (--runtime-root /app; without it, at the restored directories themselves). Only whole paths are rewritten: a directory that merely shares a prefix is left alone. The paths it rewrote, and any it could not, are recorded in db/.snapshot-restored-from.json, the one file the restore adds beside the snapshot’s; later snapshots leave it out. Bots, the Slack app configuration and tunnel tokens belong to a runner, and a server serves only its own. The restore moves every runner-keyed row to the runner of the server that will serve the volume (RUNNER_ID, which the chart’s init container shares with Genesis; jl-local-runner when unset). Without this, a snapshot from Snowflake SPCS, whose bots belong to snowflake-1, would restore bots the Kubernetes server never starts. The rows it moved are recorded in db/.snapshot-restored-from.json under runner.

Roll back an upgrade

To return to the state before an upgrade, restore the snapshot your pipeline took before it, then go back to the release that wrote it:
list prints each snapshot’s id, the Genesis release that took it, its size and when it finished, newest first; the five newest are read in full, older ones show only their id. A snapshot marked incomplete never finished and cannot be restored. Go back to the earlier release before the restore: a restore refuses a snapshot from a release newer than the one running, and a newer release migrates an older snapshot forward when it starts.

Verify the restore

A healthy pod does not prove the restore worked: a pod that starts on an empty volume is healthy too. Every snapshot records how many agents, connections, users, secrets and messages its genesis.db held, and the time of the newest message. The restore keeps those counts in db/.snapshot-restored-from.json. Once Genesis is up, an administrator compares the running instance with them, with snapshot_ctrl.py verify or the API. verify exits 0 when the check passed (or the snapshot predates the counts), 1 when it failed, and 3 when the running release has no restore check, so nothing was compared; restore passes the same result on when it runs verify:
verdict is passed when the instance holds at least what the snapshot held and the key probe did not fail: one stored secret opens under the master key, or the instance stores no secrets (decrypt_probe: no_secrets). It is failed when something is missing, genesis.db itself is missing, or the key cannot open the secret, and problems then lists each shortfall, such as agents: 0 now, 7 in the snapshot. It is not_restored when the mounted volume carries no restore record; right after a restore, that means Genesis is not running on the restored volume. It is no_baseline when the volume was restored from a snapshot taken before Genesis recorded these counts: restored, but nothing to compare with. Counts that grew after the restore still pass. The probe reports only passed, failed or no_secrets, never the secret itself. The call needs the permissions for listing snapshot jobs. Called before taking a snapshot, it shows the counts that snapshot will record.

Retention relies on snapshots

Admin → Storage → Retention deletes chat threads and finished missions idle past an age, but only once the newest complete snapshot at retention.snapshot_location holds every one of their files (matched by SHA-256 against its signed manifest) and their rows. Anything changed since that snapshot waits for the next one. With no location set, nothing is deleted. Each deleted item is listed under “Deleted, recoverable” (the Retention tab, and the Missions page’s status filter), and Restore puts back that one item from the snapshot named there: its files, its rows, its owner and who could see it. An item can be restored only while that snapshot is kept. Snapshots are removed by your bucket’s lifecycle rules, and later snapshots do not hold deleted items, so keep snapshots at least as long as your audit period. The Retention tab shows the oldest snapshot still held; a restore from a removed snapshot is refused and changes nothing. Storage Management describes every storage control and its limits.

Migrating from Snowflake SPCS

  1. Upgrade the Native App to a release with state snapshot support, and allow the bucket’s endpoints in its external access integration.
  2. In Genesis on SPCS, create a connection for the snapshot bucket: a GCP connection whose service account holds roles/storage.objectAdmin on a GCS bucket (the path to GKE), or an AWS connection that can list, read, write and delete under an S3 prefix.
  3. Record the SPCS master key and store it as a Kubernetes Secret in the target cluster.
  4. Take a snapshot with gcp_connection or aws_connection set. The exporter converts the Snowflake metadata tables into the Kubernetes SQLite database, reading every table as of the same instant through Time Travel. A table with no history at that instant (created after it, or kept without Time Travel retention) is read as it is at copy time instead. reports/tables.json, written beside the trees, lists every table, its row count, whether it was read at the shared instant (point_in_time), duplicate keys it collapsed (Snowflake does not enforce keys), and any column that exists on only one side. A row SQLite would reject for any other reason fails the snapshot rather than being dropped. The report is for the operator: it is not in the signed manifest, and a restore neither downloads nor checks it.
  5. Install the Helm chart with restore.from pointing at the snapshot and the SPCS master key configured.
  6. Configure authentication for the Kubernetes install (Auth0 or another OIDC provider). Snowflake sign-in does not carry over; users sign in again and roles are granted to their new identities.
  7. Replace connections that relied on the SPCS service’s own Snowflake session with regular Snowflake connections (key pair or OAuth).
Before retiring SPCS, download reports/tables.json and review it. A table with skipped_duplicates above zero kept one row per key: where those rows differed in Snowflake, the other versions are not in the new database, so compare them in Snowflake and re-enter any that matter. A table with point_in_time: false was read later than the rest; check it if it changes often. Once the Kubernetes install is verified, suspend the SPCS service so both instances do not run against the same external systems.