Skip to content

feat: add provider-aware model aliases and delegation selectors - #2019

Merged
jbeda merged 25 commits into
mainfrom
plan/delegation-provider-model-selectors-amendment
Oct 8, 2026
Merged

jbeda merged 25 commits into
mainfrom
plan/delegation-provider-model-selectors-amendment

Conversation

@jbeda

@jbeda jbeda commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add operator-owned provider/model aliases and bindings, provider-aware delegation selectors for Subagent, Parallel, and Team, router-category discovery/selection, and accurate child model provenance. Mecatui now distinguishes the resolved provider/model identity (ProviderLabel) from the inventory's friendly name (FriendlyName; customization protocol v5).

The contract amendment originated in #1971 and was folded into this implementation PR. Current architecture and user documentation live in docs/architecture/providers.md and user-docs/; the retired acceptance/ADR files are not restored.

Behavior

  • Operator settings or flags own models:. Project-tier model settings are ignored regardless of project trust; the legacy operator models.allowlist is parsed for compatibility but has no effect and warns.
  • Scalar aliases bind to a configured default provider when one exists; provider-aware aliases carry an atomic pair. --model-alias-provider pairs a CLI alias with its provider without parsing delimiters out of opaque model IDs.
  • Subagent, Parallel, and Team can select exact provider/model pairs or discovered model-router categories. Explicit selections fail when unavailable; automatic routes fall back. Parallel uses one selector per call; Team validates the roster before adding members. Named specialist scope is preserved.
  • Plan-mode sessions remain on their persisted provider, falling back to their ordinary provider/model when a plan alias names another provider. Subagent resume remints on the child's actual persisted pair.
  • Parallel and Team child sessions persist the actual engine model/provider (including routed fallback), not an unavailable requested target. A bare model or contextual scalar alias for an undefined Team member uses the parent provider even if the global child default names another provider, including no-FS teams.
  • DiscoverModels lists selectable provider/model handles and enabled virtual router categories without disclosing category targets. Jev classification sends eligible task text and category descriptions to Typesafe when configured; the LLM backend remains the default.

Verification

After the latest code change, task lint, task test, task test:race, focused ordinary/no-FS Team contextual-selector tests, git diff --check, and the offline go run ./cmd/mecademo passed. Earlier on this rebased series, task generate, task docs, and task api:check passed; the latest change touches only Go composition and tests. CI re-runs on the pushed head. No live-provider e2e was run locally.

The AI-generated review findings and the disposition of non-blocking suggestions are summarized in a separate PR comment. Humans alone decide when to merge.

Relates to #1971

@jbeda jbeda changed the title docs: amend #1971 for provider-aware model aliases feat: add provider-aware model aliases and delegation selectors Sep 30, 2026
@jbeda
jbeda marked this pull request as draft September 30, 2026 19:11
@jbeda
jbeda marked this pull request as ready for review October 1, 2026 09:43
@kantord

kantord commented Oct 2, 2026

Copy link
Copy Markdown
Member

AI-driven review (not a human review)

This comment is purely an AI-driven source and test-surface review. It was produced by automated subagents and has not been independently validated by a human reviewer.

Reviewed PR #2019 (e4c4e325311bc7ffc7fa007b9d7e1c35ab734912) against its GitHub base commit ce948582151971c7128fef13d29c90078ddd9f1c (main). The reviewed patch exactly matches the local main...HEAD patch.

Summary

  • Spec axis: 1 important finding
  • Standards axis: 1 important finding
  • Test adequacy: 1 blocker, 1 important finding
  • Domain: 3 important, 1 advisory finding
  • Test execution: not run; this was a source-and-test-surface review.

Blocker

  • Missing AC1.3 regression coverage: no test exercises the cross-provider plan-slot fail-soft path. TestSessionEngineFactoryPlanVsExecute uses only one provider, so it cannot detect rebasing/contacting a foreign alias target, losing the bounded warning, or changing plan permission behavior. Add a two-provider factory/run test which asserts fallback to the persisted provider's ordinary model and zero calls to the foreign alias target. Relevant code: internal/app/slots.go:203; current test: internal/app/slots_plan_test.go:152. Acceptance plan: docs/acceptance/delegation-provider-model-selectors.md:55.

