Skip to content

fix: defer memory file scaffold when Abilities API unavailable at activation#989

Merged
chubes4 merged 1 commit intomainfrom
fix/activation-scaffold-timing
Mar 29, 2026
Merged

fix: defer memory file scaffold when Abilities API unavailable at activation#989
chubes4 merged 1 commit intomainfrom
fix/activation-scaffold-timing

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented Mar 29, 2026

Summary

Fixes #988USER.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 init before including the plugin via plugin_sandbox_scrape(). This means our add_action('init', ...) callback that registers abilities never runs in the activation request. When datamachine_ensure_default_memory_files() calls ScaffoldAbilities::get_ability(), it returns null and the function silently bails.

This is expected WordPress behavior, not a core bug. The Abilities API explicitly blocks initialization before init and is designed for the normal request lifecycle.

Fix

Three small, focused changes:

  1. datamachine_ensure_default_memory_files() now returns booltrue if scaffold ran, false if abilities were unavailable. Backward-compatible: existing callers that ignore the return value are unaffected.

  2. 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.

  3. Deferred init hook 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

  • Respects the Abilities API design — no bypassing the registry or duplicating filesystem logic
  • One-shot: the transient fires once then self-cleans
  • Auto-expires (1 hour) so it can't get stuck
  • Also covers the datamachine_maybe_run_migrations() edge case (runs at init priority 5, before abilities register at 10)

…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
@chubes4 chubes4 merged commit da980de into main Mar 29, 2026
1 check failed
@chubes4 chubes4 deleted the fix/activation-scaffold-timing branch March 29, 2026 19:32
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.

USER.md not scaffolded during activation — Abilities API unavailable at activation hook timing

1 participant