/ Stream
build 2026.12.03 · --:--:-- UTC · RSS

BabbTools for the frontier.

mascot mascot
All materials

Reader A/B Discriminator — IN/IS/MAY/TO as typed guarded rewrites + recursive delegation

READERS-DISCRIMINATOR-REPORT.md View the source file

Stage D prep, local only. Python stdlib only. No GitHub writes, no Lab tool work. Sources: babbworks/stream main 5d18970, notes 12 (§4, BKL-03), 15 (§5), 16 (§4–§5), 18 (§8–§9), 19 (§3–§4).

Files

~/workspace/stream-unfolding-work/readers/
  rewrites.py                      shared spec data: the four rewrite specs,
                                   kind registry, can rules (A form),
                                   can derived definition (B form),
                                   bundles RW + DL
  discriminator.py                 DiscReaderA / DiscReaderB subclasses,
                                   rewrite entry points, D1–D5 scenarios,
                                   rewrite probes, driver (writes the log)
  test_discriminator.py            14 stdlib-unittest tests (new)
  discriminator-log.txt            full driver run log
  READERS-DISCRIMINATOR-REPORT.md  this report

Run: python3 discriminator.py; python3 test_discriminator.py (14 tests, all pass); python3 test_readers.py (15 tests, all still pass — the existing readers, transcript, driver and tests were not modified).

Discriminator outcome (one sentence)

The four rewrites do not separate A from B on forest-shaped data — all 19 IN/IS/MAY/TO probes return identical outcomes in both readers — but recursive delegation does: on branching delegation A admits the second delegator and the move while B refuses both, so the discriminator separates A from B only at MAY's recursive can, not at the four families as such.

What was built

The four rewrites (rewrites.py + discriminator.py)

Each family is a typed guarded rewrite: typed operands checked first, a named guard list in fixed order, then an atomic consume/produce delta B' = (B ∖ C) ∪ A with immutable append to H (note 19 §4: this delta is execution machinery shared by all four families, "not the entire meaning of each family"). Signatures and direction follow note 12 §4; the candidate equations follow note 19 §3 (IN_B(x,S), IS_k(x,v,S), MAY_P(a,tau,S), TO_tau(S,S')).

FamilyRewrite (op)Guards (in order)Effect
INinto: open membership; out: close named membershiptyped Refs; entity/boundary exist; distinct; into: no current membership, no cycle; out: matched live parent occurrenceinto: produce parent(x,B); out: retire it
ISassert; supersede/withdraw (named target)typed (Ref, Kind, Value); kind in registry; entity exists; assert on single-valued kind: no live conflicting claim; supersede: target live, same subject+kind, value differsassert: produce says(caller,subj,kind,val); supersede: retire target, produce new says; withdraw: retire target
MAYgrant; revoke (named grant); delegatetyped; holder is principal; action active; scope is a boundary; grant: one-use occurrence; revoke: named live grant, caller bound to holder or steward; delegate: delegator authorized (can), depth strictly decreases, (B only) single delegatorgrant: produce grant/one_use_grant; revoke: retire it; delegate: produce delegate(q,p,action,scope,depth)
TOtransfer (paired)typed (Occ, Occ, positive Int); distinct accounts; unit match; sufficient funds; exact range; conservation on the staged deltaretire both balances; produce balance(i,u,x−q), balance(j,u,y+q)

