mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
[codex] route sleep through time providers (#29973)
## Summary - add a cancellable sleep operation to `TimeProvider` - route `clock.sleep` through the configured provider - extend the supported sleep duration to 12 hours - complete the sleep turn item before propagating provider failures ## Why This isolates the core clock abstraction needed by external clock integrations. Existing system and app-server behavior remains wall-clock based in this PR; the stacked follow-up supplies app-server sleeps from an external clock.
This commit is contained in:
1 parent
22f12568e1
commit
f66d793a2d
5 files changed
+130
-12
No files matched your search
@@ -21,7 +21,7 @@ use std::time::Instant;
|
||||
|
||||
const NAMESPACE: &str = "clock";
|
||||
const TOOL_NAME: &str = "sleep";
|
||||
const MAX_SLEEP_DURATION_MS: u64 = 3_600_000;
|
||||
const MAX_SLEEP_DURATION_MS: u64 = 12 * 60 * 60 * 1000;
|
||||
|
||||
pub struct SleepHandler;
|
||||
|
||||
@@ -102,24 +102,36 @@ impl ToolExecutor<ToolInvocation> for SleepHandler {
|
||||
.input_queue
|
||||
.subscribe_activity(turn_state.as_deref())
|
||||
.await;
|
||||
let interrupted = if pending_activity.is_some() {
|
||||
true
|
||||
let sleep_result: Result<bool, FunctionCallError> = if pending_activity.is_some() {
|
||||
Ok(true)
|
||||
} else {
|
||||
let sleep = tokio::time::sleep(Duration::from_millis(args.duration_ms));
|
||||
let sleep = session
|
||||
.services
|
||||
.time_provider
|
||||
.sleep(session.thread_id, Duration::from_millis(args.duration_ms));
|
||||
tokio::pin!(sleep);
|
||||
tokio::select! {
|
||||
() = &mut sleep => false,
|
||||
result = &mut sleep => result
|
||||
.map(|()| false)
|
||||
.map_err(|err| {
|
||||
FunctionCallError::Fatal(format!("failed to sleep: {err:#}"))
|
||||
}),
|
||||
result = activity_rx.changed() => {
|
||||
if result.is_ok() {
|
||||
true
|
||||
Ok(true)
|
||||
} else {
|
||||
sleep.await;
|
||||
false
|
||||
sleep
|
||||
.await
|
||||
.map(|()| false)
|
||||
.map_err(|err| {
|
||||
FunctionCallError::Fatal(format!("failed to sleep: {err:#}"))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
session.emit_turn_item_completed(turn.as_ref(), item).await;
|
||||
let interrupted = sleep_result?;
|
||||
|
||||
let message = if interrupted {
|
||||
"Sleep interrupted by new input."
|
||||
|
||||
Reference in new issue
Block a user