Important findings

  1. Control-byte contract violation: router-category descriptions permit newline control bytes and return them in model discovery. The contract requires control-byte rejection before descriptions become model-visible. See internal/adapter/permconfig/schema.go:1947, internal/app/agent_model_discovery.go:240, and docs/acceptance/delegation-provider-model-selectors.md:38.

  2. Living-doc mismatch: docs/architecture/providers.md:537 says scalar aliases resolve through the consumer's contextual provider, but configured operator aliases bind to the configured default provider at internal/app/model_alias.go:58 and internal/app/slots.go:427. Document that configured-default binding and limit the contextual statement to unconfigured/CLI scalar aliases.

  3. Incomplete Parallel/Team composition coverage: current tests inject collaborators or call factories directly, so catalog-level selector wiring can regress without a failing test. Add real Build coverage for both tools using a cross-provider direct pair, asserting the selected provider receives the child request and invalid selection creates no branch/member. See internal/app/catalog.go:468, internal/app/catalog.go:535, and engine/agent/adr0369_parallel_team_selectors_test.go:36.

  4. Durable child-session provenance is missing: Parallel and Team choose provider-aware engines but do not stamp their created Session aggregates with the resolved provider/model. This breaks provenance, usage attribution, and rehydration for cross-provider children. Mirror the existing Subagent binding (engine/agent/subagent.go:2709) in engine/agent/parallel.go:1193 and engine/agent/teamsupervisor.go:923, with persistence tests.

  5. Remove the parallel scalar-alias path: fold legacy ModelAliases/ScalarModelAliases into ModelAliasTargets as ModelTarget{Model: ...}. Production callers already use the universal map and lookupModelAliasTarget is the resolution choke point. Locations: internal/app/build.go:832, internal/app/slots.go:307, internal/cliconfig/cliconfig.go:557.

  6. Repeated child-target resolution: four child-engine factory paths repeat provider lookup/context-window derivation. Consider a narrow resolveChildTarget helper while retaining factory-specific catalog and prompt construction. Locations: internal/app/build.go:7297, internal/app/build.go:7362, internal/app/build.go:7847, internal/app/build.go:7971.

Advisory

  • reservedModelRouterProvider duplicates the existing providerModelRouter constant. Reuse the existing constant so validation, registry admission, resolver dispatch, and discovery cannot drift. See internal/app/model_alias.go:8 and internal/app/registry.go:41.

Security review found no additional concrete security issue.

@jbeda
jbeda force-pushed the plan/delegation-provider-model-selectors-amendment branch from 3b4f1c7 to a8d80f2 Compare October 4, 2026 19:35
@jbeda
jbeda force-pushed the plan/delegation-provider-model-selectors-amendment branch from a8d80f2 to 3f847a1 Compare October 5, 2026 03:18
@kantord

kantord commented Oct 6, 2026

Copy link
Copy Markdown
Member

AI-driven follow-up review (not a human review)

This follow-up is purely an AI-driven source/test review performed by automated subagents. It has not been independently validated by a human reviewer.

I reviewed the current PR head 3f847a120d0d84823c207d500c35a52331f196e0 against its current base 3222c2fb808d4140d19b2979a73dd2a6b2cc4398, and range-diffed it against the previously reviewed patch ending at e4c4e325311bc7ffc7fa007b9d7e1c35ab734912.

The actual post-review additions are 28fc253f and 3f847a12; most earlier commit hash changes are from the rebase. The PR is still reported by GitHub as conflicting, so the eventual conflict resolution needs another check.

Correction to the previous AI review

