mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Add configurable idle heartbeats to Code Mode gRPC streams (#61385)
## What changed - Add `code_mode.heartbeat_interval_s` to configure heartbeats after inactivity on session-event and tool-call streams. The default value of `0` disables heartbeats. - Pass the interval through session options and gRPC requests, preserving provider defaults when overriding it. - Ignore heartbeat messages in the client without admitting tool callbacks, and reject tool-call heartbeats that carry invocation data. ## Testing Add coverage for disabled heartbeats, repeated idle heartbeats and timer resets after traffic, callback handling, and configuration loading. Extend TCP integration tests to verify heartbeats on both streams and continued session operation after idle periods. GitOrigin-RevId: bf0b6d3081b5541837d07f35931e0dd3e5472c3b
This commit is contained in:
@@ -17,6 +17,7 @@ use codex_code_mode::CellId;
|
||||
use codex_code_mode::CodeModeNestedToolCall;
|
||||
use codex_code_mode::CodeModeOutputTruncation;
|
||||
use codex_code_mode::CodeModeSession;
|
||||
use codex_code_mode::CodeModeSessionOptions;
|
||||
use codex_code_mode::CodeModeSessionProvider;
|
||||
use codex_code_mode::CodeModeToolKind;
|
||||
use codex_code_mode::RuntimeResponse;
|
||||
@@ -79,6 +80,7 @@ pub(crate) struct CodeModeService {
|
||||
availability: Result<(), String>,
|
||||
dispatch_broker: Arc<CodeModeDispatchBroker>,
|
||||
default_exec_yield_time_ms: u64,
|
||||
heartbeat_interval_s: u32,
|
||||
shutdown_token: CancellationToken,
|
||||
unavailable_warning_emitted: AtomicBool,
|
||||
}
|
||||
@@ -98,6 +100,7 @@ impl CodeModeService {
|
||||
availability,
|
||||
dispatch_broker,
|
||||
default_exec_yield_time_ms: config.default_exec_yield_time_ms,
|
||||
heartbeat_interval_s: config.heartbeat_interval_s,
|
||||
shutdown_token: CancellationToken::new(),
|
||||
unavailable_warning_emitted: AtomicBool::new(false),
|
||||
}
|
||||
@@ -252,9 +255,16 @@ impl CodeModeService {
|
||||
_ = self.shutdown_token.cancelled() => {
|
||||
return Err("code mode session is shutting down".to_string());
|
||||
}
|
||||
session = self
|
||||
.session_provider
|
||||
.create_session() => session?,
|
||||
session = async {
|
||||
if self.heartbeat_interval_s == 0 {
|
||||
self.session_provider.create_session().await
|
||||
} else {
|
||||
self.session_provider.create_session_with_options(CodeModeSessionOptions {
|
||||
heartbeat_interval_s: self.heartbeat_interval_s,
|
||||
..self.session_provider.default_session_options()
|
||||
}).await
|
||||
}
|
||||
} => session?,
|
||||
};
|
||||
if self.shutdown_token.is_cancelled() {
|
||||
let _ = session.shutdown().await;
|
||||
|
||||
Reference in New Issue
Block a user