fix(maestro): tolerate unknown WS frame types instead of dropping the connection (NAP-269)
ci / rust (push) Successful in 14m9s
ci / rust (push) Successful in 14m9s
`dispatch_text` (registry) and `handle_inbound` (daemon) treated any frame that didn't deserialize into a known `DaemonOutbound`/`DaemonInbound` variant as fatal: the registry returned `false` (breaking the handler loop and deregistering the daemon, wiping its catalog), and the daemon propagated the serde error out of the read loop. A newer peer emitting a not-yet-merged variant would therefore get stuck in a tight disconnect/reconnect loop. - Add a `#[serde(other)] Unknown` catch-all to both enums so unknown `type` tags decode instead of erroring. - Log-and-skip the `Unknown` variant on both sides. - Also log-and-skip genuinely malformed frames rather than tearing down the connection, so one bad frame can't wipe a daemon's catalog. Tested: unknown/malformed frames keep the connection alive (registry handler), and unknown `type` decodes to `Unknown` (protocol round-trip). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -167,8 +167,10 @@ async fn dispatch_text(
|
||||
let parsed: DaemonOutbound = match serde_json::from_str(text) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
tracing::warn!(%daemon_id, error = %e, "malformed message");
|
||||
return false;
|
||||
// A single malformed frame must not tear down the WS (and wipe this
|
||||
// daemon's catalog) — log and skip it (NAP-269).
|
||||
tracing::warn!(%daemon_id, error = %e, "malformed message — skipping");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
match parsed {
|
||||
@@ -217,6 +219,11 @@ async fn dispatch_text(
|
||||
// don't crash the connection; the registry doesn't act on it yet.
|
||||
tracing::debug!(%daemon_id, ?reply_to, "RelayAck received but T3 not implemented (NAP-238 pending)");
|
||||
}
|
||||
DaemonOutbound::Unknown => {
|
||||
// A newer daemon emitted a frame type this build doesn't know. Skip
|
||||
// it rather than dropping the connection (NAP-269).
|
||||
tracing::debug!(%daemon_id, "unknown frame type — skipping (forward-compat, NAP-269)");
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -233,3 +240,32 @@ async fn send_error(
|
||||
let text = serde_json::to_string(&err).expect("serialize error");
|
||||
sink.send(Message::Text(text)).await
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// `dispatch_text` returning `false` is what breaks the handler loop and
|
||||
// triggers a deregister (catalog wipe). A frame the registry can't act on
|
||||
// must NOT do that, or a newer daemon emitting an unknown variant gets
|
||||
// stuck in a tight reconnect loop (NAP-269).
|
||||
|
||||
#[tokio::test]
|
||||
async fn unknown_frame_keeps_connection_alive() {
|
||||
let registry = Registry::new();
|
||||
let frame = serde_json::json!({ "type": "FutureVariant", "x": 1 }).to_string();
|
||||
assert!(
|
||||
dispatch_text(®istry, "laptop", "tok", &frame).await,
|
||||
"unknown frame type must be skipped, not drop the WS"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn malformed_frame_keeps_connection_alive() {
|
||||
let registry = Registry::new();
|
||||
assert!(
|
||||
dispatch_text(®istry, "laptop", "tok", "{ not valid json").await,
|
||||
"malformed frame must be skipped, not drop the WS"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user