Shared machinery (note 18 §9's marking): typed operands, occurrence addressing, the atomic consume/produce delta, immutable H append. Distinct laws: IN topology/acyclicity; IS kind typing + conflict state; MAY grant/delegation/revocation policy (including the recursive can); TO exact units + paired conservation.

New actions, admitted through the normal propose/activate path in bundles RW (detach, supersede, withdraw, revoke) and DL (delegate, move_via_delegation): each reader implements them as _act_* handlers on a subclass; no core reader code was touched.

The recursive-delegation example (D1–D5)

can(P,A,S) — P may do action A in scope S — is the MAY family's recursive core (note 12: "no general permission-transitivity law is assumed"; BKL-03: child subsumption by action subset, nested scope, contained validity interval, strictly smaller remaining delegation depth). Root grants confer depth 3 (MAX_DELEG_DEPTH); each delegation must strictly decrease it.

  • Reader A admits can as two positive rules (note 15 §5 safe): can-base: can(P,A,S) :- grant(G,P,A,S2,R), within(S,S2) and can-deleg: can(P,A,S) :- delegate(Q,P,A,S2,D), can(Q,A,S), within(S,S2). Scope narrows down the chain; the within atom in can-base is load-bearing — D2 caught the first version (exact scope match) failing, because a grant scoped to R must authorize a delegation scoped to B.
  • Reader B refuses both rules as rules at proposal time and records the translation (translation DL: can-base (can) -- recursive: refused as rule, translated to derived definition; same for can-deleg), evaluating can instead as the supplied delegation-walk derived definition: follow the delegatee's single delegator slot toward a root grant, checking at every edge that the requested scope lies within the edge scope and depth strictly increases toward the root, checking the root grant before following the slot (cycle-safe order). The walk lives in a derived index, delegate_slot, rebuilt from base after every accepted invoke — the same index-vs-view shape as B's parent_slot.

Per-reader results

Setup for every scenario (both readers, identical): transcript through L:13 (F + D active), RW + DL proposed and activated, Q1/Q2 made, bound (CQ1/CQ2), root-granted move in scope R. Refs: R=1, B=3, A=5, C=7, P=9, Q1=15, Q2=17 (birth occurrence addresses).

D1 — linear delegation (Q1 → P, scope R, depth 2; P moves A B→C)

ObservableAB
delegateaccepted, occ #23accepted, occ #23
can(P,move,R) beforeTrueTrue
witnessrule can-deleg ← base #23 + can(Q1) ← can-base ← base #21 + within(R,R)chain [9, 15]
move A B→Caccepted; retired #12 (parent) + #23 (delegate)accepted; same
can(P,move,R) afterFalse (one-use capability consumed)False
Q1 root grant live afterTrue (a delegated use does not consume the root grant)True
parents after{(B,R),(A,C),(C,B)}identical

Agree on every observable. Cost of the can query: A 294 rule applications / 42 closure iterations (full closure recomputed per query, as in the transcript comparison); B 5 walk steps / 11 derived queries. Where the translation obligation lands for B: (1) the bundle author must supply can as a delegation-walk derived definition — B never invents it; (2) B's reader code needs a new walk (_can, delegate_slot, _rebuild_delegate_slot) — the translation is not data-only, each new recursive shape needs new reader code, whereas A needs only new rules as data; (3) the walk's validity conditions (scope nesting, depth order, root-grant-first order) must be re-implemented in the walk, duplicating logic A gets from the rules.

D2 — branching delegation (THE separation)

Q1 → P (scope B, depth 2), then Q2 → P (scope R, depth 2); the move is C B→R, which needs scope R (scope B does not contain R).

ObservableAB
delegate Q1→P (scope B)accepted, occ #23accepted, occ #23
delegate Q2→P (scope R)accepted, occ #24REFUSED [multi_parent_delegation] — "delegatee 9 already has a delegator for action move (15); a second delegator has no covering derived definition"
live delegate edges#23 (Q1,B) + #24 (Q2,R)#23 only
can(P,move,R)True (via Q2)False (only chain is Q1 scope B; within(R,B) false)
can(P,move,B)TrueTrue (B keeps the Q1 chain)
move C B→Raccepted; retired #13 + #24; parents {(B,R),(A,B),(C,R)}REFUSED [target_outside_scope] — target 1 is not within scope 3; parents unchanged {(B,R),(A,B),(C,B)}

The mechanism, exactly: B's can is an ancestor-walk over a single-parent delegation forest — one delegator per (delegatee, action), stored in delegate_slot. Two delegators for the same action is not a forest, so B refuses the second delegation at the action guard as a representation refusal, not a domain-law refusal. A derives can by closure over a relation, so disjunction over delegators (either chain suffices) falls out of the fixed point. The separation is observable on an outcome (accept vs refuse of the same move), not only on internal state.

D3 — 2-cycle delegation (Q1 → P, then P → Q1 at depth 1)

Both readers accept the back-delegation, derive can(P) and can(Q1), and accept the move A B→C. A 2-cycle with a root grant in it is harmless in both: A's least fixed point terminates (nothing is derived from the cycle alone), and B's walk checks the root grant before following the delegator slot, so it never follows the cycle. (A cycle with no root grant cannot form through the guarded actions at all: delegate requires can(delegator) first, so an unauthorized delegator is refused [delegator_not_authorized] in both — tested.)

D4 — depth enforcement at issuance

P (remaining depth 2) delegating at depth 2 is refused [bad_depth] in both (not strictly smaller, note 12 BKL-03); delegating at depth 1 is accepted in both. Depth is enforced by the shared action guard in both readers.

D5 — over-depth edge, harness-seeded (second separation)

A delegate(Q1,P,move,R,depth=99) fact is written straight into base, bypassing the delegate guard (marked harness-seeded, as with the Books balance seeding). Then:

ObservableAB
can(P,move,R)TrueFalse

A's rules do not re-check depth at query time (note 15 rules carry no arithmetic), so the malformed edge is honoured. B's walk re-checks depth at query time (last edge depth must be < MAX_DELEG_DEPTH = 3 at the root grant), so it is rejected. This separates query-time re-validation, not the guarded actions — through the delegate action both readers agree (D4), because a depth-99 edge can never enter the log that way. It is a robustness property of admitted data, and it cuts in B's favour: B re-validates more at query time (depth), while A re-validates scope (via within in the rules) but not depth.

Rewrite probes — all 19 agree

ProbeAB
IN into X→C / out X→Caccepted / acceptedaccepted / accepted
IN into A→C (second parent)REFUSED [already_parented]REFUSED [already_parented]
IN out A→R (unmatched)REFUSED [unmatched_close]REFUSED [unmatched_close]
IS assert height(P)=180acceptedaccepted
IS assert height(P)=190REFUSED [conflicting_claim] (names live occ)identical
IS assert note(P) ×2 (multi)acceptedaccepted
IS supersede height 180→181accepted (retires target)accepted
IS withdraw noteacceptedaccepted
IS assert unknown kindREFUSED [unknown_kind]identical
MAY grant P move scope Cacceptedaccepted
MAY revoke by stranger CQ1REFUSED [caller_not_bound]identical
MAY revoke by holder CPacceptedaccepted
MAY revoke again (spent)REFUSED [unknown_occurrence]identical
TO transfer 400 (conserves)accepted, 600+650=1250accepted
TO transfer 2000REFUSED [insufficient_funds]identical
TO transfer 2⁶²REFUSED [overflow]identical
TO transfer cross-unitREFUSED [unit_mismatch]identical
TO transfer qty 0REFUSED [bad_quantity]identical

Two notes on the IN probes. First, the second-parent refusal fires at the action guard (already_parented) in both readers, before A's post-state unique_parent constraint — so IN does not separate on outcomes; the difference is architectural and shown by inspection, not by a run: in A, unique-parent is a check over base facts (a law a bundle could change); in B it is the parent_slot representation itself (unrepresentable without a new representation). Second, the same holds for the TO probes: TO is shared machinery (the guarded consume/produce delta) in both readers, and the multi-leg / chained settlement extension past paired transfer is unbuilt in both.

What it does NOT prove

  • Not a general separation of the four families. IN, IS and TO as implemented here, and MAY's grant/revoke, coincide exactly on every probe. The discriminator separates only MAY's recursive can under branching, plus the D5 query-time depth re-validation for harness-seeded data. A reader that only ever sees linear delegation chains and guarded actions cannot be told apart from A by any test in this batch.
  • Not that B is sufficient for STREAM. The D2 case is one branching shape; delegation-through-derived-membership (a join, e.g. authority via group membership + grant), multi-parent membership, arbitrary graph reachability, and the matrix's row-crossing operations are still unexpressed in both readers, and B's restrictions on those are untested. Per note 18 §6, A stays the reference semantics.
  • Not that A is safe as written. D5 shows A's can rules trust admission-time guards for depth: a malformed delegate edge admitted by any other path (older bundle version, direct import, a bug in a future delegate action) is honoured at query time. If depth is a load-bearing law, it needs either a query-time check outside the rules or a proof that no admission path can produce a bad edge.
  • Not a cost verdict. The metering (A: 294 rule applications per can query on this tiny state; B: 5 walk steps) repeats the transcript comparison's finding — A recomputes the whole closure per query — but the states here are toy-sized, and neither reader was optimized. The cost gap is real in shape (per-closure vs per-chain) and unmeasured at any realistic size.
  • Not byte compatibility. B runs the same bundles only because the translations were supplied in the bundle data and the new walks were written in B's code. The DL bundle is one input with two readings, exactly as note 18 §6 warns.
  • Scope of the kind registry. IS kinds are a two-entry registry (height single, note multi) invented for this experiment; no claim is made about STREAM's real kinds, conflict rules, or supersession policy.

Bugs caught while building (recorded, as in the comparison)

  1. can-base first required exact scope match (grant(G,P,A,S,R)), so a root grant scoped to R did not authorize a delegation scoped to B and D2 failed at the first delegation in A. Fixed by adding within(S,S2) to can-base — the subsumption atom is load-bearing, and the failure is what proved it.
  2. authority_depth first break out of its scan after the first grant row, skipping delegate edges entirely. Restructured into two clean passes (grants, then delegate edges).
  3. A test expectation bug (fresh-reader active set is ["DL","RW"], not the full transcript set) — test-only, no reader code involved.

Sharpest remaining difference between A and B

A derives authority from data (rules + closure: disjunction, joins and recursion fall out of the fixed point), while B derives it from shape (one walk over one single-parent forest per predicate): anything whose authority needs two parents, a join, or a second recursive predicate is representable in A as a rule and unrepresentable in B without new reader code — and the translation obligation for each such shape lands twice, once on the bundle author (supply the derived definition) and once on the reader implementer (write the walk).