fix(#2290): register_agent in handle_spawn (event-driven, replaces stale spawn_poll comment)
This commit is contained in:
parent
73f1020a7e
commit
66c6828359
1 changed files with 9 additions and 4 deletions
|
|
@ -205,14 +205,18 @@ async fn handle_spawn(coord: &Arc<Coordinator>, name: &str) -> Result<HostRespon
|
|||
let agent_dir = Coordinator::agent_dir(name);
|
||||
let hive = coord.hive_env();
|
||||
let paths = Coordinator::agent_paths(name, agent_dir);
|
||||
// lifecycle::spawn creates the runtime dir internally before start, so
|
||||
// no manual ensure_agent_runtime_dir here. MCP listener registration is
|
||||
// handled by mcp_sockets::spawn_poll on its first post-start tick.
|
||||
// lifecycle::spawn creates the runtime dir internally before start.
|
||||
// MCP listener registration is event-driven: bind immediately on
|
||||
// success so the harness can connect on its first turn without
|
||||
// waiting for any poll interval.
|
||||
match lifecycle::spawn(name, &hive, &paths).await {
|
||||
Ok(()) => {
|
||||
if let Err(e) = coord.power.set(name, crate::power::Wanted::Up) {
|
||||
tracing::warn!(%name, error = ?e, "agent_power: set wanted=up failed");
|
||||
}
|
||||
// Bind the MCP listener now that the container is starting up.
|
||||
// The harness connects to this socket on its first turn.
|
||||
coord.register_agent(name)?;
|
||||
coord.notify_manager(&hive_sh4re::HelperEvent::Spawned {
|
||||
agent: name.to_owned(),
|
||||
ok: true,
|
||||
|
|
@ -223,7 +227,8 @@ async fn handle_spawn(coord: &Arc<Coordinator>, name: &str) -> Result<HostRespon
|
|||
tokio::spawn(lifecycle::sync_tmpfiles());
|
||||
}
|
||||
Err(e) => {
|
||||
coord.unregister_agent(name);
|
||||
// Spawn failed: register_agent was never called, so there is
|
||||
// nothing to unregister. Notify the manager and propagate.
|
||||
coord.notify_manager(&hive_sh4re::HelperEvent::Spawned {
|
||||
agent: name.to_owned(),
|
||||
ok: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue