Lightweight coding agent that runs in your terminal
Rust
feat: return session ID from thread/fork (#21332)
jif-oai06e5dfa4dd9f
diff --git a/codex-rs/analytics/src/client_tests.rs b/codex-rs/analytics/src/client_tests.rsindex 42d508602a..510378c20d 100644--- a/codex-rs/analytics/src/client_tests.rs+++ b/codex-rs/analytics/src/client_tests.rs@@ -138,6 +138,7 @@ fn sample_thread_resume_response() -> ClientResponsePayload {fn sample_thread_fork_response() -> ClientResponsePayload {ClientResponsePayload::ThreadFork(ThreadForkResponse {+ session_id: "session-3".to_string(),thread: sample_thread("thread-3"),model: "gpt-5".to_string(),model_provider: "openai".to_string(),diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.jsonindex d6f184a6db..20279bf010 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json@@ -15664,6 +15664,11 @@}]},+ "sessionId": {+ "default": "",+ "description": "Session id shared by threads that belong to the same session tree.",+ "type": "string"+ },"thread": {"$ref": "#/definitions/v2/Thread"}diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.jsonindex 1f252cbd23..50a19200a5 100644--- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json+++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json@@ -13550,6 +13550,11 @@}]},+ "sessionId": {+ "default": "",+ "description": "Session id shared by threads that belong to the same session tree.",+ "type": "string"+ },"thread": {"$ref": "#/definitions/Thread"}diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.jsonindex 05f9849df3..902a6f4c9f 100644--- a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json+++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json@@ -2619,6 +2619,11 @@}]},+ "sessionId": {+ "default": "",+ "description": "Session id shared by threads that belong to the same session tree.",+ "type": "string"+ },"thread": {"$ref": "#/definitions/Thread"}diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ThreadForkResponse.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ThreadForkResponse.tsindex ddcef104e9..b0bb9caea6 100644--- a/codex-rs/app-server-protocol/schema/typescript/v2/ThreadForkResponse.ts+++ b/codex-rs/app-server-protocol/schema/typescript/v2/ThreadForkResponse.ts@@ -9,7 +9,10 @@ import type { AskForApproval } from "./AskForApproval";import type { SandboxPolicy } from "./SandboxPolicy";import type { Thread } from "./Thread";-export type ThreadForkResponse = {thread: Thread, model: string, modelProvider: string, serviceTier: ServiceTier | null, cwd: AbsolutePathBuf, /**+export type ThreadForkResponse = {/**+ * Session id shared by threads that belong to the same session tree.+ */+sessionId: string, thread: Thread, model: string, modelProvider: string, serviceTier: ServiceTier | null, cwd: AbsolutePathBuf, /*** Instruction source files currently loaded for this thread.*/instructionSources: Array<AbsolutePathBuf>, approvalPolicy: AskForApproval, /**diff --git a/codex-rs/app-server-protocol/src/protocol/v2/thread.rs b/codex-rs/app-server-protocol/src/protocol/v2/thread.rsindex d8250987a6..5a09c2e665 100644--- a/codex-rs/app-server-protocol/src/protocol/v2/thread.rs+++ b/codex-rs/app-server-protocol/src/protocol/v2/thread.rs@@ -419,6 +419,9 @@ pub struct ThreadForkParams {#[serde(rename_all = "camelCase")]#[ts(export_to = "v2/")]pub struct ThreadForkResponse {+ /// Session id shared by threads that belong to the same session tree.+ #[serde(default)]+ pub session_id: String,pub thread: Thread,pub model: String,pub model_provider: String,diff --git a/codex-rs/app-server/README.md b/codex-rs/app-server/README.mdindex 60ff4573aa..8aeeb7df4f 100644--- a/codex-rs/app-server/README.md+++ b/codex-rs/app-server/README.md@@ -303,11 +303,11 @@ Example:{ "id": 12, "result": { "thread": { "id": "thr_123", "turns": [], … } } }```-To branch from a stored session, call `thread/fork` with the `thread.id`. This creates a new thread id and emits a `thread/started` notification for it. When the source history includes persisted token usage, the server also emits `thread/tokenUsage/updated` for the new thread immediately after the response. If the source thread is actively running, the fork snapshots it as if the current turn had been interrupted first. Pass `ephemeral: true` when the fork should stay in-memory only:+To branch from a stored session, call `thread/fork` with the `thread.id`. This creates a new thread id and emits a `thread/started` notification for it. The response includes the forked thread's `sessionId`, so clients do not need to infer it from the new thread id. When the source history includes persisted token usage, the server also emits `thread/tokenUsage/updated` for the new thread immediately after the response. If the source thread is actively running, the fork snapshots it as if the current turn had been interrupted first. Pass `ephemeral: true` when the fork should stay in-memory only:```json{ "method": "thread/fork", "id": 12, "params": { "threadId": "thr_123", "ephemeral": true } }-{ "id": 12, "result": { "thread": { "id": "thr_456", … } } }+{ "id": 12, "result": { "sessionId": "thr_456", "thread": { "id": "thr_456", … } } }{ "method": "thread/started", "params": { "thread": { … } } }```diff --git a/codex-rs/app-server/src/request_processors/thread_processor.rs b/codex-rs/app-server/src/request_processors/thread_processor.rsindex 5563bd56e9..7cef88b14b 100644--- a/codex-rs/app-server/src/request_processors/thread_processor.rs+++ b/codex-rs/app-server/src/request_processors/thread_processor.rs@@ -3116,6 +3116,7 @@ impl ThreadRequestProcessor {thread_response_active_permission_profile(config_snapshot.active_permission_profile);let response = ThreadForkResponse {+ session_id: session_configured.session_id.to_string(),thread: thread.clone(),model: session_configured.model,model_provider: session_configured.model_provider_id,diff --git a/codex-rs/app-server/tests/suite/v2/thread_fork.rs b/codex-rs/app-server/tests/suite/v2/thread_fork.rsindex 5c4ba3a3e3..4a6644e30a 100644--- a/codex-rs/app-server/tests/suite/v2/thread_fork.rs+++ b/codex-rs/app-server/tests/suite/v2/thread_fork.rs@@ -101,7 +101,9 @@ async fn thread_fork_creates_new_thread_and_emits_started() -> Result<()> {).await??;let fork_result = fork_resp.result.clone();- let ThreadForkResponse { thread, .. } = to_response::<ThreadForkResponse>(fork_resp)?;+ let ThreadForkResponse {+ session_id, thread, ..+ } = to_response::<ThreadForkResponse>(fork_resp)?;// Wire contract: thread title field is `name`, serialized as null when unset.let thread_json = fork_result@@ -121,6 +123,7 @@ async fn thread_fork_creates_new_thread_and_emits_started() -> Result<()> {);assert_ne!(thread.id, conversation_id);+ assert_eq!(session_id, thread.id);assert_eq!(thread.forked_from_id, Some(conversation_id.clone()));assert_eq!(thread.preview, preview);assert_eq!(thread.model_provider, "mock_provider");