fix: defer memory file scaffold when Abilities API unavailable at activation#989
Merged
fix: defer memory file scaffold when Abilities API unavailable at activation#989
Conversation
…ivation During plugin activation, WordPress fires init before including the plugin via plugin_sandbox_scrape, so the init callback that registers abilities never runs. datamachine_ensure_default_memory_files() now returns bool to signal availability, and the activation handler sets a transient when the scaffold cannot run. A deferred init hook at priority 20 picks up the transient on the first normal request and completes the scaffold. Closes #988
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.
Summary
Fixes #988 —
USER.md(and agent-layer memory files) were not scaffolded during plugin activation because the Abilities API isn't available at that point.Root Cause
During plugin activation, WordPress fires
initbefore including the plugin viaplugin_sandbox_scrape(). This means ouradd_action('init', ...)callback that registers abilities never runs in the activation request. Whendatamachine_ensure_default_memory_files()callsScaffoldAbilities::get_ability(), it returnsnulland the function silently bails.This is expected WordPress behavior, not a core bug. The Abilities API explicitly blocks initialization before
initand is designed for the normal request lifecycle.Fix
Three small, focused changes:
datamachine_ensure_default_memory_files()now returnsbool—trueif scaffold ran,falseif abilities were unavailable. Backward-compatible: existing callers that ignore the return value are unaffected.datamachine_activate_for_site()sets a transient on failure — when the scaffold bails during activation,set_transient('datamachine_needs_scaffold', 1, HOUR_IN_SECONDS)flags that work is pending.Deferred
inithook at priority 20 picks up the transient on the first normal request (after abilities register at priority 10), runs the scaffold, and deletes the transient.Why this approach
datamachine_maybe_run_migrations()edge case (runs atinitpriority 5, before abilities register at 10)