mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
code-mode: claim buffered completion once
This commit is contained in:
@@ -611,6 +611,34 @@ fn failed_completion_delivery_rebuffers_the_event() {
|
||||
assert_eq!(response_rx.try_recv(), Ok(Ok(event)));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn only_the_first_termination_claims_a_buffered_completion() {
|
||||
let session_shutdown_token = CancellationToken::new();
|
||||
let cell_state = CellState::new(session_shutdown_token.child_token());
|
||||
let completion = CellEvent::Completed {
|
||||
content_items: Vec::new(),
|
||||
error_text: None,
|
||||
};
|
||||
assert!(cell_state.commit_completion(completion.clone(), || {}));
|
||||
assert!(matches!(
|
||||
cell_state.deliver_completion(/*response_tx*/ None),
|
||||
CompletionDelivery::Buffered
|
||||
));
|
||||
|
||||
let first_termination = cell_state.request_termination();
|
||||
assert_eq!(
|
||||
cell_state.request_termination().await,
|
||||
Err(CellError::AlreadyTerminating)
|
||||
);
|
||||
assert_eq!(first_termination.await, Ok(completion.clone()));
|
||||
assert_eq!(
|
||||
cell_state.finish_termination(CellEvent::Terminated {
|
||||
content_items: Vec::new(),
|
||||
}),
|
||||
Some(completion)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_shutdown_rejects_observation_before_the_actor_closes() {
|
||||
let session_shutdown_token = CancellationToken::new();
|
||||
|
||||
@@ -115,6 +115,7 @@ enum CellPhase {
|
||||
response_tx: oneshot::Sender<Result<CellEvent, CellError>>,
|
||||
},
|
||||
Completed(CellEvent),
|
||||
CompletionClaimed(CellEvent),
|
||||
Tombstone,
|
||||
}
|
||||
|
||||
@@ -167,10 +168,14 @@ impl CellState {
|
||||
Box::pin(async { Err(CellError::AlreadyTerminating) })
|
||||
}
|
||||
CellPhase::Completed(event) => {
|
||||
*phase = CellPhase::Completed(event.clone());
|
||||
*phase = CellPhase::CompletionClaimed(event.clone());
|
||||
self.cancellation_token.cancel();
|
||||
ready_event(event)
|
||||
}
|
||||
CellPhase::CompletionClaimed(event) => {
|
||||
*phase = CellPhase::CompletionClaimed(event);
|
||||
Box::pin(async { Err(CellError::AlreadyTerminating) })
|
||||
}
|
||||
CellPhase::Tombstone => closed_event(),
|
||||
}
|
||||
}
|
||||
@@ -257,6 +262,11 @@ impl CellState {
|
||||
let _ = response_tx.send(Err(CellError::Closed));
|
||||
ObservationDelivery::Closed
|
||||
}
|
||||
CellPhase::CompletionClaimed(event) => {
|
||||
*phase = CellPhase::CompletionClaimed(event);
|
||||
let _ = response_tx.send(Err(CellError::Closed));
|
||||
ObservationDelivery::Closed
|
||||
}
|
||||
CellPhase::Tombstone => {
|
||||
let _ = response_tx.send(Err(CellError::Closed));
|
||||
ObservationDelivery::Closed
|
||||
@@ -276,6 +286,7 @@ impl CellState {
|
||||
Some(event)
|
||||
}
|
||||
CellPhase::Completed(completed_event) => Some(completed_event),
|
||||
CellPhase::CompletionClaimed(completed_event) => Some(completed_event),
|
||||
CellPhase::Tombstone => None,
|
||||
};
|
||||
self.cancellation_token.cancel();
|
||||
|
||||
Reference in New Issue
Block a user