Skip to content

bug: ConversationManager calls unqualified wp_json_encode() in namespace → fatal in duplicate-tool-call smoke test #2588

@chubes4

Description

@chubes4

Summary

inc/Engine/AI/ConversationManager.php calls wp_json_encode() unqualified inside the DataMachine\Engine\AI namespace. When the surrounding WordPress shim doesn't provide a namespaced fallback, PHP resolves it to DataMachine\Engine\AI\wp_json_encode() — which doesn't exist — and fatals. This currently breaks the duplicate-tool-call-mode-aware-smoke.php host smoke test on every PR's Test job.

Evidence (CI Test job, any current PR)

PHP Fatal error: Uncaught Error: Call to undefined function
  DataMachine\Engine\AI\wp_json_encode()
  in inc/Engine/AI/ConversationManager.php:278
Stack:
  #0 ConversationManager.php(292): modelFacingToolDataJson()
  #1 ConversationManager.php(268): boundModelFacingToolData()
  ...
  #5 tests/duplicate-tool-call-mode-aware-smoke.php(37): generateDuplicateToolCallMessage()
HOST_SMOKE_FAIL:tests/duplicate-tool-call-mode-aware-smoke.php:exit=255
homeboy test: FAILED (exit code 255)

The rest of the suite passes (43 assertions, 0 failures immediately before); only this smoke test fatals.

Root cause

ConversationManager.php is in namespace DataMachine\Engine\AI;. Unqualified calls to global functions resolve to the current namespace first, then fall back to global — but only at runtime, and only if no namespaced function exists. In the host-smoke harness (no full WP bootstrap), wp_json_encode isn't guaranteed in the expected resolution path, so the namespaced lookup fails hard. At least two call sites:

  • line 134: ... : wp_json_encode( $value ) );
  • line 278: $json = wp_json_encode( $tool_data );

Introduced (or surfaced) by b4b0f2f6 fix: mediate conversation tools through Agents API.

Fix

Fully-qualify the calls: \wp_json_encode(...) (leading backslash) at every call site in this file (and audit the file for other unqualified WP function calls that could hit the same trap in the smoke harness — e.g. wp_parse_url, sanitize_*, etc., if any are called in code paths the host-smoke tests exercise).

Impact

  • Blocks the Test job on every PR — including unrelated PRs (found while merging feat: per-agent network scope for wake_briefing on multisite #2587, whose own changes don't touch this file). PRs are currently being merged with a red Test check because the failure is pre-existing and unrelated to their diffs.
  • Once fixed, the Test gate becomes meaningful again instead of a known-red signal everyone has to mentally skip.

Acceptance criteria

  • homeboy test data-machine -- --filter / the duplicate-tool-call-mode-aware-smoke.php host smoke test passes.
  • No unqualified wp_json_encode (or other global WP function calls that fatal under the host-smoke harness) remain in ConversationManager.php.

Constraints

  • Conventional commits (fix:).
  • No CHANGELOG edits / version bumps (homeboy-managed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions