Roll back an app's changes in a Kovlet Data Space
Undo what one buggy app wrote to a Data Space, and keep every other app's changes. You can also restore the whole space to an earlier moment, or bring back single rows and files from the Trash.
On this page
At a glance
- Kovlet records which user, machine and app made every change. An owner can undo one app's changes in the console, under Safety.
- Restore to a point in time returns the whole Data Space to a moment in the last 24 hours.
- A rollback is a new change, so you can undo it too.
- Schema changes are never rolled back. A value someone else changed after the app is kept.
- How far back you can go depends on the plan: 7 days on Free, 30 on Pro, 90 on Org (
retention_days).
Prerequisites
- The owner role on the Data Space.
- The Kovlet console:
https://kovlet.com, orhttp://localhost:5173with thekovletdDocker image from Run Kovlet locally. Locally, sign in asdev@example.com, the user--dev-auto-approveacts as. - To follow along with the sample apps:
- a local
kovletd --dev --dev-auto-approve - Node.js 22 or newer
npm i @kovlet/client tsxin an empty folder with"type": "module"in itspackage.json
- a local
Step 1: Make a mess to clean upOptional
This script stands in for a real bug. A "Budget" app writes two good rows. Then an "Importer" app joins the same Data Space and makes a mess. It sets every amount to 0, deletes a row and adds a junk row.
import { createKovletClient, t } from "@kovlet/client";
const local = { url: "http://127.0.0.1:8080", consoleUrl: "http://localhost:5173" }; // kovletd --dev
const tables = { expenses: { title: t.string(), amount: t.number() } };
// "Budget" creates its space and writes two good rows.
const budget = createKovletClient({ ...local, appName: "Budget", spaces: { main: { tables } } });
await budget.connect();
const rows = budget.space("main").table("expenses");
await rows.insert({ title: "Rent", amount: 1200 });
const groceries = await rows.insert({ title: "Groceries", amount: 85 });
await budget.whenSynced();
const spaceId = budget.space("main").spaceId;
// "Importer" joins the same space and makes a mess.
const importer = createKovletClient({ ...local, appName: "Importer", spaces: { main: { spaceId, tables } } });
await importer.connect();
await importer.whenSynced();
const bad = importer.space("main").table("expenses");
for (const row of bad.all()) await bad.update(row.id, { amount: 0 });
await bad.delete(groceries.id);
await bad.insert({ title: "???", amount: -1 });
await importer.whenSynced();
importer.disconnect();
await new Promise((r) => setTimeout(r, 500)); // let Budget receive the broadcast
console.log("space:", spaceId);
console.log("Budget sees:", rows.all().map((r) => `${r.title} ${r.amount}`));
budget.disconnect();npx tsx buggy-import.tsYou should see
- Two sign-in lines, then the Budget app's broken rows. The IDs and codes differ.
[kovlet] To connect Budget, open http://localhost:5173/activate?user_code=2WRU-RT9F and confirm code 2WRU-RT9F
[kovlet] To connect Importer, open http://localhost:5173/activate?user_code=MU3Y-WMZ3 and confirm code MU3Y-WMZ3
space: 01a23732-946f-743b-9509-a576c3783f7e
Budget sees: [ 'Rent 0', '??? -1' ]The Budget app received the Importer's changes live, like every other app on the Data Space would.
Step 2: Find what the app changed
Open Safety for the Data Space in the console:
https://kovlet.com/safety/<space id>, orhttp://localhost:5173/safety/<space id>locally.
You can also pick Safety in the console's navigation and choose the space.
The Activity list shows every change, newest first, with who made it. Filter it by person, machine, app (All apps → Importer) or table. That shows exactly what one app did.
Any app or script with viewer access can read the same feed over the API. It takes the same filters: user, machine, app, table, kind, since, until.
curl -s "$KOVLET_URL/v1/spaces/$KOVLET_SPACE_ID/activity?table=expenses&limit=20" -H "Authorization: Bearer $KOVLET_TOKEN"Each entry carries:
seq, the change's number in the spaceat, when it happenedby, who made it (user_id,machine_id,app_id)- the op
- the row's
beforeandafter
Tip With a local server, kovletd dev seed --env --space Budget sets KOVLET_URL, KOVLET_TOKEN and KOVLET_SPACE_ID. See Run Kovlet locally.
Step 3: Undo the app's changes
In Safety, in Undo an app's changes:
- Pick the App (Importer) and the Window: Last 15 min, Last hour or Last 24 h. The console picks the app that changed the space last.
- Read the preview. For the sample it says 4 changes found:
- 2 field values set back to earlier values
- 1 deleted row restored from Trash
- 1 row this app created go to Trash
- Other apps' changes are kept
- Click Undo Importer's changes, then Undo changes in the dialog.
You should see
- The confirmation "Undid 4 changes from Importer", with an Undo button.
- The Budget app sees
Rent 1200andGroceries 85again. Every app on the Data Space receives the restored values live. - The
???row is in the Trash.
What an undo does:
- It reverts the app's row and file changes in the window. Field values go back to what they were before the app changed them. Rows and files the app deleted come back. Rows and files the app created go to the Trash. Rows are never erased.
- It keeps every change by anyone else. That includes a value another app or person changed after this app. The preview counts those as later edits kept.
- It never touches the schema. A column the app added stays.
- It is a new change, attributed to you. The activity history keeps both the app's changes and the undo.
Note If the Data Space changes between the preview and your click, nothing is applied. The console shows the new preview: "The data changed since this preview. Check the new numbers and confirm again."
Note How far back you can roll back depends on the plan: 7 days on the free plan, 30 on Pro, 90 on Org (retention_days). Going further back fails with retention_window.
Step 4: Undo the undo
A rollback is reversible like any other change.
- Right away: click Undo on the confirmation. It hides after a few seconds.
- Later: do a point-in-time restore to the moment just before the undo (next step).
Step 5: Restore the whole Data Space to a point in time
When several apps or people made a mess, return everything to an earlier moment. In Safety, in Restore to a point in time:
- Drag the slider to the moment to return to. It goes from 24 h ago to Now in 15-minute steps. The label shows the time and the last change kept (
seq). - Read the preview: how many rows, fields and files change.
- Click Restore <space name>, then confirm.
Every change after that moment is reverted, by everyone. The restore is one new change, so you can undo it. Schema changes are kept.
Step 6: Restore one row or file from the Trash
Deleting a row or a file moves it to the Trash. Apps stop seeing it, but nothing is erased.
In Safety → Trash, click Restore next to the item. From code, an app with editor access can do the same:
import type { Space } from "@kovlet/client";
export function restoreFromTrash(space: Space, rowId: string, fileId: string) {
space.table("expenses").restore(rowId);
space.files.restore(fileId);
}Over REST, use POST /v1/spaces/{space}/tables/{table}/records/{id}/restore and POST /v1/spaces/{space}/files/{id}/restore.
A file goes back to its old path. If another file holds that path now, the restore fails with 409 path_conflict.
Roll back over the API
The console uses two routes: POST /v1/spaces/{space}/rollback/preview, then POST /v1/spaces/{space}/rollback. Both take the same body. Both need the owner role from a console session. An app or agent token gets 403 scope_required.
The body's kind says what to roll back:
kind | Fields |
|---|---|
undo_app | app_id, and minutes or since (RFC 3339), not both. Narrow it with table (rows of one table) or path_prefix (files under a folder), not both. |
point_in_time | to_seq or to_time (RFC 3339), not both. No narrowing. |
- Preview:
POST /v1/spaces/{space}/rollback/previewwith{"kind": "undo_app", "app_id": "<app id>", "minutes": 15}. Nothing changes. The answer is the plan. Here it is for the sample run, withsampleshortened to one entry:JSON{"kind": "undo_app", "head_seq": 7, "rows": 3, "fields": 2, "files": 0, "ops_reverted": 4, "schema_ops_skipped": 0, "conflicts": [], "sample": [{"kind": "record", "table": "expenses", "id": "01a23732-a920-7f84-bd10-0cb19de59d37", "fields": {"amount": {"from": 0, "to": 1200}}, "reverts": [4]}]}samplelists up to 20 changes. Setsample(0–100) for more or fewer.conflictslists what the rollback leaves alone, each with areason(see the table below). - Apply:
POST /v1/spaces/{space}/rollbackwith the same body plus"expected_head_seq": <head_seq from the preview>. The answer has the plan, the ops written,rollback_idandundo_to_seq.rollback_idis the mutation ID that every op of the rollback shares.JSON{"rollback_id": "01a23732-e64a-76d3-8569-9afd51eb5c35", "head_seq": 11, "undo_to_seq": 7, "plan": {…}, "ops": […]} - Undo it (if you need to): roll back with
{"kind": "point_in_time", "to_seq": <undo_to_seq>}.
Conflict reason | What the rollback keeps |
|---|---|
overwritten_later | A value someone else changed after the app (seq names the later change). |
table_missing, column_missing | A value whose table or column no longer exists. |
required_column | The current value of a required column, instead of removing it. |
type_mismatch | The current value, when the old one doesn't fit the column's type now. |
path_taken | A file's current path, when another file holds the old one. |
unique_taken | The current value, when another row now holds the old one in a unique column. |
Troubleshooting
| What you see | Why | What to do |
|---|---|---|
| Only owners can undo changes. in Safety | You aren't an owner of this Data Space. | Ask an owner to roll back, or to make you one. |
| Nothing to undo | The app made no row or file changes in the window. | Pick a longer window, or check Activity for the right app. |
400 retention_window | The rollback reaches further back than the plan keeps history. retention_days says how far it may go. | Roll back less far, or request a higher plan (upgrade_url). |
409 stale_preview | The Data Space changed after the preview. | Preview again and apply with the new head_seq. |
400 invalid_rollback | The body mixes fields that don't go together, for example minutes and since. | Fix the fields the message names. |
403 scope_required | An app or agent token called a rollback route. | Roll back as an owner in the console. |
| The app writes the bad data again | The bug is still running. | Stop or fix the app before you roll back. |
KovletAuthError: the user denied the request right after the code appears, on kovletd --dev --dev-auto-approve | Every run of a Node script without a persistent storage signs in as a new personal device, and the free plan allows 10. The kovletd log says quota exceeded: devices limit is 10. | Start from an empty server (Run Kovlet locally). |
Every error code is in the errors and limits reference.
Next
- Share live data between two apps: connect a second app to a Data Space.
- Evolve a schema and approve proposals: the schema proposals in the same Safety view.
- Upload and sync files: files in the Trash and their versions.
Ready to try it? Start free. No credit card, no API keys.
For coding agents: this page is also Markdown. Add .md to the URL or send Accept: text/markdown. The full reference is at /llms-full.txt.