Skip to content

Commit 86cb211

Browse files
committed
Distinguish unknown Codex thread statuses
1 parent 88cbe02 commit 86cb211

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

src/codex_app_server.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ pub enum CodexHoldReason {
197197
Compaction,
198198
NotLoaded,
199199
SystemError,
200+
UnknownStatus,
200201
WaitingOnApproval,
201202
WaitingOnUserInput,
202203
}
@@ -847,7 +848,7 @@ impl CodexControlState {
847848
turn_id: None,
848849
},
849850
_ => CodexObservedState::Held {
850-
reason: CodexHoldReason::SystemError,
851+
reason: CodexHoldReason::UnknownStatus,
851852
turn_id: None,
852853
},
853854
};
@@ -902,7 +903,8 @@ impl CodexControlState {
902903
| CodexHoldReason::WaitingOnApproval
903904
| CodexHoldReason::WaitingOnUserInput
904905
| CodexHoldReason::NotLoaded
905-
| CodexHoldReason::SystemError,
906+
| CodexHoldReason::SystemError
907+
| CodexHoldReason::UnknownStatus,
906908
..
907909
} => self.observed.clone(),
908910
// A completion for a turn other than the one believed live is the only evidence here
@@ -4106,6 +4108,51 @@ mod tests {
41064108
);
41074109
}
41084110

4111+
#[test]
4112+
fn an_unrecognized_thread_status_has_a_distinct_delivery_hold() {
4113+
let mut state = subscribed_state(CodexObservedState::Active {
4114+
turn_id: "turn-1".into(),
4115+
});
4116+
4117+
state
4118+
.observe(&json!({
4119+
"method": "thread/status/changed",
4120+
"params": {
4121+
"threadId": "thread-main",
4122+
"status": { "type": "futureStatus" }
4123+
}
4124+
}))
4125+
.unwrap();
4126+
assert_eq!(
4127+
state.observed(),
4128+
&CodexObservedState::Held {
4129+
reason: CodexHoldReason::UnknownStatus,
4130+
turn_id: None,
4131+
}
4132+
);
4133+
4134+
state
4135+
.observe(&json!({
4136+
"method": "turn/completed",
4137+
"params": { "threadId": "thread-main", "turn": { "id": "turn-1" } }
4138+
}))
4139+
.unwrap();
4140+
assert!(matches!(
4141+
state.observed(),
4142+
CodexObservedState::Held {
4143+
reason: CodexHoldReason::UnknownStatus,
4144+
..
4145+
}
4146+
));
4147+
4148+
let tmp = tempfile::tempdir().unwrap();
4149+
let config = delivery_config(tmp.path());
4150+
message::send_to_inbox(&config.inbox, "h.sender", Some("held"), None, &[], "body")
4151+
.unwrap();
4152+
let mut delivery = inbox_delivery(tmp.path(), config);
4153+
assert_eq!(delivery.maybe_request(&state).unwrap(), None);
4154+
}
4155+
41094156
#[test]
41104157
fn persisted_control_state_is_bound_to_the_exact_runtime_incarnation() {
41114158
let tmp = tempfile::tempdir().unwrap();

0 commit comments

Comments
 (0)