Skip to content

ADR 008: The Engine Sits Behind MetaseedClient; ProfileFacade Is Built on the Client

Date: 261201 Status: Accepted (261201), amended 261201 (schema contract, order of work) Context: Issue #484; supersedes the layering of ADR 001, whose single source of truth for the entity graph it keeps

Decision

Three layers, each depending only on the one below it:

Layer Where What it is Who uses it
Engine metaseed.engine, class EntityGraph The entities of one dataset of one profile version: the store, the parent and reference links, tree and graph views, loading and writing documents. Today this is ProfileFacade and metaseed.facade.{store,linking,children,graph,documents,node}. MetaseedClient only
Client metaseed.api, class MetaseedClient The one way into the engine. Returns immutable results, raises only MetaseedError, reports validation as a ValidationResult. The local web UI, the MCP server, the CLI, the adapters, metaseed-hub, scripts
Conveniences metaseed.facade, class ProfileFacade Holds a MetaseedClient and adds what an interactive session wants: attribute helpers (m.Investigation.create(...), m.Investigation.help()), search, and the profile accessors (miappe(), isa(), ...). Notebooks and people at a prompt

ProfileFacade("miappe", "1.2") and the accessors keep working: they build a client and wrap it. ProfileFacade.client returns the client it wraps.

What the client gains

The hosts use about twenty engine members today (measured 261201 across the local UI, the MCP server, the CLI and metaseed-hub). Each becomes a client method with a documented contract, or a public function of metaseed.api, not a pass-through of the engine's signature:

Hosts need Client contract
profile, version, profile_spec, the entity type names (entities) client.profile, client.version, client.profile_spec, client.list_entity_types()
get_tree, get_roots, get_children Unchanged, and get_tree() returns the whole tree as immutable nodes in one call, so a host never reads a tree one entity at a time
to_dict, load_from_dict, load_nested, load client.to_document() and client.load_document(data, root=...), which report what they skipped as they do now
to_graph client.graph(), the nodes and edges a host draws
add_entity, update_entity, delete_entity, clear The existing create_entity, update_entity, delete_entity, clear
facade.linking.choose_parent_field, holds_exactly_one, facade.children.data_with_children Public functions of metaseed.api that take the profile, since they describe the profile, not a dataset
_instances, _spec, _loader, _root_entity (read by ui/state.py, agent/mcp/tools/datasets.py and the hub) Replaced by the public members above; nothing outside the engine reads them

Amendment: the schema the hosts read

Decided 261201, after step 1. The hosts depend on the engine most through EntityHelper, the per-type schema object, not through the members above: across metaseed's hosts, the adapters and metaseed-hub they read all_fields (25 uses), nested_fields (20), field_info (20), reference_fields (14), identifier_field (7), child_fields (7) and the private _spec (7). These become client contracts too:

Hosts need Client contract
helper.nested_fields, child_fields, reference_fields, identifier_field, all_fields, field_info client.get_entity_schema(type): EntitySchema gains nested_fields, child_fields and reference_fields as read-only mappings and identifier_field; its fields already carry what field_info returns
holds_exactly_one(helper, field) client.holds_exactly_one(entity_type, field), deciding by the one shape rule of ADR 005
choose_parent_field(helper, child_type, requested) client.choose_parent_field(parent_type, child_type, requested=None), raising ParentFieldError (a MetaseedError that is also a ValueError)
data_with_children(node, graph) client.get_entity_data(entity_id, with_children=True)
facade.load_nested(document, entity_type) client.load_nested(document, entity_type=None)
facade.to_graph() client.to_graph()
facade.profile_spec, helper._spec client.profile_spec, a copy, so a caller cannot change the profile the engine validates against
facade.to_dict(), load_from_dict() The existing client.serialize()["entities"] and client.load({"entities": ...})
helper.create(...) The existing client.create_entity(...)

EntityHelper stays an engine class; ProfileFacade wraps it for interactive use.

MetaseedClient.facade and MetaseedClient.from_facade are deprecated for one minor release and then removed; ProfileFacade(client) and facade.client replace them.

Context

ADR 001 made ProfileFacade the single source of truth for the entity graph, which ended linking logic duplicated between the UI and the dataset managers. It also made the facade the place everything reaches into. ProfileFacade and its modules are about 3,400 lines, and MetaseedClient (about 560 lines) mostly passes calls through to it. 63 modules use the facade directly (36 in metaseed's web UI, MCP server, CLI, repositories and services; 27 in metaseed-hub), and two of them read its private fields. The client's promises (immutable results, only MetaseedError) therefore hold for library callers and for nobody else.

The name says the opposite of what the class does: a facade is a thin front over a subsystem, and ProfileFacade is the subsystem. The thin front is MetaseedClient.

ADR 007 makes the adapters separate distributions; they already take a MetaseedClient. Once every host also goes through the client, the client is the one surface the plugin distributions and metaseed-hub depend on, and a test can hold that line.

Order of work

Each step keeps the suite green and is released only together with the last one, because the hub moves in the same release.

  1. Create metaseed.engine by moving the store, linking, children, graph, document and node modules and the engine part of ProfileFacade into EntityGraph. MetaseedClient builds on EntityGraph. (Done 261201; ProfileFacade subclasses EntityGraph until step 4.)
  2. Add the client contracts in the tables above, each with tests of its contract.
  3. Move the local web UI (AppState holds a client), the MCP server, the CLI, the repositories and the adapters to the client.
  4. Rebuild ProfileFacade on the client. Amended order: the hosts move first, because while they use ProfileFacade as the engine, rebuilding it first would break every one of them at once.
  5. Move metaseed-hub to the client, in a pull request released with this metaseed release.
  6. Turn on the gates.

Gates

  • An import-scanning test fails when a module outside metaseed.api and metaseed.engine imports metaseed.engine, at module level, in a function body or under TYPE_CHECKING. metaseed.facade is not exempt: it reaches the engine through the client.
  • An AST scan fails on any attribute access to a name starting with _ on a MetaseedClient, EntityGraph or ProfileFacade from outside their own modules. It runs over metaseed and over metaseed-hub, in each repository's suite.
  • A test fails when a public client method returns a mutable engine object (EntityNode, a store, a helper) rather than an Entity, EntityNode from metaseed.api, or plain data.
  • metaseed-hub's coupling test adds metaseed.engine and metaseed.facade to the imports only its boundary module may make.

Consequences

  • One place keeps the client's promises for every caller, and the plugin distributions and the hub depend on a surface with documented contracts.
  • metaseed.facade.store, .linking, .children, .graph, .documents and .node are submodule paths, which the API contract already calls not public; they move without a deprecation period. ProfileFacade, the accessors, MetaseedClient and EntityHelper behaviour stay.
  • Reads through the client copy into immutable objects. The tree and graph reads return everything in one call; the largest shipped example is timed before and after, and the change is reported in the pull request.
  • About 63 modules change, 27 of them in metaseed-hub; the hub change ships in the same release.

Considered Alternatives

Rename only

Rename ProfileFacade to what it is and leave the layering. Rejected because the defect is that every host reaches past the client, which a rename does not change.

Gate private access only

Keep the layering and add only the private-attribute scan. Rejected because the hosts would still depend on about twenty engine members with no documented contract, which is the surface the plugin distributions and the hub need to be stable.

Make MetaseedClient mutable and return engine objects

Avoids copying. Rejected because a caller could then change engine state without validation, the defect immutable results exist to prevent.