# When the agent gets it wrong

URL: https://kywi-docs-production.up.railway.app/agent/when-the-agent-gets-it-wrong
Type: docPage

Most direct content writes leave no audit-log row at all, and the row a workflow write does leave carries the same user id a human edit would.

The audit log is not a record of everything an agent did. It's written only from the workflow path — submitting, approving, rejecting — and from revision approve/reject. A direct `create_content`, `update_content`, `publish_content`, or `delete_content` call never touches it. (A changeset that publishes a pending revision runs the same approve bookkeeping, and no content tool builds changesets.)

## Direct writes are untraceable in the audit log — but not unrecoverable

A direct write leaves no audit-log entry, so the audit log is the wrong place to look for what an agent changed or when. Two other trails survive it, unevenly. A `delete_content` call is a soft delete — nothing is removed, the row is marked deleted and lands in Trash. Version history runs the other way round from what you'd expect: an update or a publish takes its snapshot after the write lands, not before, so the version it stores is the new state, not the one it replaced. A `create_content` takes no snapshot at all, so a page an agent created and then edited has no version of its original state either. That timing changes what you restore — after one bad agent edit, the newest version in history is the bad state itself, and the version to bring back is the one below it, the last snapshot taken before the bad write landed. A snapshot that fails is logged as a warning and swallowed — the save still succeeds, quietly, with nothing behind it. Recovering from a bad direct write means reading version history for the state before the damage, and checking Trash, not searching for an audit entry that was never written.

## Version history keeps only the newest 50 versions of an item

Every snapshot prunes that item's history back to fifty rows. Fifty saves is an afternoon of an agent making small corrections to one page, and there is no protected slot for the last snapshot a person took — it goes off the end with everything else. Before you hand an agent a page you care about, note the newest version's timestamp in Version History; that's the last human state you'll want to find again once the agent's own saves start pushing older versions off the end — there is no page export to fall back on instead.

## Where a row does exist, it doesn’t say "agent"

Where the workflow path does stamp an audit row, and wherever an ordinary save stamps `createdBy`/`updatedBy`, the value written is the same user id an interactive session's write would carry — an API-key-authenticated call resolves to the account that owns the key. There's no separate marker distinguishing a key-driven write from that same user editing by hand; a row that says a change came from you could just as well be an agent using your key.

## Telling an agent’s writes apart from your own

The one way to make writes attributable is to give each agent its own account and its own key, named for what it is, rather than sharing your own key across every agent you run. A key is created under, and listed under, the account that owns it, so a dedicated agent account turns "who wrote this" back into a question `createdBy` can actually answer — a shared key can't. Nothing else in the schema will do this job for you: the audit table records a user id and an email and has no column for which key, or what kind of caller, made the change.

## Undoing a bad write

Whatever the audit log does or doesn't show, [Version history and rollback](/governing/version-history-and-rollback/) and [Trash and permanent deletion](/governing/trash-and-permanent-deletion/) are where you go to actually undo it — restore an earlier version onto a page an agent edited badly, or pull a deleted page back out of Trash before it's gone for good.
