-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Show warning on Codex incidents #7305
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
Open
aibrahim-oai
wants to merge
21
commits into
main
Choose a base branch
from
codex-status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b4a1a50
status
aibrahim-oai 44ff9fc
review
aibrahim-oai f05492f
crate
aibrahim-oai 5c40534
use client
aibrahim-oai 075d506
use client
aibrahim-oai 1938116
status
aibrahim-oai 6b66534
status
aibrahim-oai 53ff941
warning
aibrahim-oai 70b613b
warning
aibrahim-oai 087e571
tests
aibrahim-oai 0d0779d
codex-status
aibrahim-oai bbf5368
codex-status
aibrahim-oai 08b6d9e
codex-status
aibrahim-oai e2a5592
Merge branch 'main' into codex-status
aibrahim-oai 764aff6
codex-status
aibrahim-oai af1254f
codex-status
aibrahim-oai 6eb0474
Merge branch 'codex-status' of https://github.com/openai/codex into c…
aibrahim-oai 567844f
codex-status
aibrahim-oai 11b1391
copy
aibrahim-oai 1e77965
copy
aibrahim-oai db70faa
copy
aibrahim-oai 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| use std::collections::HashMap; | ||
| use std::fmt::Debug; | ||
| use std::path::PathBuf; | ||
| use std::pin::Pin; | ||
| use std::sync::Arc; | ||
| use std::sync::atomic::AtomicU64; | ||
|
|
||
| use crate::AuthManager; | ||
| use crate::ResponseStream; | ||
| use crate::SandboxState; | ||
| use crate::client_common::REVIEW_PROMPT; | ||
| use crate::compact; | ||
|
|
@@ -52,6 +54,7 @@ use serde_json::Value; | |
| use tokio::sync::Mutex; | ||
| use tokio::sync::RwLock; | ||
| use tokio::sync::oneshot; | ||
| use tokio::time::sleep_until; | ||
| use tokio_util::sync::CancellationToken; | ||
| use tracing::debug; | ||
| use tracing::error; | ||
|
|
@@ -106,6 +109,7 @@ use crate::shell; | |
| use crate::state::ActiveTurn; | ||
| use crate::state::SessionServices; | ||
| use crate::state::SessionState; | ||
| use crate::status::IdleWarning; | ||
| use crate::tasks::GhostSnapshotTask; | ||
| use crate::tasks::ReviewTask; | ||
| use crate::tasks::SessionTask; | ||
|
|
@@ -2180,12 +2184,19 @@ async fn try_run_turn( | |
| }); | ||
|
|
||
| sess.persist_rollout_items(&[rollout_item]).await; | ||
| let mut stream = turn_context | ||
| .client | ||
| .clone() | ||
| .stream(prompt) | ||
| .or_cancel(&cancellation_token) | ||
| .await??; | ||
| let mut idle_warning = IdleWarning::default(); | ||
| let client = turn_context.client.clone(); | ||
| let mut stream_future = Box::pin(client.stream(prompt).or_cancel(&cancellation_token)); | ||
|
|
||
| let mut stream = await_stream_with_idle_warning( | ||
| stream_future.as_mut(), | ||
| &mut idle_warning, | ||
| &sess, | ||
| &turn_context, | ||
| ) | ||
| .await?; | ||
|
|
||
| idle_warning.mark_event(); | ||
|
|
||
| let tool_runtime = ToolCallRuntime::new( | ||
| Arc::clone(&router), | ||
|
|
@@ -2202,7 +2213,24 @@ async fn try_run_turn( | |
| // Poll the next item from the model stream. We must inspect *both* Ok and Err | ||
| // cases so that transient stream failures (e.g., dropped SSE connection before | ||
| // `response.completed`) bubble up and trigger the caller's retry logic. | ||
| let event = match stream.next().or_cancel(&cancellation_token).await { | ||
| let event = tokio::select! { | ||
| biased; | ||
| result = stream.next().or_cancel(&cancellation_token) => result, | ||
| _ = sleep_until(idle_warning.deadline()) => { | ||
| if let Some(message) = idle_warning.maybe_warning_message().await { | ||
| sess.send_event( | ||
| &turn_context, | ||
| EventMsg::Warning(WarningEvent { message }), | ||
| ) | ||
| .await; | ||
| } | ||
| continue; | ||
| } | ||
aibrahim-oai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| idle_warning.mark_event(); | ||
|
|
||
| let event = match event { | ||
| Ok(event) => event, | ||
| Err(codex_async_utils::CancelErr::Cancelled) => { | ||
| let processed_items = output.try_collect().await?; | ||
|
|
@@ -2401,6 +2429,34 @@ async fn try_run_turn( | |
| } | ||
| } | ||
|
|
||
| async fn await_stream_with_idle_warning<F>( | ||
| mut stream_future: Pin<&mut F>, | ||
| idle_warning: &mut IdleWarning, | ||
| sess: &Arc<Session>, | ||
| turn_context: &Arc<TurnContext>, | ||
| ) -> CodexResult<ResponseStream> | ||
| where | ||
| F: std::future::Future< | ||
| Output = Result<CodexResult<ResponseStream>, codex_async_utils::CancelErr>, | ||
| > + Send, | ||
| { | ||
| loop { | ||
| tokio::select! { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you need to mark the event while being processed |
||
| biased; | ||
| result = &mut stream_future => return result?, | ||
| _ = sleep_until(idle_warning.deadline()) => { | ||
| if let Some(message) = idle_warning.maybe_warning_message().await { | ||
| sess.send_event( | ||
| turn_context, | ||
| EventMsg::Warning(WarningEvent { message }), | ||
| ) | ||
| .await; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async fn handle_non_tool_response_item(item: &ResponseItem) -> Option<TurnItem> { | ||
| debug!(?item, "Output item"); | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
This continue will skip the
idle_warning.mark_event();