The previous comment's sole blocker was incorrect. The AC1.3 two-provider plan-slot fail-soft test was already present in the previously reviewed head and remains at internal/app/slots_plan_test.go:368-443. It covers same-provider selection, cross-provider fallback, preserved plan mode, warning emission, actual identity, and zero calls to the wrong provider. This should not have been reported as missing.

What the new changes fixed

  • Separated opaque model identity from friendly inventory names. Status/customization input now carries exact ProviderID/model ID, provider-qualified ProviderLabel, and separate FriendlyName fields (cmd/mecatui/customization/input.go:60-74). Header/status rendering derives identity from the server-resolved pair rather than treating a friendly name as identity (cmd/mecatui/ui/statusline_source.go:227-240, cmd/mecatui/ui/view.go:249-270). The customization protocol and docs were updated to v5.
  • Preserved provider/model attribution while adapting to the rebased auxiliary-usage APIs. Compaction, ask-reviewer, router, and reflection construction now carry the resolved provider/model identity through the new ProviderModelID/AuxiliaryUsage shapes (internal/app/build.go:4878-4913, internal/app/build.go:7462-7627, internal/app/reflection_observer.go:851-866).
  • Closed concrete rebase wiring gaps. Cross-provider writable subagents now pass the selected pair into writableExplorerDeps (internal/app/build.go:7306-7327), and team child engines consistently use the selected provider ID (internal/app/build.go:8517-8544, internal/app/build.go:8728-8743).
  • No concrete new security regression was found in the follow-up delta.

Remaining findings from the previous review

  • Router description contract mismatch remains. Newline is explicitly exempted from control-byte rejection (internal/adapter/permconfig/schema.go:1956-1962) and the test intentionally accepts a folded description ending in a newline (internal/adapter/permconfig/models_test.go:247-267). This still conflicts with the acceptance language requiring control-byte rejection before model-visible discovery.
  • Scalar-alias documentation mismatch remains. docs/architecture/providers.md:535-540 says scalar aliases resolve on the consumer's contextual provider, while configured aliases bind through modelBindingProvider (internal/app/model_alias.go:58-62).
  • Explicit Parallel/Team selectors still lack real Build/catalog integration tests. Real-Build tests cover automatic router selection, but direct and explicit model-router selectors remain engine/factory-level. Wiring at internal/app/catalog.go:484-486 and internal/app/catalog.go:535-546 could regress without those tests failing.
  • Durable Parallel/Team session identity remains unstamped. The dependency wiring is improved, but Parallel and Team still create/persist child Session aggregates without setting their resolved ProviderID/ModelID (engine/agent/parallel.go:1197-1239, engine/agent/teamsupervisor.go:923-954). Subagent does stamp these fields (engine/agent/subagent.go:2714-2715).
  • The dual scalar/typed alias paths, duplicated router sentinel constants, and repeated child-target resolution remain unchanged. These are maintainability suggestions rather than merge blockers.

New test gap introduced by the follow-up

Important: 3f847a12 repairs cross-provider writable, no-FS, and named-specialist provider/model wiring, but its test change only adapts an existing helper call. There are no behavioral regression tests executing those repaired cross-provider paths (internal/app/build.go:7306, internal/app/build.go:7870, internal/app/build.go:8135, internal/app/build.go:8166). Existing writable coverage is same-provider/model-only. Add cross-provider tests asserting both provider identity and provider-dependent child dependencies for writable, no-FS, and named read-only/writable specialists.

Advisory: AC1.3 asserts warning presence but not that the warning remains bounded/value-free (internal/app/slots_plan_test.go:428).

Focused verification

The current head passed:

cd engine && go test ./agent/ -run '<ADR-0369 selector and validation tests>'
go test ./internal/app -run '<alias, slot, selector, and auxiliary-provider tests>'
go test ./cmd/mecatui/customization ./cmd/mecatui/ui

No live-provider tests were run. Because merge conflicts remain, these results apply only to current head 3f847a12, not to the eventual conflict-resolution commit.

@jbeda
jbeda force-pushed the plan/delegation-provider-model-selectors-amendment branch from 3f847a1 to ee9980d Compare October 6, 2026 20:37
@kantord

