Skip to content

Format the code#2

Merged
ajit-zer07 merged 1 commit intomainfrom
multi-round-mode
Mar 6, 2026
Merged

Format the code#2
ajit-zer07 merged 1 commit intomainfrom
multi-round-mode

Conversation

@ajit-zer07
Copy link
Contributor


PR Description

Title: Sync runtime with upstream RFC spec — full proto realignment, new RPCs, and decision mode rewrite


Summary

Brings the MACP runtime into exact compliance with the upstream RFC specification. This is a comprehensive update spanning proto schema restructuring, error code
alignment, new RPC implementations, and a complete decision mode rewrite.

  • Replaced single macp.proto with canonical 3-file split structure (envelope.proto, core.proto, decision.proto)
  • Implemented 5 new RPCs: Initialize, ListModes, GetManifest, ListRoots, StreamSession
  • Rewrote decision mode from toy (payload == "resolve") to full RFC lifecycle (Proposal → Evaluation → Objection → Vote → Commitment)
  • Aligned all error codes with the spec's error registry
  • Updated all client binaries to exercise new RPCs and message types
  • 122 tests passing (92 lib + 30 server), clean clippy, clean fmt

Details

Phase 1: Proto Schema Realignment

  • Deleted proto/macp.proto (single-file layout)
  • Added proto/macp/v1/envelope.proto — Envelope, Ack, MACPError (with bytes details), SessionState
  • Added proto/macp/v1/core.proto — MACPRuntimeService with 10 RPCs, all wrapper request/response types, SessionStartPayload (8 fields), SessionMetadata,
    capability messages (ClientInfo, RuntimeInfo, Capabilities), AgentManifest, ModeDescriptor
  • Added proto/macp/modes/decision/v1/decision.proto — ProposalPayload, EvaluationPayload, ObjectionPayload, VotePayload
  • Updated build.rs to compile all three protos
  • Updated src/lib.rs with pb and decision_pb modules

Phase 2: Server + Runtime Adaptation

  • Renamed service impl from MacpService → MacpRuntimeService
  • send_message(Envelope) → Ack → send(SendRequest) → SendResponse
  • get_session(SessionQuery) → SessionMetadata → get_session(GetSessionRequest) → GetSessionResponse
  • cancel_session returns CancelSessionResponse wrapping Ack
  • SessionMetadata: removed resolution, mode_state, participants; added mode_version, configuration_version, policy_version
  • MACPError.details: changed from map<string,string> to bytes
  • SessionStartPayload: now 8 fields (intent, participants, mode_version, configuration_version, policy_version, ttl_ms, context, roots)
  • Session struct extended with intent, mode_version, configuration_version, policy_version

Phase 3: Error Code Alignment

Aligned MacpError variants with the spec's registries/error-codes.md:

┌────────────────────────┬──────────────────────────────┐
│ Variant │ Wire Code │
├────────────────────────┼──────────────────────────────┤
│ InvalidMacpVersion │ UNSUPPORTED_PROTOCOL_VERSION │
├────────────────────────┼──────────────────────────────┤
│ InvalidEnvelope │ INVALID_ENVELOPE │
├────────────────────────┼──────────────────────────────┤
│ DuplicateSession │ INVALID_ENVELOPE │
├────────────────────────┼──────────────────────────────┤
│ UnknownSession │ SESSION_NOT_FOUND │
├────────────────────────┼──────────────────────────────┤
│ SessionNotOpen │ SESSION_NOT_OPEN │
├────────────────────────┼──────────────────────────────┤
│ TtlExpired │ SESSION_NOT_OPEN │
├────────────────────────┼──────────────────────────────┤
│ InvalidTtl │ INVALID_ENVELOPE │
├────────────────────────┼──────────────────────────────┤
│ UnknownMode │ MODE_NOT_SUPPORTED │
├────────────────────────┼──────────────────────────────┤
│ InvalidModeState │ INVALID_ENVELOPE │
├────────────────────────┼──────────────────────────────┤
│ InvalidPayload │ INVALID_ENVELOPE │
├────────────────────────┼──────────────────────────────┤
│ Forbidden │ FORBIDDEN │
├────────────────────────┼──────────────────────────────┤
│ Unauthenticated (new) │ UNAUTHENTICATED │
├────────────────────────┼──────────────────────────────┤
│ DuplicateMessage (new) │ DUPLICATE_MESSAGE │
├────────────────────────┼──────────────────────────────┤
│ PayloadTooLarge (new) │ PAYLOAD_TOO_LARGE │
├────────────────────────┼──────────────────────────────┤
│ RateLimited (new) │ RATE_LIMITED │
└────────────────────────┴──────────────────────────────┘

Phase 4: Initialize RPC

  • Protocol version negotiation: intersects client's supported versions with ["1.0"]
  • Returns RuntimeInfo, Capabilities (sessions, cancellation, mode_registry, etc.), and supported modes
  • Rejects unsupported versions with UNSUPPORTED_PROTOCOL_VERSION

Phase 5: Discovery RPCs

  • ListModes — returns mode descriptors for decision and multi_round with metadata (determinism class, participant model, message types)
  • GetManifest — returns runtime's AgentManifest with supported modes and content types
  • ListRoots — returns empty root list
  • WatchModeRegistry / WatchRoots — return UNIMPLEMENTED (streaming watchers deferred)

Phase 6: Decision Mode Rewrite

Full RFC-compliant lifecycle replacing the toy implementation:

  • State machine: Proposal → Evaluation/Objection → Vote → Commitment
  • Typed payloads: ProposalPayload, EvaluationPayload, ObjectionPayload, VotePayload, CommitmentPayload
  • Validation: proposal_id references checked, phase ordering enforced, vote deduplication (last vote wins per sender)
  • Terminal: Commitment message resolves the session
  • Backward compat: Legacy payload == b"resolve" on Message type still works

Phase 7: StreamSession

  • Bidirectional streaming using async-stream crate
  • Processes each inbound StreamSessionRequest envelope through runtime.process()
  • Returns accepted envelopes and error responses on the stream

Phase 8: Client Binaries

  • client.rs — Full decision lifecycle demo: Initialize → ListModes → SessionStart → Proposal → Evaluation → Vote → Commitment → GetSession
  • fuzz_client.rs — Comprehensive error path testing: Initialize (good + bad version), all error codes, new RPCs (ListModes, GetManifest, ListRoots), multi-round
    convergence, CancelSession, participant validation
  • multi_round_client.rs — Updated for new wrapper types and SessionStartPayload fields

Stats

  • 24 files changed, +3,772 / -390 lines
  • 122 tests passing (92 lib + 30 server)
  • 0 clippy warnings

Test plan

  • cargo build — compiles cleanly with split proto structure
  • cargo test — all 122 tests pass
  • cargo clippy — no warnings
  • cargo run — server starts as MACPRuntimeService on 127.0.0.1:50051
  • cargo run --bin client — full decision mode lifecycle demo
  • cargo run --bin multi_round_client — multi-round convergence demo
  • cargo run --bin fuzz_client — all error paths with spec-compliant codes
  • Verify error codes match registries/error-codes.md exactly
  • Verify proto messages match canonical spec protos verbatim

@ajit-zer07 ajit-zer07 merged commit e601db7 into main Mar 6, 2026
6 of 7 checks passed
@ajit-zer07 ajit-zer07 deleted the multi-round-mode branch March 17, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant