Skip to content
GitHub Get Started
Reference

Persistence & Sleep

agentOS automatically persists the /home/user filesystem and session transcripts (with sequence numbers for replay) across sleep/wake, sleeping after a configurable grace period (15 minutes by default) and waking automatically when a client connects or a cron job triggers.

DataStoragePersists?
Files in /home/userPersistent filesystemYes
Session recordsSQLite (agent_os_sessions)Yes
Session event historySQLite (agent_os_session_events)Yes
Preview URL tokensSQLite (agent_os_preview_tokens)Yes
Cron job definitionsActor stateYes
Running processesVM kernelNo
Active shellsVM kernelNo
In-memory mountsVM memoryNo
VM kernel stateVM memoryNo

The actor stays awake as long as any of these are active:

  • Active sessions (created but not closed/destroyed)
  • Running processes (spawned but not exited)
  • Active shells (opened but not closed)
  • Pending hooks (server-side callbacks still executing)

When all activity stops, the sleep grace period begins.

After all activity stops, the actor waits 15 minutes before sleeping. This allows for brief pauses between interactions without restarting the VM.

Activity stops ──> 15 min grace period ──> Actor sleeps
(VM shutdown, processes killed)
New client connects ──> Actor wakes ──> VM boots ──> Filesystem restored
SettingDefaultDescription
Action timeout15 minutesMaximum time for any single action
Sleep grace period15 minutesTime before sleeping after all activity stops

These are set internally by the agentOS() factory and cannot be overridden per-call.

SleepDestroy
FilesystemPreservedDeleted
Session recordsPreservedDeleted
Event historyPreservedDeleted
Preview tokensPreservedDeleted
VM stateLostLost
ProcessesKilledKilled

Subscribe to vmBooted and vmShutdown events to track VM lifecycle.

lifecycle-client.ts
import { createClient } from "@rivet-dev/agentos/client";
import type { registry } from "./server";
const client = createClient<typeof registry>({ endpoint: "http://localhost:6420" });
const conn = client.vm.getOrCreate("my-agent").connect();
conn.on("vmBooted", () => {
console.log("VM is ready");
});
conn.on("vmShutdown", (payload) => {
console.log("VM shutdown reason:", payload.reason);
// reason: "sleep" | "destroy" | "error"
});

See Full Example

When the actor wakes up, the VM boots and the filesystem is restored from SQLite, session records and event history are immediately available, and processes and shells from the previous session are gone. Clients can reconnect, list prior work with listPersistedSessions (which works without a running VM), and replay a session’s persisted transcript with getSessionEvents.

resume-client.ts
import { createClient } from "@rivet-dev/agentos/client";
import type { registry } from "./server";
const client = createClient<typeof registry>({ endpoint: "http://localhost:6420" });
const vm = client.vm.getOrCreate("my-agent");
// List sessions persisted before sleep (works without a running VM)
const sessions = await vm.listPersistedSessions();
console.log("Previous sessions:", sessions.length);
// Replay the most recent session's transcript from durable storage
const last = sessions[0];
if (last) {
const events = await vm.getSessionEvents(last.sessionId);
for (const e of events) {
console.log(e.seq, e.event.method);
}
}

See Full Example (uses the same server.ts as above)

Stores the virtual filesystem.

ColumnTypeDescription
pathTEXT PRIMARY KEYFile or directory path
is_directoryINTEGER1 for directory, 0 for file
contentBLOBFile content
modeINTEGERPOSIX mode bits
sizeINTEGERFile size in bytes
atime_msINTEGERAccess time (ms)
mtime_msINTEGERModification time (ms)
ctime_msINTEGERChange time (ms)
birthtime_msINTEGERBirth time (ms)

Stores session metadata.

ColumnTypeDescription
session_idTEXT PRIMARY KEYUnique session identifier
agent_typeTEXTAgent type (e.g. “pi”)
capabilitiesTEXT (JSON)Agent capabilities
agent_infoTEXT (JSON)Agent metadata
created_atINTEGERCreation timestamp (ms)

Stores session event history.

ColumnTypeDescription
idINTEGER PRIMARY KEYAuto-incrementing ID
session_idTEXTSession reference
seqINTEGERSequence number within session
eventTEXT (JSON)JSON-RPC notification
created_atINTEGERTimestamp (ms)