Skip to content

Debug agents with query log

Query log is a per-database ring buffer that records every SQL statement with its parameters, duration, and outcome. On restart, an agent replays recent entries to reconstruct exactly what succeeded, what failed, and where to resume without relying on in-memory state.

import { PerSQL } from "@persql/sdk";
const persql = new PerSQL({ token: process.env.PERSQL_TOKEN! });
const db = persql.database("acme/runs");
// Reconstruct last run from the per-database query ring buffer
const { data: log } = await db.queryLog({ pageSize: 50 });
for (const entry of log.reverse()) {
if (entry.status === "error") {
console.error("Failed:", entry.sqlText, entry.errorMessage);
}
}
// Resume from the first unfinished job recorded in the database
const tail = await db.query(
"SELECT step FROM agent_jobs WHERE done = 0 ORDER BY id LIMIT 1"
);
console.log("Resume at:", tail.data[0]?.step ?? "all done");

The log includes parameter JSON, so an agent can reconstruct inputs that were never persisted to application tables. No telemetry pipeline or external collector is required.

Resume agent plans without duplicate work