Message pipeline
The verified message pipeline. Mirrors lean-cbcl/LeanCbcl/Pipeline.lean. Input strings (from stdin, the CLI, a WASM/FFI/NIF wrapper, or an arena agent) traverse a fixed sequence of steps: parse → parse_message → validate → expand → causal verify → shape check → success. Success yields a ValidMessageGrammar witness; any step failure produces a ValidationError carrying a blame attribution.
graph LR
input["Input String\n(stdin / argv / NIF / FFI)"]
parse-step["Step 1 Parse\ncrates/cbcl-parser/src/parser.rs"]
parse-message-step["Step 2 Parse Message\ncrates/cbcl-parser/src/message_parser.rs"]
validate-step["Step 3 Validate\ncrates/cbcl-core/src/r1.rs r3.rs"]
expand-step["Step 4 Expand\ncrates/cbcl-core/src/template.rs"]
causal-step["Step 6a Causal Verify\ncrates/cbcl-core/src/protocol.rs"]
shape-step["Step 6b Shape Check\ncrates/cbcl-core/src/r5.rs shape.rs"]
success["Success: ValidMessageGrammar\ncrates/cbcl-parser/src/pipeline.rs"]
failure["ValidationError + Blame\ncrates/cbcl-core/src/blame.rs"]
input --> parse-step
parse-step -->|"S-expr"| parse-message-step
parse-message-step -->|"Message"| validate-step
validate-step -->|"R1/R2/R3 OK"| expand-step
expand-step -->|"expanded Message"| causal-step
causal-step -->|"causally OK"| shape-step
shape-step -->|"shape OK"| success
parse-step -->|"ParseError"| failure
parse-message-step -->|"MalformedMessage"| failure
validate-step -->|"R1/R2/R3 violation"| failure
expand-step -->|"R2FuelExhausted"| failure
causal-step -->|"CausalViolation"| failure
shape-step -->|"ShapeViolation"| failure
Steps
Step 1 — Parse (crates/cbcl-parser/src/parser.rs). Tokenize and parse an S-expression. Hand-rolled recursive-descent (ADR-001), O(n), fuel-bounded. ParseError on malformed input. Equivalent to the DPDA decision (det_parser.rs ↔ DetParser.lean: agentDetParser_agrees).
Step 2 — Parse message (crates/cbcl-parser/src/message_parser.rs + cbcl-core/message.rs). Lift S-expression into a typed Message. MalformedMessage on grammar violation. MessageParser.lean proves grammar soundness AND completeness (ValidMessageGrammar ↔ parseMessage).
Step 3 — Validate (r1.rs, r3.rs, plus the syntactic part of r2.rs). Validate dialect-related safety constraints. Errors: R1RecursivePerformative, R2ResourceBoundsInvalid, R3CoreOverride. R1 detection via DFS — proven sound and complete in Lean.
Step 4 — Expand (template.rs, evaluator.rs). Expand template substitutions under R2 fuel. R2FuelExhausted if a substitution exceeds the dialect’s declared depth/expansion bounds. TemplateExpansion.lean proves expansion terminates within declared bounds.
Step 6a — Causal verify (protocol.rs). For dialects with a (protocol ...) clause, verify_causal checks that incoming messages are well-ordered against the agent’s MessageStore. Failure: CausalViolation { violation, blame }.
Step 6b — Shape check (r5.rs, shape.rs). Final check before success. Failure: ShapeViolation { violation, blame }. R5 covers REQ-208 + REQ-222.
Fail-closed guarantee
REQ-231: fail-closed, no bypass, no partial checks. The pipeline cannot return success unless every step succeeded — there is no path that elides causal verification or shape checking once dialect-installed.
run_pipeline— light path: parse + validate, no runtime context. Used in test harnesses and FFI parse-only paths.run_pipeline_full— full path, takes aDialectRegistryandMessageStore.
Lean: pipeline_success_grammar proves success ⟹ ValidMessageGrammar.
See also
- CBCL — architecture overview
- Overall architecture
- Extension points — dialect installation, where R1/R2/R3 are first enforced.