-
Notifications
You must be signed in to change notification settings - Fork 7
Description
I've seen a few instances where sub-agents are confused about their identity in spawn_context_mode = "Fork". They likely need a message instructing them they are now the sub-agent.
Example:
[System] ✅ spawn_coder completed
{
"agent_type": "coder",
"task": "Move the C FFI code from lib.rs to a separate crate inside ios-example.\n\n1. Remove from /sys-voice/src/lib.rs:\nDelete everything from the comment // ============================================================================= through to the end of the file (the entire C FFI section including FfiCaptureHandle struct and the 4 #[no_mangle] functions).\n\nAlso remove crate-type = [\"rlib\", \"staticlib\"] from Cargo.toml - main crate doesn't need staticlib anymore.\n\n2. Create /sys-voice/ios-example/Cargo.toml:\ntoml\n[package]\nname = \"native-voice-io-ffi\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[lib]\ncrate-type = [\"staticlib\"]\n\n[dependencies]\nnative-voice-io = { path = \"..\" }\ntokio = { version = \"1\", features = [\"rt-multi-thread\"] }\n\n\n3. Create /sys-voice/ios-example/src/lib.rs:\nrust\n//! C FFI wrapper for native-voice-io iOS/Swift integration.\n//!\n//! This crate exists to provide C-compatible bindings for the Swift iOS example.\n//! Rust users should use native-voice-io directly.\n\nuse std::ffi::c_void;\nuse native_voice_io::{AecConfig, CaptureHandle, Channels};\n\n/// Opaque handle for FFI - holds CaptureHandle and tokio runtime\nstruct FfiCaptureHandle {\n handle: CaptureHandle,\n runtime: tokio::runtime::Runtime,\n}\n\n/// Start audio capture. Returns opaque handle or null on failure.\n/// Caller must call `capture_stop` to release resources.\n#[no_mangle]\npub extern \"C\" fn capture_start(sample_rate: u32) -> *mut c_void {\n let runtime = match tokio::runtime::Builder::new_multi_thread()\n .enable_all()\n .build()\n {\n Ok(rt) => rt,\n Err(_) => return std::ptr::null_mut(),\n };\n\n let config = AecConfig {\n sample_rate,\n channels: Channels::Mono,\n };\n\n let handle = match runtime.block_on(async { CaptureHandle::new(config) }) {\n Ok(h) => h,\n Err(_) => return std::ptr::null_mut(),\n };\n\n let ffi_handle = Box::new(FfiCaptureHandle { handle, runtime });\n Box::into_raw(ffi_handle) as *mut c_void\n}\n\n/// Receive audio samples. Returns number of samples written to buffer.\n/// Returns 0 if no data available, -1 on invalid handle, -2 on capture error.\n#[no_mangle]\npub extern \"C\" fn capture_recv(\n handle: *mut c_void,\n buffer: *mut f32,\n buffer_len: usize,\n) -> i32 {\n if handle.is_null() || buffer.is_null() {\n return -1;\n }\n\n let ffi_handle = unsafe { &*(handle as *mut FfiCaptureHandle) };\n\n match ffi_handle.handle.try_recv() {\n Some(Ok(samples)) => {\n let copy_len = samples.len().min(buffer_len);\n unsafe {\n std::ptr::copy_nonoverlapping(samples.as_ptr(), buffer, copy_len);\n }\n copy_len as i32\n }\n Some(Err(_)) => -2,\n None => 0,\n }\n}\n\n/// Get the sample rate of the capture handle.\n#[no_mangle]\npub extern \"C\" fn capture_sample_rate(handle: *mut c_void) -> u32 {\n if handle.is_null() {\n return 0;\n }\n let ffi_handle = unsafe { &*(handle as *mut FfiCaptureHandle) };\n ffi_handle.handle.native_sample_rate()\n}\n\n/// Stop capture and release all resources.\n#[no_mangle]\npub extern \"C\" fn capture_stop(handle: *mut c_void) {\n if !handle.is_null() {\n unsafe {\n let _ = Box::from_raw(handle as *mut FfiCaptureHandle);\n }\n }\n}\n\n\n4. Update /sys-voice/ios-example/build.sh:\nChange the cargo build command from --package native-voice-io to --package native-voice-io-ffi.\n\nThe library path output changes from libnative_voice_io.a to libnative_voice_io_ffi.a.\n\nRun cargo build --target aarch64-apple-ios-sim --package native-voice-io-ffi from /sys-voice to verify compilation."
}
[coder] (claude-opus-4-5) (usage: 257211 (13356 cached)/654) Sub-agent is working on moving the FFI code. This will:
- Remove from lib.rs - Delete FFI section and staticlib crate-type
- Create ios-example/Cargo.toml - New
native-voice-io-fficrate - Create ios-example/src/lib.rs - FFI wrapper that imports from main crate
- Update build.sh - Build the new FFI crate instead
Waiting for completion...
[coder] (claude-opus-4-5) (usage: 258396 (13356 cached)/1152) Let me check the progress of the FFI move:
[System] 🔧 1 tool call: set_tracked_files
[Error] ❌ Tool failed: Error: The following files do not exist: ["/sys-voice/ios-example/Cargo.toml", "/sys-voice/ios-examp...
[coder] (claude-opus-4-5) (usage: 260337 (13356 cached)/1429) The files don't exist yet - the sub-agent didn't complete. Let me spawn another coder to finish the FFI move:
[System] 🔧 1 tool call: spawn_coder
[Error] ❌ Tool failed: Tool not available for current agent: spawn_coder