feat(app-server): add history_mode to thread (#29927)

## Description

This PR adds a new `historyMode = "legacy" | "paginated"` to `Thread`.
This will be stored in `SessionMeta` in the JSONL rollout file and as a
new column in the SQLite thread_metadata table, and exposed on
`thread/start` and on the `Thread` object in app-server.

## What changed

- Added canonical `ThreadHistoryMode` with `legacy` and `paginated`,
defaulting old and new SessionMeta to `legacy`.
- Carried `history_mode` through core session config, ThreadStore stored
metadata, local/in-memory stores, rollout metadata extraction, and the
existing SQLite `threads` table.
- Added experimental `historyMode` to app-server v2 `Thread` and
`thread/start`.
- Made paginated stored threads metadata-discoverable but unsupported
for legacy full-history reads, `load_history`, live resume, and create
paths.
- Regenerated app-server schema fixtures and added
protocol/state/thread-store/app-server coverage for persistence and
fail-closed behavior.

## Compatibility floor
Because users may be running various versions of Codex binaries on the
same machine (TUI, Codex App, etc.), we will need to establish a
compatibility floor for upcoming paginated threads, which will change
how thread storage reads and writes work.

The overall plan here:
```
Release N:
- Add historyMode to SessionMeta / Thread / SQLite metadata.
- Teach binaries to understand paginated threads.
- If a binary sees `historyMode="paginated"` but does not support the paginated contract, it refuses to resume/mutate the thread.
- Default remains `"legacy"`.

Release N+1:
- First-party clients start opting into paginated threads where appropriate.
- Internal dogfood / staged rollout.
- Measure old-client usage and paginated-thread unsupported errors.

Release N+2:
- Only after Release N+ is overwhelmingly deployed, make paginated the default.
- Accept that a small tail of N-1-or-older binaries may not understand paginated threads.
```

The important behavior change is fail-closed handling for a binary that
encounters a persisted `paginated` thread before it knows how to fully
support paginated history. In app-server, if a thread is `paginated`, we
will:

- allow metadata-only discovery paths like `thread/list` and
`thread/read(includeTurns=false)`, so clients can still see the thread
and inspect its `historyMode`
- reject legacy full-history/live-thread paths like
`thread/read(includeTurns=true)` and `thread/resume` with an unsupported
JSON-RPC error
- avoid silently treating an unknown or future `historyMode` as `legacy`

Under the hood, the ThreadStore layer also rejects legacy operations
that would need to load or replay the full thread history for a
paginated thread. That gives us the behavior we want for Release N:
future paginated threads are visible, but this binary fails closed
instead of trying to operate on them as if they were legacy threads.
This commit is contained in:
Owen Lin authored and GitHub committed 2026-06-26 09:12:42 -07:00
1 parent 2c5bc5e284
commit 5267e805fb
91 files changed
+1385 -39

No files matched your search

+47
View File
@@ -129,6 +129,41 @@ async fn find_thread_path_falls_back_when_db_path_is_stale() {
assert_state_db_rollout_path(home, thread_id, Some(fs_rollout_path.as_path())).await;
}
#[tokio::test]
async fn read_thread_item_from_rollout_rejects_unknown_canonical_history_mode() {
let temp = TempDir::new().unwrap();
let home = temp.path();
let uuid = Uuid::from_u128(303);
let ts = "2025-01-03T12-00-00";
write_session_file(
home,
ts,
uuid,
/*num_records*/ 1,
Some(SessionSource::Cli),
)
.unwrap();
let path = home.join(format!("sessions/2025/01/03/rollout-{ts}-{uuid}.jsonl"));
let contents = fs::read_to_string(&path).unwrap();
let mut lines = contents.lines();
let mut canonical_meta: serde_json::Value =
serde_json::from_str(lines.next().expect("canonical session meta")).unwrap();
canonical_meta["payload"]["history_mode"] = serde_json::json!("future");
let user_event = lines.next().expect("user event");
let mut source_meta = canonical_meta.clone();
let source_uuid = Uuid::from_u128(304);
source_meta["payload"]["session_id"] = serde_json::json!(source_uuid);
source_meta["payload"]["id"] = serde_json::json!(source_uuid);
source_meta["payload"]["history_mode"] = serde_json::json!("legacy");
fs::write(
&path,
format!("{canonical_meta}\n{user_event}\n{source_meta}\n"),
)
.unwrap();
assert_eq!(crate::list::read_thread_item_from_rollout(path).await, None);
}
#[tokio::test]
async fn find_thread_path_falls_back_when_db_path_points_to_another_thread() {
let temp = TempDir::new().unwrap();
@@ -610,6 +645,7 @@ async fn test_list_conversations_latest_first() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -629,6 +665,7 @@ async fn test_list_conversations_latest_first() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -648,6 +685,7 @@ async fn test_list_conversations_latest_first() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -760,6 +798,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -779,6 +818,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -834,6 +874,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -853,6 +894,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -900,6 +942,7 @@ async fn test_pagination_cursor() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -1072,6 +1115,7 @@ async fn test_get_thread_contents() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -1290,6 +1334,7 @@ async fn test_updated_at_uses_file_mtime() -> Result<()> {
dynamic_tools: None,
selected_capability_roots: Vec::new(),
memory_mode: None,
history_mode: Default::default(),
multi_agent_version: None,
context_window: None,
},
@@ -1432,6 +1477,7 @@ async fn test_timestamp_only_cursor_skips_same_second_filesystem_ties() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,
@@ -1451,6 +1497,7 @@ async fn test_timestamp_only_cursor_skips_same_second_filesystem_ties() {
git_sha: None,
git_origin_url: None,
source: Some(SessionSource::VSCode),
history_mode: Default::default(),
parent_thread_id: None,
agent_nickname: None,
agent_role: None,