Skip to content

feat: CPEX Rust config#38

Merged
araujof merged 3 commits into
devfrom
feat/cpex_config
May 4, 2026
Merged

feat: CPEX Rust config#38
araujof merged 3 commits into
devfrom
feat/cpex_config

Conversation

@terylt

@terylt terylt commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds config-driven plugin management to the CPEX Rust core. Plugins, policy groups, and routing rules are declared in
a single YAML config. The manager resolves routes at dispatch time based on entity metadata in extensions, with cached
lookups for high-throughput use cases.

Built on top of feat/cpex_rust_core (async invoke, PluginContextTable, OnError::Disable, etc.).

Config parser — Parses a unified YAML format with plugins, policy_groups, and routes sections. Routes match
entities by exact name, name list, glob, or wildcard with specificity-based resolution (exact 1000 > list 500 > glob
300 > wildcard 0). Scope filtering, tag merging (union), and when clauses (carried for APL evaluation) are
supported. Validation at parse time rejects duplicate plugins, unknown plugin refs, and malformed routes.

Factory systemPluginFactory trait maps kind strings to plugin constructors. from_config(yaml, factories)
builds a fully wired PluginManager from YAML. Routes can override plugin config; the factory creates new instances
with merged config.

Route-filtered dispatchinvoke_by_name and invoke::<H> resolve routes via MetaExtension (entity_type,
entity_name, scope, tags) before dispatching. When routing is disabled or meta is absent, all registered plugins fire.

Route cacheRwLock<HashMap<RouteCacheKey, Arc<Vec<HookEntry>>>> with hashbrown raw_entry for zero-allocation
cache hits and Arc for zero-copy reads. Keyed by (entity_type, entity_name, hook_name, scope).
clear_route_cache() for config reload.

MetaExtension — Added to Extensions with entity_type, entity_name, tags, scope, and properties. Used by the
routing system to identify which entity a hook invocation targets.

Closes: #16

Changes

  • config.rs — Unified YAML config parser with plugins, policy groups, routes, specificity-based resolution, scope
    matching, tag merging, and validation
    • factory.rsPluginFactory trait and PluginFactoryRegistry for config-driven plugin instantiation
    • manager.rsfrom_config/load_config, route-filtered dispatch, hashbrown route cache with Arc zero-copy
      reads, override instances with merged config, clear_route_cache
    • hooks/payload.rsMetaExtension (entity_type, entity_name, tags, scope, properties) on Extensions
    • registry.rsregister_for_names_with_handler for factory path (no HookTypeDef type parameter required)
    • lib.rs — Added factory module
    • Cargo.toml — Added hashbrown dependency

@araujof araujof changed the title Feat/cpex config feat: CPEX Rust config Apr 22, 2026
@araujof araujof added enhancement New feature or request framework Rust labels Apr 22, 2026
@araujof araujof added this to CPEX Apr 22, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in CPEX Apr 22, 2026
@araujof araujof added this to the 0.2.0 milestone Apr 22, 2026
@araujof araujof moved this from Backlog to In progress in CPEX Apr 22, 2026
@araujof araujof changed the base branch from main to dev April 24, 2026 01:46
@terylt terylt marked this pull request as ready for review April 28, 2026 15:49
@terylt terylt requested review from araujof and jonpspri as code owners April 28, 2026 15:49
@araujof araujof self-assigned this Apr 30, 2026

@araujof araujof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work, @terylt!

Overall,

  • Trust model enforcement is consistent: config loader -> manager -> PluginRef -> executor, never from plugin.
  • The Arc-based route cache with raw_entry zero-allocation hits is a good optimization.
  • Test coverage spans all execution modes, error behaviors, routing resolution, and cache behavior.
  • The 5-phase executor design is clean and the phase separation is well-enforced.

A few minor comments, let me know if they are planned in a next PR, or if you want to address them here.

Issues

1. Glob matching is overly simplistic (config.rs)

StringOrList::matches() only handles suffix wildcards (prefix*). Was that intentional?

let prefix = pattern.trim_end_matches('*');
name.starts_with(prefix)

This silently mismatches on interior or leading globs. Either document that only trailing * is supported, or use a glob crate (e.g., glob-match).

2. from_config duplicates load_config logic (manager.rs)

from_config() and load_config() have the same plugin instantiation loop and executor setup, but diverged implementations. Consider having from_config delegate to load_config internally.

3. RwLock::unwrap() will panic on poisoned lock (manager.rs)

If a thread panics while holding the write lock, all subsequent unwrap() calls will panic too, cascading across the system. Since this is a library crate consumed by others, consider using .read().unwrap_or_else(|e| e.into_inner()) (or parking_lot::RwLock which is non-poisoning and already a transitive dep via tokio).

4. find_matching_route returns only the single best route (config.rs)

If two routes have equal specificity for the same entity, the last one in config order wins (due to total > s using strict greater-than). This is deterministic but not documented, and could surprise users. Consider either documenting "first wins on tie" or returning all tied routes.

