mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add the voice helper lifecycle foundation (#41897)
## What changed - Add `codex-realtime-webrtc` with a length-prefixed, 256-byte JSON control protocol for `hello`, `ready`, `close`, and `closed` messages. - Add a hardened `codex-voice-host` binary that validates protocol and build compatibility, handles orderly shutdown and parent pipe loss, and exposes its build commit. - Keep this initial foundation limited to process lifecycle management; it does not open audio devices, load native plugins, negotiate WebRTC, or enable voice in the TUI. ## Testing - Exercise the helper as a subprocess, covering handshake, explicit close, parent pipe loss, malformed frames, incompatible builds, and invalid message order. GitOrigin-RevId: 6d8d7dd7ba5c4886879882d79314d235f6ab7cf4
This commit is contained in:
1 parent
65237aeca0
commit
d60560f14e
11 files changed
+358
No files matched your search
@@ -0,0 +1,75 @@
|
||||
//! Private helper lifecycle foundation. No devices, native plugins, or media are opened yet.
|
||||
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::sync::mpsc;
|
||||
use std::time::Duration;
|
||||
|
||||
use codex_realtime_webrtc::Message;
|
||||
use codex_realtime_webrtc::encode_frame;
|
||||
use codex_realtime_webrtc::read_message;
|
||||
|
||||
const BUILD_COMMIT: &str = match option_env!("STABLE_GIT_COMMIT") {
|
||||
Some(commit) => commit,
|
||||
None => "dev",
|
||||
};
|
||||
|
||||
fn main() {
|
||||
codex_process_hardening::pre_main_hardening();
|
||||
let mut args = std::env::args_os().skip(/*n*/ 1);
|
||||
match (args.next(), args.next()) {
|
||||
(Some(arg), None) if arg == "--build-commit" => println!("{BUILD_COMMIT}"),
|
||||
(None, None) => {
|
||||
if run().is_err() {
|
||||
std::process::exit(/*code*/ 1);
|
||||
}
|
||||
}
|
||||
_ => std::process::exit(/*code*/ 2),
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> io::Result<()> {
|
||||
let (sender, receiver) = mpsc::sync_channel(/*bound*/ 1);
|
||||
std::thread::Builder::new()
|
||||
.name("voice-control".into())
|
||||
.spawn(move || {
|
||||
let mut input = io::stdin().lock();
|
||||
loop {
|
||||
match read_message(&mut input) {
|
||||
Ok(Some(message)) => {
|
||||
if sender.try_send(message).is_err() {
|
||||
std::process::exit(/*code*/ 1);
|
||||
}
|
||||
}
|
||||
Ok(None) => break,
|
||||
Err(_) => std::process::exit(/*code*/ 1),
|
||||
}
|
||||
}
|
||||
drop(sender);
|
||||
// Independent of the main worker or a blocked stdout write, including after parent death.
|
||||
std::thread::sleep(Duration::from_secs(/*secs*/ 2));
|
||||
std::process::exit(/*code*/ 1);
|
||||
})?;
|
||||
let Ok(hello) = receiver.recv() else {
|
||||
return Ok(());
|
||||
};
|
||||
if hello
|
||||
!= (Message::Hello {
|
||||
protocol: 1,
|
||||
build_commit: BUILD_COMMIT.to_owned(),
|
||||
})
|
||||
{
|
||||
return Err(io::Error::other("incompatible voice helper"));
|
||||
}
|
||||
let mut output = io::stdout().lock();
|
||||
output.write_all(&encode_frame(&Message::Ready {})?)?;
|
||||
output.flush()?;
|
||||
match receiver.recv() {
|
||||
Ok(Message::Close {}) => {
|
||||
output.write_all(&encode_frame(&Message::Closed {})?)?;
|
||||
output.flush()
|
||||
}
|
||||
Err(_) => Ok(()),
|
||||
Ok(_) => Err(io::Error::other("invalid voice control sequence")),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user