-
Notifications
You must be signed in to change notification settings - Fork 7.3k
feat: add list loaded threads to app server #8902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
codex-rs/app-server/tests/suite/v2/thread_loaded_list.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| use anyhow::Result; | ||
| use app_test_support::McpProcess; | ||
| use app_test_support::create_mock_chat_completions_server; | ||
| use app_test_support::to_response; | ||
| use codex_app_server_protocol::JSONRPCResponse; | ||
| use codex_app_server_protocol::RequestId; | ||
| use codex_app_server_protocol::ThreadLoadedListParams; | ||
| use codex_app_server_protocol::ThreadLoadedListResponse; | ||
| use codex_app_server_protocol::ThreadStartParams; | ||
| use codex_app_server_protocol::ThreadStartResponse; | ||
| use pretty_assertions::assert_eq; | ||
| use std::path::Path; | ||
| use tempfile::TempDir; | ||
| use tokio::time::timeout; | ||
|
|
||
| const DEFAULT_READ_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10); | ||
|
|
||
| #[tokio::test] | ||
| async fn thread_loaded_list_returns_loaded_thread_ids() -> Result<()> { | ||
| let server = create_mock_chat_completions_server(vec![]).await; | ||
| let codex_home = TempDir::new()?; | ||
| create_config_toml(codex_home.path(), &server.uri())?; | ||
|
|
||
| let mut mcp = McpProcess::new(codex_home.path()).await?; | ||
| timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??; | ||
|
|
||
| let thread_id = start_thread(&mut mcp).await?; | ||
|
|
||
| let list_id = mcp | ||
| .send_thread_loaded_list_request(ThreadLoadedListParams::default()) | ||
| .await?; | ||
| let resp: JSONRPCResponse = timeout( | ||
| DEFAULT_READ_TIMEOUT, | ||
| mcp.read_stream_until_response_message(RequestId::Integer(list_id)), | ||
| ) | ||
| .await??; | ||
| let ThreadLoadedListResponse { | ||
| mut data, | ||
| next_cursor, | ||
| } = to_response::<ThreadLoadedListResponse>(resp)?; | ||
| data.sort(); | ||
| assert_eq!(data, vec![thread_id]); | ||
| assert_eq!(next_cursor, None); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn thread_loaded_list_paginates() -> Result<()> { | ||
| let server = create_mock_chat_completions_server(vec![]).await; | ||
| let codex_home = TempDir::new()?; | ||
| create_config_toml(codex_home.path(), &server.uri())?; | ||
|
|
||
| let mut mcp = McpProcess::new(codex_home.path()).await?; | ||
| timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??; | ||
|
|
||
| let first = start_thread(&mut mcp).await?; | ||
| let second = start_thread(&mut mcp).await?; | ||
|
|
||
| let mut expected = [first, second]; | ||
| expected.sort(); | ||
|
|
||
| let list_id = mcp | ||
| .send_thread_loaded_list_request(ThreadLoadedListParams { | ||
| cursor: None, | ||
| limit: Some(1), | ||
| }) | ||
| .await?; | ||
| let resp: JSONRPCResponse = timeout( | ||
| DEFAULT_READ_TIMEOUT, | ||
| mcp.read_stream_until_response_message(RequestId::Integer(list_id)), | ||
| ) | ||
| .await??; | ||
| let ThreadLoadedListResponse { | ||
| data: first_page, | ||
| next_cursor, | ||
| } = to_response::<ThreadLoadedListResponse>(resp)?; | ||
| assert_eq!(first_page, vec![expected[0].clone()]); | ||
| assert_eq!(next_cursor, Some(expected[0].clone())); | ||
|
|
||
| let list_id = mcp | ||
| .send_thread_loaded_list_request(ThreadLoadedListParams { | ||
| cursor: next_cursor, | ||
| limit: Some(1), | ||
| }) | ||
| .await?; | ||
| let resp: JSONRPCResponse = timeout( | ||
| DEFAULT_READ_TIMEOUT, | ||
| mcp.read_stream_until_response_message(RequestId::Integer(list_id)), | ||
| ) | ||
| .await??; | ||
| let ThreadLoadedListResponse { | ||
| data: second_page, | ||
| next_cursor, | ||
| } = to_response::<ThreadLoadedListResponse>(resp)?; | ||
| assert_eq!(second_page, vec![expected[1].clone()]); | ||
| assert_eq!(next_cursor, None); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn create_config_toml(codex_home: &Path, server_uri: &str) -> std::io::Result<()> { | ||
| let config_toml = codex_home.join("config.toml"); | ||
| std::fs::write( | ||
| config_toml, | ||
| format!( | ||
| r#" | ||
| model = "mock-model" | ||
| approval_policy = "never" | ||
| sandbox_mode = "read-only" | ||
|
|
||
| model_provider = "mock_provider" | ||
|
|
||
| [model_providers.mock_provider] | ||
| name = "Mock provider for test" | ||
| base_url = "{server_uri}/v1" | ||
| wire_api = "chat" | ||
| request_max_retries = 0 | ||
| stream_max_retries = 0 | ||
| "# | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| async fn start_thread(mcp: &mut McpProcess) -> Result<String> { | ||
| let req_id = mcp | ||
| .send_thread_start_request(ThreadStartParams { | ||
| model: Some("gpt-5.1".to_string()), | ||
| ..Default::default() | ||
| }) | ||
| .await?; | ||
| let resp: JSONRPCResponse = timeout( | ||
| DEFAULT_READ_TIMEOUT, | ||
| mcp.read_stream_until_response_message(RequestId::Integer(req_id)), | ||
| ) | ||
| .await??; | ||
| let ThreadStartResponse { thread, .. } = to_response::<ThreadStartResponse>(resp)?; | ||
| Ok(thread.id) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this return
Vec<Thread>? i.e. would the metadata on Thread be useful?We don't have to populate all the turns & items since we only do that for specific APIs (we've already documented the behavior on the
Threadobject)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because sometimes we don't have them and don't need them
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, would be nice to support pagination for consistency with our other list APIs, even though in practice you'd probably want to return everything always. Mainly because adding pagination later is a breaking change