fix: derive async-runner loopback scheme+port from the internal server, not the public URL#402
Merged
Merged
Conversation
…r, not the public URL The Action Scheduler loopback burst that warms N async-runner workers rewrites the dispatch host to 127.0.0.1 (to dodge .local mDNS latency) but PRESERVED the scheme and port parsed from the public admin-ajax URL — always https, default :443. On a split runtime whose internal worker pool is plain HTTP on a non-443 port (public HTTPS front door on .local:443, internal pool on localhost:8882), the rewritten target becomes https://127.0.0.1/... with no TLS listener on 127.0.0.1:443, so every concurrent async-runner POST fails the TLS handshake. The fan-out then silently collapses to the serial ~60s WP-Cron heartbeat drain — the last cap on true N-way parallel branch fanout. Add the agents_workflow_async_runner_loopback_base filter so a runtime (or an mu-plugin) can declare where its local server is ACTUALLY reachable on the loop, e.g. http://localhost:8882. When set, its scheme/host/port replace the public ones; the original path + query (the AS nonce) are carried onto it and the canonical public Host header is preserved so the local server still virtual-hosts to the correct site. When the filter is unset the behavior is byte-for-byte the pre-filter default (host -> 127.0.0.1, scheme + port + Host from the public URL), so no single-server runtime regresses. Adds tests/workflow-async-loopback-target-smoke.php with real assertions on the constructed target for both the default and the plain-HTTP-non-443 override case. PHPStan level max clean; full smoke suite green.
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.
Root cause
WP_Agent_Workflow_Action_Scheduler_Branch_Executor::loopback_dispatch_target()warms N async-runner workers by firing N concurrent loopback POSTs toadmin-ajax.php(theas_async_request_queue_runneraction). To dodge multi-second.localmDNS resolution it rewrites the dispatch host to127.0.0.1and carries the real host in aHost:header — correct. But it also preserved the scheme and port parsed from the public admin-ajax URL — alwayshttps, default:443.On a split runtime whose internal worker pool is plain HTTP on a non-443 port (public HTTPS front door on
.local:443, internal pool onlocalhost:8882), the rewritten target becomeshttps://127.0.0.1/wp-admin/admin-ajax.php?…. There is no HTTPS listener on127.0.0.1:443, so every concurrent async-runner POST fails the TLS handshake (ssl/tls alert handshake failure). The loopback burst that should wake N workers for N branches all fail, and branches fall back to the serial ~60s WP-Cron heartbeat drain — the last cap on true N-way parallel branch fanout.Measured directly on the affected runtime with
Requests::request_multiple:https://127.0.0.1/…target → 0/8 succeed (TLS handshake failure).http://localhost:8882/…+ canonicalHost:header → 8/8 → HTTP 200, 8 workers claim + drain 8 distinct branches.The fix
Add the
agents_workflow_async_runner_loopback_basefilter so a runtime (or an mu-plugin) can declare where its local server is ACTUALLY reachable on the loop, e.g.http://localhost:8882. When set, its scheme/host/port replace the public ones; the original path + query (the AS nonce) are carried onto it, and the canonical publicHost:header is preserved so the local server still virtual-hosts to the correct site.When the filter is unset the behavior is byte-for-byte the pre-filter default (host →
127.0.0.1, scheme + port +Hostheader from the public URL), so no single-server runtime regresses. The.local→127.0.0.1 mDNS dodge is intact; the scheme/port fix composes cleanly with it.The filter default is generic — agents-api stays product-agnostic; the runtime supplies its real internal loopback base.
Tests
tests/workflow-async-loopback-target-smoke.php(new) — real assertions on the constructed target for both the default (https://127.0.0.1/…+ canonical Host) and the plain-HTTP-non-443 override (http://localhost:8882/…, nothttps://127.0.0.1:443/…) cases, plus nonce survival and explicit-port handling. Wired intocomposer smoke.AI assistance