revert_session_to_message
Rewinds a chat session, document and conversation, to just before a specific user message. The reverted message's text comes back as compose_text, to edit and resend. Messages from the reverted turn forward are soft-archived: hidden but kept (redo_revert restores them). Pass the turn_index a chat reply returned. Rejects with 409 while a chat job is in progress or awaiting approval. Returns 422 (code 'turn_has_no_restore_point') when the turn recorded no restore point (usually the message before it did not finish); the response lists revertable_turns (possibly empty) that can be rewound to.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"session_id": "<session_id>",
"turn_index": "<turn_index>"
},
"name": "revert_session_to_message"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dry_run | No | When true, compute the per-document revert diff WITHOUT committing or archiving anything — used to render a preview before the user confirms. | |
| session_id | Yes | ||
| turn_index | Yes | Turn index of the user message to revert. The text of that message is returned in compose_text so the caller can re-edit and resend it. Every chat row at this turn or later is soft-archived (hidden from active reads but retained for audit). | |
| response_mode | No | 'summary': no HTML; counts, conflicts, the redo handle. | full |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dry_run | No | Echoes the request's dry_run: when true nothing was committed/archived — this is a preview only. | |
| session_id | Yes | Session identifier. | |
| compose_text | Yes | The text of the user message that was reverted. Clients should pre-fill the compose box with this so the user can edit and resend. | |
| change_counts | No | response_mode 'summary' only (absent otherwise): per document (slug), how many sections the revert restores, by operation (edit, create, delete). Summary carries this in place of revert_changes, which is null there. | |
| editor_action | No | Client instruction: 'update' to load the restored document, or 'clear' to reset the editor to empty. | update |
| document_state | No | Restored document state. Null when the session is reset to empty. | |
| revert_changes | No | Per-document (slug -> change-set) revert diff. Applying these merges the revert onto any concurrent live edits — a conflicting section is surfaced for you to resolve rather than replacing the whole document. On dry_run this is the preview; on a real revert it is what was committed. | |
| revert_conflicts | No | Per-document (slug -> entries) sections whose restore did NOT fully land. TWO classes, told apart by the 'displaced' flag. (1) NOT LANDED ('displaced' absent/false): content another writer committed was preserved instead (reason 'concurrent_edit_preserved' / 'lineage_unknown'), or a removal could not be resolved against the live document; the matching revert_changes entry is annotated 'conflict': true and carries the preserved bytes as new_html (the honest committed state) plus the un-landed restore as restore_html. (2) LANDED IN THE WRONG PLACE ('displaced': true): the content WAS restored but not at its original position — reason 'restored_elsewhere' (it was added at the end of the document because the section it anchors to is gone) or 'position_not_restored' (a concurrent writer's placement won). These carry an empty their_html (nothing of another writer's was preserved, so there is nothing to adopt) plus the raw 'resolution' token, and the matching revert_changes entry is annotated 'displaced': true — never 'conflict', because new_html is still the restored content. (3) NOT SAVED AT ALL ('write_failed': true, operation 'write', chunk_id null): the document's recovery write did not commit — reason 'document_deleted' (archived mid-revert), 'storage_paused' (durable saving paused for this account) or 'write_failed'. Document-level, so there is no matching revert_changes entry; storage still holds the pre-revert content while document_state shows the reverted document, so a client MUST re-read the document before saving again. Null/absent when the revert landed cleanly everywhere. | |
| reverted_to_turn | Yes | Turn index that the active conversation now ends at (the AI reply preceding the reverted user message). -1 when the session is reset to its initial empty state (revert from the very first user message). | |
| redo_checkpoint_id | No | The identifier of the pre-revert state. Revert is non-destructive — passing this back to POST /sessions/{id}/redo (with the same turn_index) restores it and un-archives the rolled-back turns, undoing the revert. Null on a dry-run, and null when the pre-revert state could not be captured — in that case redo_unavailable_reason says which, so absence by design and absence by failure are never the same value. | |
| archived_turn_count | Yes | Number of chat rows soft-archived by this revert (turns hidden from the UI but retained for audit). | |
| redo_unavailable_reason | No | Present ONLY when redo_checkpoint_id is null because the pre-revert state could not be captured (never on a dry-run, where null is by design). The revert itself succeeded and is durable; what is unavailable is the one-step undo of it. Treat a non-null value as: do not attempt redo_revert for this revert — it has no argument to pass. |