5. serde_yaml is deprecated (Cargo.toml)

The serde_yaml crate is deprecated in favor of alternatives. Not blocking, but worth noting for future migration planning (e.g., serde_yml or yaml-rust2 + manual serde).

Suggestions (non-blocking)

  • create_override_instance silently falls back (manager.rs): when factory creation fails, it logs an error and returns None, causing the base instance to fire with the original config. This could mask misconfigurations. Consider propagating the error or at minimum emitting a warn! with the route context.

  • FilteredExtensions is always default() (executor.rs): the TODO is fine for Phase 1, but since meta is needed for route resolution and plugins might want to read it, you could pass through meta in the filtered view now. Currently plugins can't see the meta extension that drives their own dispatch.

  • Shutdown in reverse order (manager.rs): the comment says "reverse registration order" but plugin_names() returns insertion order. If you want reverse, call .rev() on the iterator.

terylt added 3 commits May 4, 2026 12:22
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
@terylt terylt force-pushed the feat/cpex_config branch from feb85c6 to e78e75d Compare May 4, 2026 18:26
@araujof

araujof commented May 4, 2026

Copy link
Copy Markdown
Contributor

LGTM. Fixes to this PR will fold into #45.

@araujof araujof self-requested a review May 4, 2026 18:37
@araujof araujof merged commit dc3d248 into dev May 4, 2026
@github-project-automation github-project-automation Bot moved this from In progress to Done in CPEX May 4, 2026
@araujof araujof deleted the feat/cpex_config branch May 4, 2026 18:43
araujof pushed a commit that referenced this pull request May 4, 2026
* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
araujof pushed a commit that referenced this pull request May 6, 2026
* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
araujof pushed a commit that referenced this pull request May 6, 2026
* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
monshri pushed a commit to monshri/contextforge-plugins-framework that referenced this pull request May 27, 2026
* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
monshri pushed a commit to monshri/contextforge-plugins-framework that referenced this pull request Jun 8, 2026
* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
araujof pushed a commit that referenced this pull request Jun 10, 2026
* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
araujof added a commit that referenced this pull request Jun 10, 2026
* feat: initial Rust Core (cpex-core and cpex-sdk) (#13)

* feat: initial revision rust core.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: addressed comments in PR. Updated PluginContext to match spec.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>

* feat: CPEX Rust config (#38)

* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>

* feat:  RUST with CMF and extensions. (#44)

* feat: initial revision rust core.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: addressed comments in PR. Updated PluginContext to match spec.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: RUST CMF initial revision.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added invoke named support, added constants, fixed reviewed code.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added owned extensions and did some refactoring.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>

* feat: cgo Go bindings (#45)

* feat: initial revision rust core.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: addressed comments in PR. Updated PluginContext to match spec.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: RUST CMF initial revision.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added invoke named support, added constants, fixed reviewed code.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added owned extensions and did some refactoring.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added cgo and golang bindings, examples and readme.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* address P0/P1/P2 review findings (except #17)

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: address remaining P2/P3 review findings + testing gaps

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* docs: add CPEX Go public API spec

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* docs: renamed document

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* feat(cpex-rust): CGO review passes 1-11 + lint cleanup + Makefile targets

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: address linting issues, updated makefile to support building examples.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* docs: updated the go spec to reflect recent changes.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>

* docs: intial rust specification (#50)

Co-authored-by: Teryl Taylor <terylt@ibm.com>

* feat: change Plugin handler to async for performance (#49)

Co-authored-by: Teryl Taylor <terylt@ibm.com>

* fix: missing cmf-demo main.go file and gitignore fix that missed it (#52)

Co-authored-by: Teryl Taylor <terylt@ibm.com>

* feat: initial APL Rust implementation (#60)

* fix: initial revision APL.

* feat: apl-cpex bridge crate + plugin-registry-driven hook dispatch

* feat: add support for plugin calling in APL routes.

* feat: add more APL plugin support, unified config

* feat: added cedar direct PDP.

* feat: add identity hook and extensions.

* feat: added token delegation hooks and tests.

* feat: added plugin for jwt token identity, oauth and biscuit delegation, cedarling PDP.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: updated identity and delegation to support keycloak. added delegate() function, and identity sections.

* fix: added some sample plugins, added updates to support cedar.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added session support, serialize and parallel and full effects capabilities.

* feat: add ffi pre-built .a library

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: add workflow_dispatch target

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: critical and high issues from review.

* feat: add APL FFI and go bindings

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: add musl tools to musl runners

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: potential double free after use bug.

* chore: update Go module paths after repo rename to cpex

* feat: map identity extension into cpex ffi

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* feat: add cpex_invoke_resolved abi

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: has_hook_for handling

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: update headers

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: session binding

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: updated comments

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* tests: added more session tests for Tier 1 ids.

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: terylt <30874627+terylt@users.noreply.github.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request framework Rust

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE]: YAML config parsing for RUST Core with routing rules.

2 participants