Skip to content

feat(cli): --webhook-receiver flag so expect_webhook* steps can grade - #679

Merged
bokelley merged 4 commits into
mainfrom
bokelley/webhook-receiver-cli
Apr 21, 2026
Merged

bokelley merged 4 commits into
mainfrom
bokelley/webhook-receiver-cli

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Closes #675. Exposes the storyboard runner's existing webhook_receiver option on adcp storyboard run / adcp comply. Without this, webhook-emission and idempotency storyboards skipped their webhook-assertion steps with "Test-kit contract 'webhook_receiver_runner' is not configured on this runner" even when agents emitted fully spec-compliant signed RFC 9421 webhooks.

Three new flags (parsed once, plumbed through single-file, full-assessment via comply(), and multi-instance run paths):

  • --webhook-receiver [MODE] — MODE is loopback (default, 127.0.0.1) or proxy (operator-supplied public URL)
  • --webhook-receiver-port PORT — force bind port, defaults to auto-assign
  • --webhook-receiver-public-url URL — public HTTPS base for proxy mode, implies proxy when used alone

Setting any of these activates the receiver and adds webhook_receiver_runner to the run's contracts so requires_contract gates resolve. Also exposed on ComplyOptions (webhook_receiver, contracts) so programmatic callers of comply() get the same behavior.

CLI guards fail loudly up front for common footguns: proxy without public URL, loopback with public URL, non-integer or out-of-range ports, and --webhook-receiver combined with --multi-instance-strategy multi-pass (receiver URL is per-pass, agents caching pass-1 URLs would deliver to a dead port in pass 2).

Test plan

  • node --test test/lib/cli-webhook-receiver-flag.test.js test/lib/cli-storyboard-file-flag.test.js test/lib/cli-multi-instance-strategy.test.js test/lib/storyboard-webhook-receiver.test.js — 52/52 pass
  • npm run build + tsc --noEmit — clean
  • Live run against test-mcp webhook-emission --webhook-receiver — receiver boots, steps execute and grade real behavior (fail no_webhook_received because the public test agent doesn't emit webhooks, which is the correct signal — before this change they skipped with the contract-not-configured reason)
  • CI full suite
  • Manual: run against an agent that emits webhooks to confirm idempotency_key presence + retry-stability grades pass

🤖 Generated with Claude Code

…#675)

Exposes the storyboard runner's existing `webhook_receiver` option on the
CLI. Without this, `webhook-emission` and `idempotency` storyboards skipped
their webhook-assertion steps with "Test-kit contract 'webhook_receiver_runner'
is not configured on this runner" even when agents emitted fully spec-compliant
signed RFC 9421 webhooks.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley and others added 2 commits April 20, 2026 21:29
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…vector 027

Upstream `latest.tgz` published vector 027-webhook-registration-authentication-unsigned
between main's last CI run and this PR's. CI's "Validate generated files are
in sync" step regenerates against current upstream, so the branch has to
carry the regen.

- Regenerate core.generated.ts, tools.generated.ts, schemas.generated.ts
- Move CatalogAction / CatalogItemStatus re-exports: the generator placed
  them in core.generated.ts, not tools.generated.ts
- Register a passthrough mutation for vector 027 (same pattern as 021-026)
- Extend NEGATIVE_VECTORS_UNIMPLEMENTED in request-signing-vectors.test.js
- Bump hardcoded vector counts 26 → 27 in grader + runner-integration tests
- Skip vector 027 in grader-e2e + grader-mcp (the reference verifier hasn't
  implemented the "unsigned webhook registration with authentication"
  rejection yet — tracked in the same follow-up as 021-026's skip rationale)

Unrelated to the #679 CLI change but required to unblock this PR's CI.
Also catches main up to current upstream.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley added a commit that referenced this pull request Apr 21, 2026
…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]>
…iver-cli

# Conflicts:
#	src/lib/testing/storyboard/request-signing/builder.ts
#	src/lib/types/core.generated.ts
#	src/lib/types/schemas.generated.ts
#	test/request-signing-grader-e2e.test.js
#	test/request-signing-grader-mcp.test.js
#	test/request-signing-vectors.test.js
@bokelley
bokelley merged commit a4b8eb8 into main Apr 21, 2026
13 checks passed
@bokelley
bokelley deleted the bokelley/webhook-receiver-cli branch April 21, 2026 09:34
bokelley added a commit that referenced this pull request Apr 21, 2026
…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]>
bokelley added a commit that referenced this pull request Apr 21, 2026
* docs(proposals): webhook-grading reachability — tunnel vs sockets vs 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]>

* feat(cli): --webhook-receiver-auto-tunnel for remote-agent grading

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]>

* docs(proposals): trim reachability doc, link rendezvous to spec-repo 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]>

* fix(cli): auto-tunnel review fixes — URL marker, persistent cleanup, 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]>

* docs: drop in-repo webhook-reachability proposal

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]>

* fix(cli): auto-tunnel E2E fixes — ngrok regex + SIGKILL escalation

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]>

* fix(cli): auto-tunnel — chunk-boundary buffer + cleanup polish

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]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

adcp storyboard run: expose webhook_receiver option so expect_webhook steps can actually grade

1 participant