Skip to content

Fix agent bundle ability registration for sandbox runs#2629

Merged
chubes4 merged 8 commits into
mainfrom
fix-agent-abilities-late-init
Jun 15, 2026
Merged

Fix agent bundle ability registration for sandbox runs#2629
chubes4 merged 8 commits into
mainfrom
fix-agent-abilities-late-init

Conversation

@chubes4

@chubes4 chubes4 commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary

  • Register Data Machine agent abilities outside the full runtime gate so WP Codebox sandbox runtime tasks can resolve datamachine/run-agent-bundle.
  • Avoid marking AgentAbilities registered when constructed after the Abilities API lifecycle without actually registering.
  • Add a focused smoke test for the agent ability registration lifecycle.

Testing

  • php tests/agent-abilities-registration-smoke.php
  • php -l inc/Abilities/AgentAbilities.php && php -l data-machine.php && php -l tests/agent-abilities-registration-smoke.php
  • php tests/send-email-ability-lazy-definitions-smoke.php && php tests/abilities-categories-load-order-smoke.php

AI assistance

  • AI assistance: Yes
  • Tool(s): OpenCode (GPT-5.5)
  • Used for: Diagnosed the WP Codebox sandbox ability registration failure, drafted the patch and smoke test, and ran local verification. Chris remains responsible for review and merge.

@homeboy-ci

homeboy-ci Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Homeboy Results — data-machine

Lint

lint — passed

ℹ️ Full options: homeboy docs commands/lint
Deep dive: homeboy lint data-machine --changed-since 1ab9c45

Artifacts and drill-down
  • CI results artifact: homeboy-ci-results-data-machine-lint-quality-Linux-node24 contains immediate command JSON for this action invocation.
  • Observation artifact: homeboy-observations-data-machine-lint-quality-Linux-node24 contains exported Homeboy run history for deeper queries.
  • Drill-down: download the observation artifact, then run homeboy runs import <dir>, homeboy runs list, and homeboy runs findings <run-id>.
  • Artifacts are attached to the workflow run: https://github.com/Extra-Chill/data-machine/actions/runs/27574345186

Test

test — passed

ℹ️ Auto-fix lint issues: homeboy refactor data-machine --from lint --write
ℹ️ Collect coverage: homeboy test data-machine --coverage
ℹ️ Pass args to test runner: homeboy test -- [args]
ℹ️ Full options: homeboy docs commands/test
Deep dive: homeboy test data-machine --changed-since 1ab9c45

Artifacts and drill-down
  • CI results artifact: homeboy-ci-results-data-machine-test-quality-Linux-node24 contains immediate command JSON for this action invocation.
  • Observation artifact: homeboy-observations-data-machine-test-quality-Linux-node24 contains exported Homeboy run history for deeper queries.
  • Drill-down: download the observation artifact, then run homeboy runs import <dir>, homeboy runs list, and homeboy runs findings <run-id>.
  • Artifacts are attached to the workflow run: https://github.com/Extra-Chill/data-machine/actions/runs/27574345186

Audit

audit — passed

  • audit — 49 finding(s)
  • Total: 49 finding(s)

Deep dive: homeboy audit data-machine --changed-since 1ab9c45

Artifacts and drill-down
  • CI results artifact: homeboy-ci-results-data-machine-audit-quality-Linux-node24 contains immediate command JSON for this action invocation.
  • Observation artifact: homeboy-observations-data-machine-audit-quality-Linux-node24 contains exported Homeboy run history for deeper queries.
  • Drill-down: download the observation artifact, then run homeboy runs import <dir>, homeboy runs list, and homeboy runs findings <run-id>.
  • Artifacts are attached to the workflow run: https://github.com/Extra-Chill/data-machine/actions/runs/27574345186
Tooling versions
  • Homeboy CLI: homeboy 0.229.11+40902460
  • Extension: wordpress from https://github.com/Extra-Chill/homeboy-extensions
  • Extension revision: a5bf3b36
  • Action: unknown@unknown

chubes4 and others added 7 commits June 15, 2026 13:36
WP Codebox sandbox runs (WordPress Playground) execute the smoke via
`run-php`, which boots WordPress through wp-load.php — firing init and the
one-shot wp_abilities_api_categories_init / wp_abilities_api_init actions —
and only THEN require_once's the plugin file. By the time AgentAbilities
and AbilityCategories are instantiated, both registration windows have
already closed, so the public wp_register_ability()/wp_register_ability_category()
helpers no-op. The datamachine-agent category was never registered, and
WordPress core then dropped every category-bound agent ability (including
datamachine/run-agent-bundle) via _doing_it_wrong() and a null return.

Core only enforces the abilities lifecycle in the public helper wrappers;
WP_Abilities_Registry::register() and WP_Ability_Categories_Registry::register()
have no such guard and are safe to call any time after init. Add a guarded
late-registration path to both classes that registers through the registry
instance when the init action has already completed, keeping the public-helper
path for normal requests. The is_registered() guard makes the late path
idempotent.

Update the related lifecycle smoke tests to assert the corrected behavior
(post-init construction registers via the registry instead of silently
no-opping) and faithfully model the registry instances.
The host-smoke-wp backend runs changed smoke tests inside a real WordPress
runtime. agent-abilities-late-registration-smoke.php unconditionally declared
doing_action(), did_action(), add_action(), and WP_Ability — fataling with
"Cannot redeclare" once it ran in real WP. Add a wp_get_ability() real-runtime
branch that asserts datamachine/run-agent-bundle is registered (mirroring
agent-abilities-registration-smoke.php), and guard every pure-PHP stub behind
function_exists()/class_exists() so the file is safe to include in both the
standalone pure-PHP harness and the real WordPress runtime.
The wp-codebox host-smoke-wp backend boots a bare WordPress with the plugin
DIRECTORY mounted but NOT activated (recipe blueprint has plugins: []), so
Data Machine's normal plugins_loaded registration never runs. The real-WP
branch of agent-abilities-registration-smoke.php (and the late-registration
smoke) asserted wp_get_ability('datamachine/run-agent-bundle') against this
bare runtime, where no Data Machine ability is ever registered — the test
could not pass.

Load the agent ability registration the same unconditional way data-machine.php
does at file scope (AbilityCategories::ensure_registered() + new AgentAbilities()),
then assert the ability resolves through wp_get_ability(). This exercises the
real registration code on the real registry, covering the hook-before-fire,
register-during-fire, and late-register-after-fire timing states. Also remove
the temporary diagnostic and guard the pure-PHP AbilityCategories stub behind
class_exists() so it never clashes with the required real class.
@chubes4 chubes4 merged commit 96700a2 into main Jun 15, 2026
5 checks passed
@chubes4 chubes4 deleted the fix-agent-abilities-late-init branch June 15, 2026 20:37
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.

1 participant