fed-sx-m2: Step 1b — nx_kernel multi-actor gen_server calls + 9 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s

New gen_server exports add_actor/3, publish_to/2, log_tip_for/1,
actors/0, state_for/1, bucket_for/1, with_projections_for/2 —
each is a thin gen_server:call delegating to 1a's pure-functional
bucket API via fresh handle_call branches. Existing single-actor
calls (publish/1, log_tip/0, with_projections/1) route through
bucket 0 unchanged.

Per-actor mailbox sharding (one gen_server per bucket so distinct-
actor publishes don't serialise on a single mailbox) is forward-
looking — deferred to Step 4 where the per-actor HTTP routing makes
it actually load-bearing. Single-mailbox serialisation is fine for
Steps 1-3.

nx_kernel_multi.sh extended from 17 to 26 cases (gen_server load,
start_link bucket-0 seed, add_actor/3 dup detection, publish_to/2
per-actor isolation, interleaved publishes, no_actor error, state_for
+ with_projections_for round-trips). 134/134 across 12 nx_kernel-
adjacent + http suites. Erlang conformance 761/761 preserved.
This commit is contained in:
2026-06-06 10:25:43 +00:00
parent 6a9bd054c7
commit 089d1445a1
3 changed files with 131 additions and 13 deletions

View File

@@ -108,6 +108,47 @@ cat > "$TMPFILE" <<EPOCHS
;; Legacy new/3 + publish/2 still route to the single actor
(epoch 25)
(eval "(get (erlang-eval-ast \"${PRELUDE} S = nx_kernel:new(alice, AliceKS, AliceAS), {ok, _, S1} = nx_kernel:publish(Req, S), nx_kernel:log_tip(S1) =:= 1 andalso nx_kernel:actor_id(S1) =:= alice\") :name)")
;; ── Step 1b: gen_server multi-actor calls ──────────────────────
;; The Erlang-on-SX scheduler doesn't preserve spawned processes
;; across separate erlang-eval-ast invocations, so each gen_server
;; test inlines start_link with operations (same convention as
;; nx_kernel_server.sh).
(epoch 26)
(eval "(er-load-gen-server!)")
;; start_link works, actors/0 lists the single seeded actor
(epoch 30)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:start_link(alice, AliceKS, AliceAS), nx_kernel:actors() =:= [alice]\") :name)")
;; add_actor/3 (gen_server) -> :ok, actors/0 reflects both
(epoch 31)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:start_link(alice, AliceKS, AliceAS), ok = nx_kernel:add_actor(bob, BobKS, BobAS), nx_kernel:actors() =:= [alice, bob]\") :name)")
;; add_actor/3 duplicate -> {error, already_present}
(epoch 32)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:start_link(alice, AliceKS, AliceAS), case nx_kernel:add_actor(alice, AliceKS, AliceAS) of {error, already_present} -> ok; _ -> bad end\") :name)")
;; publish_to/2 advances only the named actor's log
(epoch 33)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:start_link(alice, AliceKS, AliceAS), nx_kernel:add_actor(bob, BobKS, BobAS), {ok, _} = nx_kernel:publish_to(alice, Req), AliceTip = nx_kernel:log_tip_for(alice), BobTip = nx_kernel:log_tip_for(bob), {AliceTip, BobTip} =:= {1, 0}\") :name)")
;; Interleaved publishes preserve per-actor counters
(epoch 34)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:start_link(alice, AliceKS, AliceAS), nx_kernel:add_actor(bob, BobKS, BobAS), nx_kernel:publish_to(alice, Req), nx_kernel:publish_to(bob, Req), nx_kernel:publish_to(alice, Req), AliceTip = nx_kernel:log_tip_for(alice), BobTip = nx_kernel:log_tip_for(bob), {AliceTip, BobTip} =:= {2, 1}\") :name)")
;; publish_to unknown actor -> {error, no_actor}, no kernel crash
(epoch 35)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:start_link(alice, AliceKS, AliceAS), case nx_kernel:publish_to(ghost, Req) of {error, no_actor} -> ok; _ -> bad end\") :name)")
;; state_for/1 returns the per-actor AS
(epoch 36)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:start_link(alice, AliceKS, AliceAS), nx_kernel:add_actor(bob, BobKS, BobAS), {ok, ASb} = nx_kernel:state_for(bob), ASb =:= BobAS\") :name)")
;; with_projections_for/2 sets per-actor projections, observable via bucket_for
(epoch 37)
(eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:start_link(alice, AliceKS, AliceAS), nx_kernel:add_actor(bob, BobKS, BobAS), nx_kernel:with_projections_for(alice, [px]), {ok, AliceBucket} = nx_kernel:bucket_for(alice), {ok, BobBucket} = nx_kernel:bucket_for(bob), [{projections, AliceP} | _] = lists:filter(fun(P) -> element(1, P) =:= projections end, AliceBucket), [{projections, BobP} | _] = lists:filter(fun(P) -> element(1, P) =:= projections end, BobBucket), {AliceP, BobP} =:= {[px], []}\") :name)")
EPOCHS
OUTPUT=$(timeout 240 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -148,6 +189,15 @@ check 22 "independent next_published seqs" "true"
check 23 "actor_state/2 per-actor" "true"
check 24 "with_actor_projections per-actor" "true"
check 25 "legacy new/3 + publish/2 routes" "true"
check 26 "gen_server loaded" "gen_server"
check 30 "start_link seeds bucket 0" "true"
check 31 "add_actor/3 (srv) -> ok + actors" "true"
check 32 "add_actor/3 duplicate detected" "ok"
check 33 "publish_to/2 isolates per actor" "true"
check 34 "interleaved publishes per actor" "true"
check 35 "publish_to unknown -> no_actor" "ok"
check 36 "state_for/1 per-actor AS" "true"
check 37 "with_projections_for per-actor" "true"
TOTAL=$((PASS+FAIL))
if [ $FAIL -eq 0 ]; then