Skip to main content
The Extract-Replace Protocol defines how the orchestrator creates Working Set Envelopes from canonical score state (often exported as MRS-S for the Working Set) and how agent operations (MRS-Ops) are validated and applied. See: /MRS-Specification-RFC#7-working-set-envelope

Protocol Overview

Extraction (MRS-S → Working Set)

Extraction Parameters

Extraction Algorithm

Self-Containment

The extracted :content MUST be parseable as standalone MRS-S:
  • Instrument definitions included
  • Time/key/tempo state declared
  • Spans have both endpoints or boundary markers

Application (MRS-Ops → MRS-S)

Application Algorithm

Conflict Detection

The orchestrator uses source-hash for conflict detection:
If hashes don’t match, the canonical score changed since extraction → conflict.

Conflict Resolution Options

Progressive Validation

Operations are validated in stages:

Stage 1: Syntax

  • Operation type recognized
  • Required fields present
  • Field types correct

Stage 2: References

  • All UUIDs exist in source
  • All tmp-ids unique within envelope
  • Cross-references valid (e.g., span “from” references “e1” that exists)

Stage 3: Permissions

  • Operation type in :allowed-ops
  • Content within granted :bundle lanes
  • Scope within granted :scope

Stage 4: Musical Rules

  • Constraints satisfied (range, parallel fifths, etc.)
  • Duration sums correct
  • Ties connect same pitches

Derived Field Computation

The orchestrator computes derived fields:

:at (Absolute Beat Position)

For each event:
Agent never provides :at; orchestrator computes it.

:beat-start (Measure Start)

When measures are inserted:

Operation Ordering

Operations are applied in order. Dependencies must be respected:
  • Create measure before creating events in it
  • Create events before creating spans referencing them
The orchestrator MAY reorder to satisfy dependencies if unambiguous.

Partial Application

When some operations fail validation:
Policy options:
  • All-or-nothing: Reject entire batch on any failure
  • Partial: Apply valid ops, report failures
  • Interactive: Pause for human decision

Transaction Recording

Every successful application is recorded:
Transactions enable audit trail, rollback, and state reconstruction.