| 1: Subroutine: Seed Query & Re-Verification 2: function EvalSeed ( xs,δ,Q ) 3: xs′←ϕ(xs,δ) ▹ Eq. ( 5 ) 4: if ¬V(xs,xs′)∨Q≥B then return (⊥,−∞,Q) 5: Query f(S(xs′),Rs,Os)→(P(xs′),y^(xs′),C(xs′)) ; Q←Q+1 6: Compute feedback g(xs′) via Eq. ( 7 ) (or I(y^(xs′)∈Yatt) ) 7: if y^(xs′)∈Yatt∧(¬Gated∨C(xs′)≥τconf)∧Q+2≤B then 8: Query f twice: y^rev(1)(xs′),y^rev(2)(xs′) ; Q←Q+2 9: if 1+∑j=121[y^rev(j)(xs′)∈Yatt]≥2 then 10: return (xs′,g(xs′),Q) 11: end if 12: end if 13: return (⊥,g(xs′),Q) 14: end function 15: Phase 1: Offline Seed Search & Distillation (Sections 4.3 – 4.4 ) 16: Lexp←∅ 17: for each seed task (xs,ys∗,ts)∈Dseed do 18: Compute clean margin M0(xs) (Eq. ( 6 )) and features v(xs) 19: Ψinit←Ψ(Ss,Rs,Os) ; Q←0 , xs∗←⊥ , H←∅ ▹ Stage 1: Init 20: for each (ψ,θ0)∈Ψinit while Q<B∧xs∗=⊥ do ▹ Stage 2: Breadth 21: δ←ψ(xs,Rs,Os,ts;θ0) 22: (xs∗,g,Q)←\textscEvalSeed(xs,δ,Q) 23: if g>−∞ then H←H∪{(ψ,θ0,δ,g)} 24: end for 25: (xs∗,ψ∗,θ∗)←\textscSeedRefine(xs,ts,xs∗,H,Q) ▹ Stages 3–4 26: if xs∗=⊥ then 27: θ∗←DeIdentify(θ∗) ▹ Strip task-specific entities 28: Upsert card ei=(d,ℓ,v(xs),ψ∗,θ∗,sˉi) in Lexp 29: end if 30: end for 31: Freeze Lexp for read-only test-time retrieval | 32: Subroutine: Seed Refinement & Fallback (Stages 3–4) 33: function SeedRefine ( xs,ts,xs∗,H,Q ) 34: if xs∗=⊥∧H=∅∧Q<B then ▹ Stage 3: Refinement 35: (ψ^,θ^,δ^,g^)←argmax(ψ,θ,δ,g)∈Hg 36: for r=1 to Tref while Q<B∧xs∗=⊥ do 37: θ′←Matt(ψ^,xs,Rs,Os,ts,H) ; δ′←ψ^(xs,Rs,Os,ts;θ′) 38: (xs∗,g′,Q)←\textscEvalSeed(xs,δ′,Q) 39: if g′>−∞ then H←H∪{(ψ^,θ′,δ′,g′)} 40: end for 41: end if 42: for r=1 to Tfb while xs∗=⊥∧Q<B do ▹ Stage 4: Fallback 43: Synthesize fact-invariant δfb←Matt(xs,Rs,Os,ts,H) 44: (xs∗,gfb,Q)←\textscEvalSeed(xs,δfb,Q) 45: end for 46: return (xs∗,ψ∗,θ∗) 47: end function 48: Phase 2: Test-Time One-Step Retrieval & Construction (Section 4.4 ) 49: Extract structural features v(x) without pre-querying f 50: Select top- k distinct- ψ cards Ktop by RS(ei∣x) (Eq. ( 9 )) 51: Pctx←Ktop if Ktop=∅ else Ψfb 52: Construct fact-invariant δ←Matt(x,R,O,t,Pctx) in one pass 53: x′←ϕ(x,δ) ; evaluate f(S(x′),R,O) ( 2/3 repeat check on flip) 54: Phase 3: Online Dual-System Agent Auditing (Section 4.1 ) 55: Restore dual-system agent (S1 f , generative S2) to prefix h 56: if workflow is Tool Router then 57: Inject δ into tool output x ; y^(x′)←π(P(x′)) ; S2 generates args 58: else if workflow is Action Authorization then 59: S2 proposes action a from clean records; inject δ into note x for f 60: end if 61: Verify exact input match against S(x′) ; execute E(h,x′,y^(x′)) 62: Record I(y^(x′)∈Yatt) and Φviol(E(h,x′,y^(x′)))=1 ▹ Eq. ( 4 ) 63: return Lexp , constructed x′ , and node/E2E audit logs |