kantord commented Oct 7, 2026

Copy link
Copy Markdown
Member

Largely AI-automated follow-up review

This finding was produced through a largely AI-automated review using multiple automated reviewers. It has not been independently validated by a human reviewer and should be verified before acting on it.

Reviewed at current head ee9980d6c755f67c72c8b29ad0f33a5589e82969 against base 4b7abcd1ae1dbcb7b865bfb85f04bbc03ff2607f.

Blocker: an explicit undefined Team member can run on the wrong provider

A bare Team model selector correctly resolves contextually to the parent provider at internal/app/build.go:7963-7966. However, buildMemberSelectorEngine omits Target.Provider when that resolved provider equals the parent, retaining it only in ActualProvider (internal/app/build.go:7974-7978).

The undefined-member factories first initialize the member from the global child default, which may use another provider (internal/app/build.go:8559-8569). They replace the selected model but switch providers only when selected.Target.Provider is non-empty (internal/app/build.go:8706-8717; equivalent no-FS path at internal/app/build.go:8521-8533).

A reachable example is:

  • parent session on provider A;
  • global subagent/child default on provider B;
  • undefined Team member with a bare model selector intended to mean provider A / selected-model.

The resulting member instead runs as provider B / selected-model. This violates ADR 0369's contextual-provider rule and can send an unsupported or unintended model ID to the wrong provider.

Suggested fix: for undefined/no-FS members, use selected.ActualProvider when selected.Target.Provider is empty, while preserving the existing behavior for defined specialists. Add ordinary and no-FS regression cases with parent provider A, child default provider B, and both a bare model and contextual scalar alias. Assert that A receives the selected model, B receives no request, and the member evidence records A.

Additional advisory gaps

  • No restart-style test rebuilds Build/the catalog against persisted child provider/model identity; current reattachment coverage remains within one in-memory tool instance.
  • cmd/mecatui/ui/adr0369_delegation_evidence_test.go:80 now calls the routing-detail helper directly, so it no longer proves the actual delegation-focus pane wiring.

@jbeda

jbeda commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

AI-review feedback disposition (current head 471bc1cee)

Thanks for the reviews. The earlier plan-slot blocker was a false positive, as the second review noted: internal/app/slots_plan_test.go already exercises same-provider planning and cross-provider fallback without calling the foreign provider.

Correctness findings addressed:

  • The latest review's Team blocker is fixed in 471bc1cee: an undefined member with a bare model or contextual scalar alias uses the resolved parent provider even when the global child default is on another provider. Both the ordinary and no-FS paths use the resolved ActualProvider if the selector has no provider in Target. Real Build tests cover both selectors in both profiles, assert the parent provider receives the selected model, the child-default provider gets zero requests, and the Team event reports the actual pair (internal/app/build.go, internal/app/team_parallel_router_test.go).
  • Parallel and Team persist their child sessions' actual engine provider/model, including automatic-route fallback; new memstore tests check persisted identity and event evidence (engine/agent/parallel.go, engine/agent/teamsupervisor.go, engine/agent/adr0369_parallel_team_selectors_test.go).
  • Architecture documentation now distinguishes configured scalar aliases bound to models.default_provider from contextual literals/unbound aliases; it no longer points at the removed ADR as the source of truth (docs/architecture/providers.md).
  • Real Build → Service → catalog tests cover explicit cross-provider Parallel and Team selectors plus invalid-selector preflight; separate real-Build tests cover writable and no-FS cross-provider generic Subagents (internal/app/team_parallel_router_test.go, internal/app/subagent_selector_build_test.go). The earlier rebase changes also keep Mecatui's provider/model identity distinct from its friendly name.

