core-agent-ide/codex-rs/protocol/src
Owen Lin 8b7ec31ba7
feat(app-server): thread/rollback API (#8454)
Add `thread/rollback` to app-server to support IDEs undo-ing the last N
turns of a thread.

For context, an IDE partner will be supporting an "undo" capability
where the IDE (the app-server client) will be responsible for reverting
the local changes made during the last turn. To support this well, we
also need a way to drop the last turn (or more generally, the last N
turns) from the agent's context. This is what `thread/rollback` does.

**Core idea**: A Thread rollback is represented as a persisted event
message (EventMsg::ThreadRollback) in the rollout JSONL file, not by
rewriting history. On resume, both the model's context (core replay) and
the UI turn list (app-server v2's thread history builder) apply these
markers so the pruned history is consistent across live conversations
and `thread/resume`.

Implementation notes:
- Rollback only affects agent context and appends to the rollout file;
clients are responsible for reverting files on disk.
- If a thread rollback is currently in progress, subsequent
`thread/rollback` calls are rejected.
- Because we use `CodexConversation::submit` and codex core tracks
active turns, returning an error on concurrent rollbacks is communicated
via an `EventMsg::Error` with a new variant
`CodexErrorInfo::ThreadRollbackFailed`. app-server watches for that and
sends the BAD_REQUEST RPC response.

Tests cover thread rollbacks in both core and app-server, including when
`num_turns` > existing turns (which clears all turns).

**Note**: this explicitly does **not** behave like `/undo` which we just
removed from the CLI, which does the opposite of what `thread/rollback`
does. `/undo` reverts local changes via ghost commits/snapshots and does
not modify the agent's context / conversation history.
2026-01-06 21:23:48 +00:00
..
account.rs fix: move account struct to app-server-protocol and use camelCase (#5829) 2025-10-27 14:06:13 -07:00
approvals.rs Removed experimental "command risk assessment" feature (#7799) 2025-12-10 09:48:11 -08:00
config_types.rs Migrate model preset (#7542) 2025-12-03 20:30:43 +00:00
conversation_id.rs Generate JSON schema for app-server protocol (#5063) 2025-10-20 11:45:11 -07:00
custom_prompts.rs [app-server] remove serde(skip_serializing_if = "Option::is_none") annotations (#5939) 2025-10-30 18:18:53 +00:00
items.rs [app-server] small fixes for JSON schema export and one-of types (#6614) 2025-11-13 16:25:17 -08:00
lib.rs Migrate model preset (#7542) 2025-12-03 20:30:43 +00:00
message_history.rs Generate JSON schema for app-server protocol (#5063) 2025-10-20 11:45:11 -07:00
models.rs Log compaction request bodies (#8676) 2026-01-02 11:27:37 -08:00
num_format.rs Auto compact at ~90% (#5292) 2025-10-20 11:29:49 -07:00
openai_models.rs Refresh on models etag mismatch (#8491) 2026-01-01 11:41:16 -08:00
parse_command.rs [app-server] remove serde(skip_serializing_if = "Option::is_none") annotations (#5939) 2025-10-30 18:18:53 +00:00
plan_tool.rs [app-server] remove serde(skip_serializing_if = "Option::is_none") annotations (#5939) 2025-10-30 18:18:53 +00:00
protocol.rs feat(app-server): thread/rollback API (#8454) 2026-01-06 21:23:48 +00:00
user_input.rs Inject SKILL.md when it's explicitly mentioned. (#7763) 2025-12-10 13:59:17 -08:00