-
Notifications
You must be signed in to change notification settings - Fork 63
fix(broker): restore live agent roster after reconnect #1494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -347,22 +347,42 @@ impl BrokerRuntime { | |
| // the worker MCP never re-registers over HTTP. If node binding is | ||
| // unavailable, fall back to HTTP pre-registration so a tokenless | ||
| // node (e.g. mint failure) still spawns a working agent. | ||
| let mut fleet_registration = None; | ||
| let session_ref = super::fleet::fleet_initial_session_ref(&spec); | ||
| let worker_relay_key = if let Some(token) = agent_token { | ||
| seed_supplied_agent_token(relaycast_http, &name, &token); | ||
| match super::fleet::resolve_fleet_agent_token_identity( | ||
| relaycast_http, | ||
| fleet_delivery_book, | ||
| &name, | ||
| &token, | ||
| ) | ||
| .await | ||
| { | ||
| Ok(registration) => { | ||
| fleet_registration = Some((registration, None, session_ref.clone())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: A failed HTTP spawn can leave a dead worker's authoritative identity in Prompt for AI agents |
||
| } | ||
| Err(error) => { | ||
| tracing::warn!( | ||
| worker = %name, | ||
| error = %error, | ||
| "could not resolve supplied agent token for reconnect inventory" | ||
| ); | ||
| } | ||
| } | ||
| Some(token) | ||
| } else { | ||
| // Derive the session ref from the resolved spec the same way | ||
| // the fleet/sidecar paths do, so an HTTP spawn carrying a | ||
| // `harnessConfig.session_id` registers as a resumable session | ||
| // rather than a fresh spawn. No invocation id exists on the | ||
| // HTTP path. | ||
| let session_ref = super::fleet::fleet_initial_session_ref(&spec); | ||
| match super::fleet::register_node_agent_token( | ||
| fleet_control_tx, | ||
| fleet_delivery_book, | ||
| name.as_str(), | ||
| None, | ||
| session_ref, | ||
| session_ref.clone(), | ||
| ) | ||
| .await | ||
| { | ||
|
|
@@ -371,7 +391,9 @@ impl BrokerRuntime { | |
| worker = %name, | ||
| "bound agent to node via agent.register for HTTP spawn" | ||
| ); | ||
| Some(token.token) | ||
| let relay_key = token.token.clone(); | ||
| fleet_registration = Some((token, None, session_ref)); | ||
| Some(relay_key) | ||
| } | ||
| Err(node_error) => { | ||
| tracing::warn!( | ||
|
|
@@ -388,15 +410,35 @@ impl BrokerRuntime { | |
| // delivery. Bind it to this node so it is | ||
| // deliverable, surfacing a loud warning if the | ||
| // bind fails. | ||
| if let Some(warning) = | ||
| super::relaycast_events::bind_http_registered_agent_to_node( | ||
| let bind_warning = super::relaycast_events::bind_http_registered_agent_to_node( | ||
| relaycast_http, | ||
| fleet_node_name, | ||
| &name, | ||
| ) | ||
| .await; | ||
| if let Some(warning) = bind_warning { | ||
| preregistration_warning = Some(warning); | ||
| } else { | ||
| match super::fleet::resolve_fleet_agent_token_identity( | ||
| relaycast_http, | ||
| fleet_node_name, | ||
| fleet_delivery_book, | ||
| &name, | ||
| &token, | ||
| ) | ||
| .await | ||
| { | ||
| preregistration_warning = Some(warning); | ||
| { | ||
| Ok(registration) => { | ||
| fleet_registration = | ||
| Some((registration, None, session_ref.clone())); | ||
| } | ||
| Err(error) => { | ||
| tracing::warn!( | ||
| worker = %name, | ||
| error = %error, | ||
| "could not resolve HTTP-registered agent for reconnect inventory" | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| Some(token) | ||
| } | ||
|
|
@@ -578,6 +620,17 @@ impl BrokerRuntime { | |
| .await | ||
| { | ||
| Ok(effective_spec) => { | ||
| if let Some((token, invocation_id, session_ref)) = fleet_registration.take() | ||
| { | ||
| super::fleet::record_fleet_inventory_agent( | ||
|
Comment on lines
+623
to
+625
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a successful HTTP spawn uses the caller-supplied Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 6e4981b. Supplied and HTTP-fallback tokens are now resolved through the authenticated current-agent endpoint to recover the authoritative agent ID; the requested name must match before the identity enters delivery bookkeeping or reconnect inventory. Both HTTP and action.invoke spawn paths retain the resolved registration only after process launch succeeds. Added matching-identity and mismatched-name regression tests; full broker lib suite is green (915 passed, 4 ignored). |
||
| fleet_control_tx, | ||
| fleet_inventory, | ||
| &token, | ||
| invocation_id, | ||
| session_ref, | ||
| ) | ||
| .await; | ||
| } | ||
| // Prepend relay skill text for small-tier models and CLI harnesses that | ||
| // need explicit tool guidance to reliably call add_agent / remove_agent. | ||
| // Skip when relay prompt injection is opted out — relay tools are absent. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.