On this page

Sessions and undo

Every change an agent makes is recorded per session, so you can revert one session without touching anyone else's writes.

#Sessions

An agent's writes belong to a session: the MCP session, the X-Stitch-Session header you send with /agent/sql, or one automatic session per hour. Direct connections get one session per hour.

#What is recorded

  • Rows: inserted, updated and deleted rows with their old and new values (tables need a primary key to be matched back).
  • Schema: tables, indexes, views, functions, policies, constraints and columns the agent created or changed, with the SQL that reverses them.
  • Dropped tables go to a trash schema instead of being deleted, and dropped columns keep their values, so undo can bring them back.

#Undo

Studio → AI agents → Sessions & undo → open a session → Undo session… shows a dry run first: how many changes can be reversed and which conflict. A row someone else changed after the agent is a conflict and is skipped.

Terminal
POST /platform/v1/projects/<ref>/agent-sessions/<session>/revert   {"dry_run": true}
POST /platform/v1/projects/<ref>/agent-sessions/<session>/revert   {"dry_run": false}
# the agent itself, for its own sessions:
POST /platform/v1/agent/sessions/<session>/revert                    {"dry_run": false}
LimitFreeProScaleEnterprise
Agent undo window24 hours168 hours336 hours720 hours
Agent undo: rows kept per session10,000 rows100,000 rows1,000,000 rows10,000 rows

Recorded changes count towards your database size and are deleted after the undo window. Recording is on only while the project has agent keys that can write.