From 1768989d38a70eff6ca1ceef811241eac5ad4ff3 Mon Sep 17 00:00:00 2001 From: kdletters Date: Wed, 26 Aug 2026 17:42:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=80=E5=8F=91=E6=80=81?= =?UTF-8?q?=20AGC=20=E5=B7=A5=E5=85=B7=E8=BF=9B=E7=A8=8B=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免 Cargo 热重载后 current_exe 路径指向已删除旧二进制 Linux 开发态通过当前客户端进程的稳定 executable 引用启动 agc_tools 补充 DirectProject MCP 可执行路径回归测试 --- .../src-tauri/src/agent/codex_app_server.rs | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/codex_app_server.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/codex_app_server.rs index 18a483969..1ba2bb9d1 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/codex_app_server.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/codex_app_server.rs @@ -1061,6 +1061,31 @@ fn quoted_toml_string(value: &str) -> Result { }) } +fn direct_tools_mcp_executable_path() -> Result { + // In Linux development mode Cargo may replace/unlink the running binary + // while Tauri's app-server pool is still alive. A child launched from the + // old `current_exe()` pathname then fails with ENOENT. `/proc//exe` + // keeps referring to this process' executable inode until this AGC process + // exits, so the MCP child remains launchable across hot rebuilds. + #[cfg(target_os = "linux")] + { + let proc_executable = std::path::PathBuf::from(format!("/proc/{}/exe", std::process::id())); + if proc_executable.exists() { + return Ok(proc_executable); + } + } + + let current_executable = std::env::current_exe().map_err(|error| { + platform_llm::LlmError::InvalidConfig(format!("定位 AGC 受控工具进程失败:{error}")) + })?; + if !current_executable.is_file() { + return Err(platform_llm::LlmError::InvalidConfig( + "定位 AGC 受控工具进程失败:当前客户端可执行文件已不存在".to_string(), + )); + } + Ok(current_executable) +} + fn configure_game_creator_codex_app_server_command( command: &mut tokio::process::Command, llm: &GameCreatorLlmConfig, @@ -1095,9 +1120,7 @@ fn configure_game_creator_codex_app_server_command_for_mode( command.arg("-c").arg("agents.enabled=false"); } if workspace_mode == CodexAppServerWorkspaceMode::DirectProject { - let current_executable = std::env::current_exe().map_err(|error| { - platform_llm::LlmError::InvalidConfig(format!("定位 AGC 受控工具进程失败:{error}")) - })?; + let current_executable = direct_tools_mcp_executable_path()?; command .arg("-c") .arg(format!( @@ -3592,6 +3615,15 @@ mod tests { assert!(game_creator_codex_app_server_validate_llm_config(&llm).is_ok()); } + #[cfg(target_os = "linux")] + #[test] + fn direct_tools_mcp_uses_a_stable_parent_executable_reference() { + assert_eq!( + direct_tools_mcp_executable_path().expect("resolve AGC MCP executable"), + std::path::PathBuf::from(format!("/proc/{}/exe", std::process::id())) + ); + } + #[test] fn direct_project_command_configures_the_reviewed_agc_tools_bridge() { let mut command = tokio::process::Command::new("fixture");