Skip to content

fix: preserve normalized pending mediation requests - #522

Merged
chubes4 merged 1 commit into
mainfrom
fix-521-pending-mediation-normalization
Aug 23, 2026
Merged

fix: preserve normalized pending mediation requests#522
chubes4 merged 1 commit into
mainfrom
fix-521-pending-mediation-normalization

Conversation

@chubes4

@chubes4 chubes4 commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make pending pre-tool mediation normalization idempotent when an option-provided decision passes unchanged through agents_api_pre_tool_call_decision
  • preserve the canonical runtime-tool request and its host-provided identity when re-normalizing the pending tool-result envelope
  • add focused coverage for a no-op filter, custom request ID, and runtime-tool store

Root cause

pre_tool_mediation_decision() normalized the option mediator's pending decision before applying agents_api_pre_tool_call_decision, then normalized the filter result again. On that second pass, normalize_pre_tool_mediation_decision() treated the already-normalized decision['result'] tool-result envelope as though it were the pending request itself. Because the actual request was nested under result.runtime_tool_request, request normalization could not see the host-provided request_id and generated a replacement hash ID.

The pending branch now recognizes an already-normalized tool-result envelope, unwraps its canonical runtime_tool_request, and retains the envelope's runtime, metadata, and error fields. Existing compatibility is preserved: explicit top-level runtime_tool_request remains first priority, the request alias remains second, and legacy raw requests supplied through result continue to normalize as before.

Verification

  • php tests/conversation-loop-tool-execution-smoke.php (123 assertions passed)
  • php -l src/Runtime/class-wp-agent-conversation-loop.php (no syntax errors)
  • php -l tests/conversation-loop-tool-execution-smoke.php (no syntax errors)
  • composer phpstan (no errors)
  • git diff --check (clean)

Fixes #521

@chubes4
chubes4 merged commit c930b9a into main Aug 23, 2026
4 checks passed
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.

Pending pre-tool mediation loses canonical request on second normalization

1 participant