2.9 KiB
Message Pump — End-to-End Flow
The AgentServer message pump is a single, linear, attack-resistant pipeline. Every message — local or remote, request or response — follows exactly the same path.
flowchart TD
A[WebSocket Ingress<br>] --> B[TOTP + Auth Check]
B --> C[lxml Repair + Exclusive C14N]
C --> D["Envelope Grammar<br>"]
D --> E[Extract Payload XML fragment]
E --> F{Payload namespace?}
F -->|meta/v1| G["Core Meta Handler<br>(privileged, direct registry lookup)"]
F -->|user namespace| H[Route by namespace + root]
H --> I["Listener-specific Lark Grammar<br>(auto-generated from @xmlify class)"]
I --> J[Parse → clean dict]
J --> K["Call handler(payload_dict: dict) → bytes"]
K --> L[Wrap response payload in envelope]
G --> L
L --> M[Exclusive C14N + Sign]
M --> N["WebSocket Egress<br>(bytes)"]
Detailed Stages
-
Ingress: Raw bytes over WSS.
-
The Immune System: Every inbound packet is converted to a Tree.
-
Internal Routing: Trees flow between organs via the
dispatchmethod. -
The Thought Stream (Egress): Listeners return raw bytes. These are wrapped in a
<dummy/>tag and run through a recovery parser. -
Multi-Message Extraction: Every
<message/>found in the dummy tag is extracted as a Tree and re-injected into the Bus. -
Routing Decision
https://xml-platform.org/meta/v1→ Core Meta Handler (privileged, internal).
No user listener involved. Direct registry lookup forrequest-schema,request-example,request-prompt,list-capabilities.- Any other namespace → User Listener lookup by
(namespace, root_element).
-
Payload Validation & Conversion
Listener-specific Lark grammar (auto-generated from@xmlifypayload_class at registration).
One-pass, noise-tolerant parse → Transformer → guaranteed cleandict[str, Any]. -
Handler Execution
Pure callable:handler(payload_dict) -> bytes
Returns raw response payload XML fragment.
Synchronous by default (async supported). -
Response Envelope
Bus wraps handler bytes in standard response envelope. -
Egress Canonicalization
Same exclusive C14N + optional signing. -
WebSocket Out
Bytes to peer.
Safety Properties
- No entity expansion anywhere (lxml parsers hardened).
- Bounded depth/recursion by schema design + size limits.
- No XML trees escape the pump — only clean dicts reach handlers.
- Topology privacy — normal flows reveal no upstream schemas unless meta privilege granted.
- Zero tool-call convention — the payload is the structured invocation.
The pump is deliberately simple: one path, no branches except the privileged meta shortcut. Everything else is data-driven by live, auto-generated grammars.
XML in → XML out. Safely. Permanently.