Repository navigation
feat(cli): --webhook-receiver-auto-tunnel - #681
Merged
Merged
Conversation
bokelley
force-pushed
the
bokelley/webhook-reachability-doc
branch
from
April 21, 2026 01:43
c421912 to
d7f5205
Compare
bokelley
force-pushed
the
bokelley/webhook-reachability-doc
branch
from
April 21, 2026 01:47
d7f5205 to
4ee82b4
Compare
…rendezvous Design proposal responding to client feedback that webhook grading requires a public IP. Rejects socket mode (breaks conformance parity with production HTTP emitter) and ngrok-bundling (vendor lock + test-kit forbids it). Proposes a --webhook-receiver-auto-tunnel flag as a short-term fix and an AdCP-hosted rendezvous service as the long-term answer. Follow-up to PR #679. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Autodetect ngrok/cloudflared on PATH, spawn the tunnel pointed at the
webhook receiver port, extract its public URL, and plumb it into proxy
mode. Cleans up on exit (including SIGINT/SIGTERM). HTTP on the wire —
the webhook_receiver_runner parity invariant (loopback_mock ≡ proxy_url)
is preserved.
ADCP_WEBHOOK_TUNNEL="<cmd> {port}" overrides detection with a custom
tunnel, which keeps the CLI vendor-agnostic per the test-kit's
"MUST NOT require a specific tunnel vendor" rule and doubles as the
hook for the test suite to stub a fake tunnel binary.
Conflict validation (public-url, loopback, multi-pass strategy) runs
before the dry-run gate so flag misuse fails fast; actual tunnel spawn
is deferred past dry-run to avoid wasting startup cost on previews.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…issue Option A (auto-tunnel helper) is shipping in the companion commit on this branch. Option B (hosted rendezvous) is a spec-stewardship initiative with hosting, operational, and abuse-prevention commitments that belong in the adcp spec repo, not as an in-repo RFC — now tracked at adcontextprotocol/adcp#2618 (milestone 3.1.0). Keeps the Socket Mode and ngrok-bundling rejection arguments in place since they're the load-bearing reason the CLI is shaped the way it is. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…stricter conflict Three substantive fixes from the expert reviews: 1. URL-capture scoping. ngrok regex now pins to known vendor domains (*.ngrok-free.app, *.ngrok.io, *.ngrok.dev, *.ngrok.app) instead of matching any `url=<https://…>` field, so a stray diagnostics URL in startup logs can't be mistaken for the forwarding URL. Custom templates now require an explicit `ADCP_TUNNEL_URL=<https://…>` marker on stdout/stderr — the "first https:// URL" heuristic wired tunnel destinations to docs links whenever the binary logged one at startup. 2. Persistent signal handlers. `process.once` on SIGINT/SIGTERM meant a second Ctrl-C bypassed tunnel cleanup and leaked listeners. Replaced with module-level handlers installed lazily on first tunnel spawn, backed by a shared child set, with a SIGTERM → SIGKILL grace period so tunnels that ignore TERM still get reaped. 3. Unified --webhook-receiver conflict. validateAutoTunnelArgs previously only rejected explicit `--webhook-receiver loopback`; a bare `--webhook-receiver` silently resolved to loopback_mock and was then overwritten by proxy_url, hiding operator intent. Now rejects any `--webhook-receiver` form alongside auto-tunnel with a single clear message (auto-tunnel always implies proxy mode). Smaller fixes: - ADCP_WEBHOOK_TUNNEL_TIMEOUT_MS validates via Number.isFinite + positive check; invalid/zero values warn and fall back to 15000 instead of silently swallowing garbage. - runCli gains a timeout + SIGKILL on spawnSync so a regression where URL capture succeeds but the run hangs fails the test instead of stalling CI. - New test: custom template ignores a bystander URL printed before the marker (regression for the "first https:// wins" class of bugs). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Same reasoning as the rendezvous RFC: design docs drift and don't belong in the repo. The PR description captures the "why" durably (Socket Mode rejection, ngrok-bundling rejection, auto-tunnel selection) and the changeset now links straight to the rendezvous issue instead of routing through a deleted file. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Found two issues when running against a real ngrok binary:
1. ngrok regex missed the live `.ngrok-free.dev` domain. The previous
fix-commit vendor-domain allowlist (.ngrok-free.app, .ngrok.io,
.ngrok.dev, .ngrok.app) excluded `.ngrok-free.dev`, which is ngrok's
current free-tier subdomain after a mid-2024 migration. Rather than
chase the vendor-domain list, anchor on the stable `msg="started
tunnel"` log line ngrok emits exactly once per tunnel creation — the
URL in its `url=` field is authoritative by definition, and the
scoping still blocks stray `url=` fields elsewhere in the log stream
from being mistaken for the forwarding URL.
2. SIGKILL escalation was dead code. `reapTunnelChildren` scheduled a
`setTimeout` for the force-kill, but Node doesn't run timers after
the `'exit'` event fires, and the SIGINT/SIGTERM handlers called
`process.exit` synchronously right after `reapTunnelChildren` —
cancelling the timer before it could fire. A tunnel that ignored
TERM would never see KILL. Split the paths: `'exit'` sends TERM only
(best-effort, OS reaps strays); SIGINT/SIGTERM send TERM, schedule
a 250ms `setTimeout` that SIGKILLs survivors and calls
`process.exit`. Also guard against a second signal during the
escalation window by SIGKILLing immediately on the repeat.
Verified end-to-end against real ngrok 3.37.3: URL captured, storyboard
ran, no zombie tunnel processes after exit.
Plus small fixes: help-text clarifies the custom-template marker
contract ("first match wins").
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Code-review finding: the per-chunk regex scan could miss the ngrok URL if ngrok's "started tunnel" logfmt line split across two `data` events. Anchoring on the head of the line (`msg="started tunnel"` … `url=…`) made line fragmentation a real failure mode where the prior vendor-domain-anchor version was immune. Scan a rolling 16 KiB buffer across chunks instead of each chunk in isolation. Security-review finding (low): the SIGKILL escalation only signals the direct child, so `ADCP_WEBHOOK_TUNNEL="sh -c 'ngrok …'"` would leave a grandchild behind. Documented the constraint in the --help text rather than adopting detached/PGID spawn semantics — the reviewer's pragmatic call, and ngrok/cloudflared direct paths are unaffected. Two nit-level cleanups: explicit `return` after `process.exit` in the second-signal branch (defensive against refactors that swap exit for something softer) and split the "why we don't unref the timer" comment into its two separate mechanisms. Verified end-to-end against real ngrok (ngrok-free.dev URL captured, storyboard ran, no zombie processes). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley
force-pushed
the
bokelley/webhook-reachability-doc
branch
from
April 21, 2026 09:35
4219aec to
5f73bf4
Compare
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.
Summary
Ships
--webhook-receiver-auto-tunnel— autodetectsngrokorcloudflaredonPATH(or$ADCP_WEBHOOK_TUNNEL="<cmd> {port}"override), spawns the tunnel pointed at the receiver, captures its public URL, plumbs it into proxy mode, and tears the tunnel down on exit / SIGINT / SIGTERM.Follow-up to #679 (now merged), which exposed
--webhook-receiveron the CLI but required operators to stand up their own tunnel manually.Design rationale
Why not Socket Mode (a client asked for a Slack-style outbound-WebSocket delivery path). The
webhook_receiver_runnertest-kit parity invariant says "an agent that passes underloopback_mockMUST also pass underproxy_url— any divergence is a conformance bug." Both modes drive the agent's production HTTP emitter end-to-end: TLS, RFC 9421 signature math over the wire,idempotency_keyacross retries, body preservation, retry back-off. Swap HTTP for a WebSocket push and none of that gets exercised. Socket Mode is a delivery mechanism, not a conformance harness.Why not bundle ngrok.
webhook-receiver-runner.yamlsays explicitly: "Operators MAY configure a tunnel as theproxy_urlprovider, but the runner MUST NOT require a specific tunnel vendor." Pinning ngrok violates that; also, free-tier caps + authtoken requirements make first-run compliance grading depend on a SaaS account.cloudflared,frp,bore,localtunnelare all legitimate alternatives.Why auto-tunnel. HTTP on the wire is unchanged — parity invariant holds. Detection is PATH-based + env-var overridable, so no vendor lock. One flag subsumes manual tunnel setup; works offline if the binary is installed. The tradeoff is the binary prerequisite, which an actionable "install ngrok or cloudflared" error message covers. A hosted rendezvous service for graders that can't install a tunnel is tracked at adcontextprotocol/adcp#2618 (milestone 3.1.0) — separate because it requires hosting commitment and operational ownership that don't belong in a client-library PR.
Implementation notes (post-review)
msg="started tunnel"logfmt line (vendor-domain-agnostic — catches.ngrok-free.dev,.ngrok-free.app,.ngrok.app, paid-tier and custom domains alike). Cloudflared matches*.trycloudflare.com. Custom templates must emitADCP_TUNNEL_URL=<https://…>— "firsthttps://URL" would wire the tunnel to any docs URL the binary logs at startup.dataevents, so an anchor/URL straddling chunk boundaries still matches.process.on(notonce) +tunnelEscalatinglatch. SIGINT/SIGTERM: TERM → 250 ms grace → SIGKILL →process.exit. Second signal during grace: force-KILL immediately.--webhook-receiver [mode]alongside auto-tunnel is rejected with a single message; auto-tunnel always implies proxy.--dry-run; the tunnel spawn does not.Verification
node --test test/lib/cli-webhook-receiver-flag.test.js→ 20/20 pass (11 original + 9 new: conflicts, dry-run skip, missing binary, URL capture, bystander-URL rejection, startup timeout, exit-before-URL)tsc --noEmitclean,prettier --checkclean.ngrok-free.devURL, storyboard ran, no zombie processes)trycloudflare.comURL, storyboard ran, no zombie processes)Files
bin/adcp.js— flag + detection/spawn/capture/cleanup helperstest/lib/cli-webhook-receiver-flag.test.js— 9 new auto-tunnel cases with stubbed tunnel (CI doesn't depend on ngrok/cloudflared).changeset/webhook-receiver-auto-tunnel.md— minor bumpFollow-ups
🤖 Generated with Claude Code