fix: guard MemoryFileRegistry against missing agents-api at bootstrap#2006
Open
chubes4 wants to merge 1 commit into
Open
fix: guard MemoryFileRegistry against missing agents-api at bootstrap#2006chubes4 wants to merge 1 commit into
chubes4 wants to merge 1 commit into
Conversation
DM core declares agents-api as a Requires Plugins dependency, which the WordPress admin UI honors. The Homeboy playground bootstrap (used by homeboy test and homeboy release on every DM-aware plugin) loads plugins via require_once and bypasses that gate. That means DM core can boot in an environment where the agents-api substrate classes do not exist — and MemoryFileRegistry fataled during muplugins_loaded because it referenced WP_Agent_Memory_Layer, WP_Agent_Memory_Registry, WP_Agent_Context_Injection_Policy, and WP_Agent_Context_Authority_Tier unguarded. This blocked homeboy test and homeboy release across the DM family (data-machine-events, data-machine-socials, data-machine-frontend-chat, data-machine-code, …). data-machine-events v0.33.0 had to ship with --skip-checks today because of it. Guard every substrate access in MemoryFileRegistry with a cached class_exists() check. When the substrate is loaded (production), behavior is unchanged. When it isn't (playground), the registry runs degraded against its local self::$files map with canonical string-literal fallbacks for layer normalization, retrieval policy, and authority tier. Verified: homeboy test data-machine completes with 1259 passed, 0 failed, 3 skipped — the muplugins_loaded fatal is gone. Fixes #2005
Contributor
Homeboy Results —
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2005
Summary
MemoryFileRegistryfataled duringmuplugins_loadedwhenever DM core booted in an environment where theagents-apisubstrate wasn't loaded (notably the Homeboy playground used byhomeboy testandhomeboy release).WP_Agent_Memory_Layer::normalize(),WP_Agent_Context_Injection_Policy::{NEVER,ALWAYS,normalize,is_always_injected},WP_Agent_Memory_Registry::{register,unregister,reset,get_all}, and\AgentsAPI\AI\Context\WP_Agent_Context_Authority_Tier::*constant access.agents_api_loaded()helper. Production behavior (substrate loaded) is unchanged.self::$filesmap with canonical string-literal fallbacks (workspace_shared,user_global,agent_identity,agent_memory,always,never) that match the substrate's vocabulary.homeboy testandhomeboy releasefor every DM-aware plugin:data-machine-events,data-machine-socials,data-machine-frontend-chat,data-machine-code.The trace (from #2005)
data-machine-events v0.33.0had to ship with--skip-checkstoday because of this.Before / after
normalize_layer()Before:
After:
default_authority_tier()Before:
After:
The fallback string literals match
WP_Agent_Context_Authority_Tier::ordered()exactly, so downstream string-comparisons keep working in degraded mode.Why the fix is wider than the issue suggested
The issue body named
normalize_layer()(line 593) anddefault_authority_tier()(line 598) as the two touch-points. Guarding only those would have shifted the fatal one frame deeper:register()itself directly accessesWP_Agent_Context_Injection_Policy::NEVER/ALWAYSconstants (then-line 129-130),::normalize()(then-line 146), andWP_Agent_Memory_Registry::register()(then-line 153) on the same bootstrap path. All four are missing in the playground at the same moment.So the fix wraps every substrate access reachable during
register()/deregister()/reset()/get_resolved()/get_for_mode()behind the same cached guard. Code paths reachable only afteragents-apiis guaranteed loaded (admin UI handlers, etc.) are deliberately left alone — adding guards there would be dead defensive code.Test plan
tests/memory-file-registry-missing-agents-api-smoke.php(new — pure PHP, no autoloader pollution)Deliberately does NOT load
vendor/automattic/agents-api/, then exercises every touch-point. 21 assertions, all pass:class_exists()returns false for all four substrate classes.register()does not throw.shared,agent,user,network) round-trip throughnormalize_layer().LAYER_AGENT.default_authority_tier()returns the canonical string literals (workspace_shared,user_global,agent_identity,agent_memory).retrieval_policyis'always'when modes are declared,'never'when omitted.get_for_mode('chat')filters correctly without fataling.deregister()andreset()complete without fataling.Run with:
php tests/memory-file-registry-missing-agents-api-smoke.phptests/Unit/Engine/AI/MemoryFileRegistryTest.php(new — regression for substrate-loaded path)Six test cases verifying the
register()refactor did not change production behavior:test_register_round_trips_through_get_alltest_unknown_layer_normalizes_to_agent_defaulttest_no_modes_defaults_to_never_retrieval_policytest_default_authority_tier_uses_canonical_vocabularytest_deregister_removes_entrytest_get_for_mode_filters_by_mode_and_policyhomeboy test data-machine(the smoke that motivated this issue)Run from the worktree:
Before this PR:
STAGE_FAIL:load_deps:Error: Class "WP_Agent_Memory_Layer" not foundat the firstMemoryFileRegistry::register()call ininc/bootstrap.php. After: full suite runs.Lint / syntax
php -lclean on all three touched files.vendor/bin/phpcsclean on all three touched files.homeboy audit --path .: no new outliers attributable to this change.Out of scope (per issue body)
agents-apientirely. The dependency is correct; we just made it optional during bootstrap/test.Requires Plugins. Filed separately upstream.