fed-sx-m2: Step 8f — live HTTP delivery dispatch (+ 10 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 36s

Closes Step 8 (except 8b-timer which still gates on Blockers #3
send_after). New next/kernel/dispatch_http.erl wires the BIF
landed in Step 8e into a delivery_worker-shaped dispatch_fn.

dispatch_http API:
  make_dispatch_fn(PeerId, Cfg) -> fun((Activity) -> ok | {error,_})
  dispatch(Url, Activity, Cfg) -> ok | {error, _}
  inbox_url(BaseUrl, PeerAtom) -> <Base>/actors/<peer>/inbox
  resolve_peer_url(PeerId, Cfg) -> {ok, Base} | {error, no_peer_url}
  content_type/0 -> <<"application/vnd.fed-sx.activity">>

Peer URL resolution composes:
  {peer_url,    [{PeerId, BaseUrl}, ...]}   static map (tests)
  {peer_url_fn, fun ((PeerId) -> {ok, Url} | not_found)}  closure
                                            (Step 10c peer_actors)

Result mapping at dispatch/3:
  2xx           -> ok                    (worker drops the entry)
  non-2xx       -> {error, {status, N}}  (worker bumps attempt)
  resolver miss -> {error, no_peer_url}
  transport     -> {error, Reason}       (BIF re-raises, caught here)

httpc:request/4 BIF wrapper updated to catch host Eval_error via
SX `guard` and re-raise as Erlang `error:{network, ReasonBinary}`
so callers can handle it through standard try/catch — previously
the host exception bubbled past the Erlang try/catch surface
(which only handles er-thrown? / er-errored? / er-exited? markers).

Subtle Erlang-port note documented in dispatch/3: this port's
try/catch requires a literal class atom (`error:Reason`); the
generic `Class:Reason` syntax is not supported. dispatch_http
catches `error:Reason` only, which is what the BIF re-raise
produces.

Test: next/tests/dispatch_http.sh 10/10 against background
python3 http.server (always-200 handler):
  - module loads
  - inbox_url builds /actors/X/inbox
  - static :peer_url map resolves
  - missing peer -> {error, no_peer_url}
  - live POST -> 200 -> ok
  - closure path -> ok
  - closure on missing peer -> {error, no_peer_url}
  - closed port -> {error, _}
  - delivery_worker drains the queue via the live closure
  - :peer_url_fn closure path resolves

No-regression gates green: Erlang conformance 761/761,
httpc_request 10/10, http_listen_bif 5/5, delivery_worker 17/17,
delivery_retry 11/11, delivery_dispatch 7/7.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-07 11:20:53 +00:00
parent bd2c61367d
commit 57684c4589
4 changed files with 378 additions and 14 deletions

View File

@@ -606,10 +606,22 @@ a dead-letter list visible via `/admin/dead-letter`.
10/10 pass — registration, badarg validation, live GET 200,
body bytes match, headers proplist shape, 404 surfaces as ok-tuple,
binary method works.
- [ ] **8f** — Real HTTP dispatch through the BIF + content-type
wiring. dispatch_fn for live use becomes a closure over the
peer URL that calls `httpc:request/4` with the signed envelope
bytes as the body.
- [x] **8f** — Real HTTP dispatch through the BIF + content-type
wiring. New `dispatch_http.erl` builds a 1-arity closure suitable
for `delivery_worker:set_dispatch_fn/2`: encodes the activity
with `term_codec:encode/1`, sets `content-type:
application/vnd.fed-sx.activity`, POSTs to
`<base>/actors/<peer>/inbox` via `httpc:request/4`, and maps the
result to `ok` (2xx) / `{error, {status, N}}` (non-2xx) /
`{error, Reason}` (transport). Peer URL resolution composes:
static `:peer_url` proplist, then `:peer_url_fn` closure
(Step 10c will plumb the latter). BIF wrapper updated to
catch host errors via SX `guard` and re-raise as Erlang
`error:{network, ReasonBinary}` so dispatch_http's try/catch
can map them. Test: `next/tests/dispatch_http.sh` 10/10 —
inbox_url construction, both peer-resolver paths,
hit/miss/closed-port outcomes, delivery_worker drain via
the live closure.
**Tests:**
@@ -1060,6 +1072,45 @@ proceed.
Newest first.
- **2026-06-07** — Step 8f (closes Step 8 except 8b-timer which
still gates on Blockers #3 send_after): live HTTP dispatch
through `httpc:request/4`. New `next/kernel/dispatch_http.erl`
exposes `make_dispatch_fn/2`, `dispatch/3`, `inbox_url/2`,
`resolve_peer_url/2`, `content_type/0`. The closure encodes
the Activity with `term_codec:encode/1`, sets
`content-type: application/vnd.fed-sx.activity`, builds the
URL as `<BaseUrl>/actors/<peer-atom>/inbox`, and POSTs via
the Step 8e BIF wrapper. Result mapping: 2xx → `ok`; non-2xx
→ `{error, {status, N}}`; transport (DNS / connect / bad URL
/ socket closed) → `{error, Reason}` after the wrapper's
Erlang `error:{network, ReasonBinary}` is caught locally.
Cfg resolves the peer base URL through a static `:peer_url`
proplist first, then a `:peer_url_fn` closure as fallback
(Step 10c will plumb a peer_actors-cache-backed one). BIF
wrapper in `lib/erlang/runtime.sx` updated to catch host
errors via SX `guard` and re-raise as Erlang
`error:{network, ReasonBinary}` — the host's plain
`Eval_error` was previously bubbling past the Erlang
try/catch surface (which only handles `er-thrown?` /
`er-errored?` / `er-exited?` markers).
Subtle Erlang-port note: this port's `try/catch` requires a
literal class atom (`error:Reason`), not a variable
`Class:Reason`; dispatch_http catches `error:Reason` only,
which is what the BIF re-raise produces.
Test: `next/tests/dispatch_http.sh` 10/10 — module loads,
inbox_url builds `/actors/X/inbox`, static + closure peer
resolvers, live POST against background `python3 -m
http.server` (always-200 handler) returns ok, missing peer
surfaces as `{error, no_peer_url}`, closed port surfaces as
`{error, _}`, delivery_worker drains the queue via the
live closure. Closes Step 8 except 8b-timer.
Adjacent gates: Erlang conformance 761/761, httpc_request
10/10, http_listen_bif 5/5, delivery_worker 17/17,
delivery_retry 11/11, delivery_dispatch 7/7 — all green.
- **2026-06-07** — Step 8e (closes the BIF half of Step 8;
live HTTP dispatch in 8f next): `httpc:request/4` BIF wrapper
landed in `lib/erlang/runtime.sx` (briefing-allowed-exception