Deliberate dispositions, not claims of complete implementation of every suggestion:

  • Router descriptions reject control characters except newline to support YAML folded descriptions; length/UTF-8 checks and tests cover this (internal/adapter/permconfig/schema.go, models_test.go). The old acceptance wording saying all control bytes are rejected was too broad for that deliberate behavior; no other controls are passed through.
  • The legacy scalar alias representation is retained for compatible configuration callers; typed provider-aware targets take precedence. Separate child builders keep different tools/runners/prompts, so a shared provider-resolution abstraction was not added solely to deduplicate a few lines. The duplicate router sentinel constant is a non-blocking cleanup left as-is.
  • Additional restart-style reattachment, full-Build explicit virtual-category and named-writable cross-provider, and UI focus-pane tests remain coverage suggestions rather than demonstrated defects; the existing persisted-identity, real-Build direct-pair, named-provider, and rendering tests cover the concrete regressions reviewed. The plan warning's value-free bound is not separately asserted by that plan-mode test.

Local checks after the latest fix: task lint, task test, task test:race, focused selector tests, and the offline demo pass. task generate, task docs, and task api:check passed on the rebased series before the final Go-only fix. CI on 471bc1cee is the independent gate. This comment reports resolution/disposition, not a human review or a merge decision.

@kantord kantord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Largely AI-automated approval

This review was produced through a largely AI-automated process using multiple automated reviewers. It is not a substitute for a human review or merge decision.

Thank you for the substantial follow-up work. At current head 95a7e864dcb3ecab87bcf2b9a9fd7a37b52a2bfc, the previously reported correctness blockers appear resolved: contextual Team selectors use the correct provider, Parallel and Team persist actual child identity, and the explicit Build/catalog plus writable/no-FS paths now have meaningful regression coverage. I found no remaining blocker in the reviewed patch, so I am approving it.

GitHub's PR API currently labels the branch CONFLICTING / DIRTY. Curiously, GitHub also publishes a merge ref whose parents are the exact current base and head, and a local git merge-tree succeeds, so I cannot substantiate a specific or large set of conflicting files. Please refresh or reconcile the branch state before merge. Any subsequent rebase or conflict-resolution push should be re-reviewed because this approval applies only to the exact head above.

Two non-blocking nits remain:

  • The durable-identity test at engine/agent/adr0369_parallel_team_selectors_test.go:134 covers rejected-route fallback. Adding persisted ProviderID/ModelID assertions for successful explicit/routed cross-provider Parallel and Team children would close the remaining mutation gap.
  • docs/architecture/subagents-and-teams.md:95 still says that “A scalar alias uses the parent provider.” Configured scalar aliases bind to models.default_provider; only contextual selectors and unbound/CLI aliases remain parent-relative. This should match docs/architecture/providers.md:552-563 and ADR 0369.

Thanks again for addressing the earlier findings and documenting their disposition clearly.

jbeda and others added 20 commits October 8, 2026 11:57
Unify provider-aware factory seams, preserve truthful Parallel and Team child session identity, and cover real catalog selection. Refresh operator model documentation and generated config reference.

Co-authored-by: Mecatl <[email protected]>
Use the resolved provider for bare model and scalar-alias selections when the global child default points elsewhere, including no-FS teams.

Co-authored-by: Mecatl <[email protected]>
Preserve provider-aware routing, delegation, plan fallback, and discovery guidance in the new canonical session pages; regenerate the CLI reference after rebasing.

Co-authored-by: Mecatl <[email protected]>
Restore full provider/model route identity, Jev input-limit behavior, remote debugging, routing evidence, and shipped header cues after the docs restructure.

Co-authored-by: Mecatl <[email protected]>
Clarify configured scalar alias binding and remove stale model-policy comments after rebasing.

Co-authored-by: Mecatl <[email protected]>
@jbeda
jbeda force-pushed the plan/delegation-provider-model-selectors-amendment branch from 95a7e86 to 3622e2e Compare October 8, 2026 22:32
@jbeda
jbeda merged commit 34f485d into main Oct 8, 2026
40 checks passed
@jbeda
jbeda deleted the plan/delegation-provider-model-selectors-amendment branch October 8, 2026 23:07
This was referenced Oct 13, 2026
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.

2 participants