{
 "approach": "Ran B (sha baef955e...) on seeds 230000..230999 with default ChallengeConfig/ParameterVariance, one run_batch per seed, serial in-process (several OS processes on disjoint seed ranges). Instrumentation: a copy of B's source with tag-only edits (each out.append(PlaceOrder(...)) wrapped by an identity function that records its class; ammo branch label recorded in a dict), plus wrappers on PredictionMarket.place_order (map new order_id -> class) and record_participant_fills (recompute each fill's edge with the simulator's own formula, split by aggressor retail/arb, then call the original). Outcomes unchanged: total/retail/arb/failed identical on seeds 230000..230019 with and without instrumentation; per-seed class sums reconcile to total_edge within 4e-9 on all 1000 seeds. count = number of participant fills in the class across all 1000 sims.",
 "tried": [
  "Uninstrumented vs instrumented on 20 seeds: identical edges (all 20 equal exactly).",
  "Full 1000-seed block, per-class retail and arb attribution."
 ],
 "next": [
  "Remove or gate the tick-1 bank (ydf1=0, or only when the competitor spread s>1): it shows -4.18 +/- 0.67 per sim directly (arb -4.26, retail +0.09), 17% of all arbitrage loss for 0.1% of retail. Its indirect value (YES it supplies to cover low main asks) is not measured here, so a paired A/B is needed; at stake up to ~4 per sim.",
  "Cut adverse selection on the main quotes, which carry 75% of arb loss: main ask -11.26/sim (45%) and main bid -7.44/sim (30%). A jump/stale-quote guard (pull or shrink the main quote for a step after a competitor jump or probe evidence of a move) targets ~18.7/sim of arb loss; even a 20% cut is ~3.7/sim if retail is kept."
 ],
 "code": "# harness.py\nimport sys, json, time, math, hashlib, importlib.util\nsys.path.insert(0, sys.argv[1])  # simulator dir\nfrom orderbook_pm_challenge import market as M\nfrom orderbook_pm_challenge.runner import run_batch\nfrom orderbook_pm_challenge.config import ChallengeConfig, ParameterVariance\nfrom orderbook_pm_challenge.loader import load_strategy_factory\nfrom orderbook_pm_challenge.types import Side\nB_PATH, mode, s0, s1, out = sys.argv[2], sys.argv[3], int(sys.argv[4]), int(sys.argv[5]), sys.argv[6]\nsrc = open(B_PATH, encoding='utf-8').read()\nassert hashlib.sha256(src.encode()).hexdigest() == 'baef955ec10728839f7c3357016ec9eb0550e7ec689bbd5171b1cdd5c9e37273'\nCLASSES = ['main_bid','main_ask','premium_cover','cross_at_tick','cross_rest_below','tick1_bank','probe_bid','probe_ask','other']\ndef rep(s, a, b):\n    assert s.count(a) == 1, a; return s.replace(a, b)\nif mode == 'inst':\n    # Tag-only edits: record which branch created each PlaceOrder; no value or control flow changes.\n    s = src\n    s = rep(s, \"amt, qam = t, min(P['qf'], full - Y)     #\", \"amt, qam = t, min(P['qf'], full - Y); _TAG['amm'] = 'cross_at_tick'     #\")\n    s = rep(s, \"amt, qam = t, min(P['ammo_q'], target - Y)\\n\", \"amt, qam = t, min(P['ammo_q'], target - Y); _TAG['amm'] = 'premium_cover'\\n\")\n    s = rep(s, \"amt, qam = t - 1, min(P['qf'], full - Y)  #\", \"amt, qam = t - 1, min(P['qf'], full - Y); _TAG['amm'] = 'cross_rest_below'  #\")\n    s = rep(s, \"amt, qam = 1, min(P['ammo_q'], P['pre'] - Y)\", \"amt, qam = 1, min(P['ammo_q'], P['pre'] - Y); _TAG['amm'] = 'other'\")\n    s = rep(s, \"out.append(PlaceOrder(side=Side.BUY, price_ticks=1, quantity=fl(q1)))\", \"out.append(_T(PlaceOrder(side=Side.BUY, price_ticks=1, quantity=fl(q1)), 'tick1_bank'))\")\n    s = rep(s, \"out.append(PlaceOrder(side=Side.BUY, price_ticks=amt, quantity=q))\", \"out.append(_T(PlaceOrder(side=Side.BUY, price_ticks=amt, quantity=q), _TAG['amm']))\")\n    s = rep(s, \"out.append(PlaceOrder(side=Side.BUY, price_ticks=bid_t, quantity=q, client_order_id=oid))\", \"out.append(_T(PlaceOrder(side=Side.BUY, price_ticks=bid_t, quantity=q, client_order_id=oid), 'main_bid'))\")\n    s = rep(s, \"out.append(PlaceOrder(side=Side.SELL, price_ticks=ask_t, quantity=q, client_order_id=oid))\", \"out.append(_T(PlaceOrder(side=Side.SELL, price_ticks=ask_t, quantity=q, client_order_id=oid), 'main_ask'))\")\n    s = rep(s, \"out.append(PlaceOrder(side=Side.BUY, price_ticks=t, quantity=PROBE))\", \"out.append(_T(PlaceOrder(side=Side.BUY, price_ticks=t, quantity=PROBE), 'probe_bid'))\")\n    s = rep(s, \"out.append(PlaceOrder(side=Side.SELL, price_ticks=t, quantity=PROBE))\", \"out.append(_T(PlaceOrder(side=Side.SELL, price_ticks=t, quantity=PROBE), 'probe_ask'))\")\n    s = rep(s, \"        amt = 0\\n\", \"        amt = 0\\n        _TAG['amm'] = 'other'\\n\")\n    PEND = {}\n    def _T(a, c): PEND[id(a)] = (a, c); return a\n    ns = {'_T': _T, '_TAG': {}}\n    exec(compile(s, 'B_inst', 'exec'), ns)\n    Strat = ns['Strategy']\n    factory = lambda: Strat()\n    CLS = {}; ACC = {}\n    orig_place = M.PredictionMarket.place_order\n    def place_order(self, action, *, step):\n        n0 = len(self._participant_order_ids)\n        before = set(self._participant_order_ids)\n        orig_place(self, action, step=step)\n        new = self._participant_order_ids - before\n        t = PEND.pop(id(action), (None, 'other'))[1]\n        for oid in new: CLS[oid] = t\n    M.PredictionMarket.place_order = place_order\n    orig_rec = M.PredictionMarket.record_participant_fills\n    def rec(self, fills, *, probability):\n        for f in fills:\n            price = f.price_ticks / 100.0\n            e = f.quantity * (probability - price) if f.side is Side.BUY else f.quantity * (price - probability)\n            c = CLS.get(f.order_id, 'other')\n            a = ACC.setdefault(c, [0.0, 0.0, 0, 0.0])\n            if f.aggressor == M.RETAIL: a[0] += e\n            elif f.aggressor == M.ARB: a[1] += e\n            a[2] += 1; a[3] += f.quantity\n        return orig_rec(self, fills, probability=probability)\n    M.PredictionMarket.record_participant_fills = rec\nelse:\n    factory = load_strategy_factory(B_PATH)\nrows = []\nt0 = time.time()\nfor sd in range(s0, s1):\n    if mode == 'inst': CLS.clear(); ACC.clear(); PEND.clear()\n    r = run_batch(factory, base_config=ChallengeConfig(), variance=ParameterVariance(), n_simulations=1, seed_start=sd, workers=1)\n    x = r.simulation_results[0] if hasattr(r, 'simulation_results') else r.results[0]\n    row = dict(seed=sd, total=x.total_edge, retail=x.retail_edge, arb=x.arb_edge, failed=bool(getattr(x, 'failed', False)))\n    if mode == 'inst': row['cls'] = {k: v[:] for k, v in ACC.items()}\n    rows.append(row)\njson.dump(dict(secs=time.time() - t0, rows=rows), open(out, 'w'))\n\n# agg.py\nimport json,glob,math,sys\nrows=[]\nsecs=0\nfor f in sorted(glob.glob('c_*.json')):\n    d=json.load(open(f)); rows+=d['rows']; secs+=d['secs']\nrows.sort(key=lambda r:r['seed']); n=len(rows)\nassert [r['seed'] for r in rows]==list(range(230000,231000))\ndef ms(x):\n    m=sum(x)/len(x); v=sum((a-m)**2 for a in x)/(len(x)-1); return m, math.sqrt(v/len(x))\nT=[r['total'] for r in rows]; m,se=ms(T)\nprint('inc',m,se,ms([r['retail'] for r in rows])[0],ms([r['arb'] for r in rows])[0],sum(r['failed'] for r in rows))\nmx=max(abs(r['total']-sum(v[0]+v[1] for v in r['cls'].values())) for r in rows); print('recon',mx)\ncls=['main_bid','main_ask','premium_cover','cross_at_tick','cross_rest_below','tick1_bank','probe_bid','probe_ask','other']\nout=[]\nfor c in cls+['probes']:\n    g=lambda r,i:(sum(r['cls'].get(k,[0,0,0,0])[i] for k in ('probe_bid','probe_ask')) if c=='probes' else r['cls'].get(c,[0,0,0,0])[i])\n    ret=[g(r,0) for r in rows]; arb=[g(r,1) for r in rows]; tot=[a+b for a,b in zip(ret,arb)]\n    mt,st=ms(tot); mr,sr=ms(ret); ma,sa=ms(arb)\n    out.append(dict(name=c, fills_total=int(sum(g(r,2) for r in rows)), sims_with_fills=sum(1 for r in rows if g(r,2)>0),\n      shares_per_sim=round(sum(g(r,3) for r in rows)/n,2), mean=round(mt,3), se=round(st,3), retail_mean=round(mr,3), retail_se=round(sr,3),\n      arb_mean=round(ma,3), arb_se=round(sa,3), share_of_total=round(mt/m,4), share_of_retail=round(mr/ms([r['retail'] for r in rows])[0],4), share_of_arb=round(ma/ms([r['arb'] for r in rows])[0],4)))\nfor o in out: print(o)\njson.dump(dict(n=n,mean=m,se=se,retail=ms([r['retail'] for r in rows]),arb=ms([r['arb'] for r in rows]),secs=secs,failures=sum(r['failed'] for r in rows),rows=out),open('agg.json','w'))\n",
 "code_sha256": "279362c36f7b5e82e526363f9ef297b2f71b5db27923ebe0b1e2ff64bdb3ed2a",
 "incumbent_code_sha256": "baef955ec10728839f7c3357016ec9eb0550e7ec689bbd5171b1cdd5c9e37273",
 "tuning": null,
 "seeds": "230000..230999",
 "n": 1000,
 "complete": true,
 "incumbent": {
  "mean": 87.289,
  "retail_mean": 112.406,
  "arb_mean": -25.117,
  "se": 4.828,
  "retail_se": 5.083,
  "arb_se": 1.761
 },
 "findings": [
  {
   "sims_with_fills": 993,
   "shares_per_sim": 3943.67,
   "mean": 14.487,
   "se": 0.623,
   "retail_mean": 21.929,
   "retail_se": 0.7,
   "arb_mean": -7.442,
   "arb_se": 0.265,
   "share_of_total": 0.166,
   "share_of_retail": 0.1951,
   "share_of_arb": 0.2963,
   "class": "main_bid",
   "name": "main bid",
   "count": 200626
  },
  {
   "sims_with_fills": 994,
   "shares_per_sim": 6481.88,
   "mean": 78.74,
   "se": 4.935,
   "retail_mean": 90.001,
   "retail_se": 4.769,
   "arb_mean": -11.262,
   "arb_se": 1.487,
   "share_of_total": 0.9021,
   "share_of_retail": 0.8007,
   "share_of_arb": 0.4484,
   "class": "main_ask",
   "name": "main ask",
   "count": 204910
  },
  {
   "sims_with_fills": 100,
   "shares_per_sim": 91.45,
   "mean": -0.757,
   "se": 0.207,
   "retail_mean": 0.0,
   "retail_se": 0.0,
   "arb_mean": -0.758,
   "arb_se": 0.207,
   "share_of_total": -0.0087,
   "share_of_retail": 0.0,
   "share_of_arb": 0.0302,
   "class": "premium_cover",
   "name": "premium cover purchase (ammo branch 2: pays up to ammo_maxpay above p)",
   "count": 1750
  },
  {
   "sims_with_fills": 157,
   "shares_per_sim": 203.3,
   "mean": -0.389,
   "se": 0.043,
   "retail_mean": 0.015,
   "retail_se": 0.008,
   "arb_mean": -0.404,
   "arb_se": 0.043,
   "share_of_total": -0.0045,
   "share_of_retail": 0.0001,
   "share_of_arb": 0.0161,
   "class": "cross_at_tick",
   "name": "crossing purchase at the tick p just crossed (ammo branch 1)",
   "count": 555
  },
  {
   "sims_with_fills": 251,
   "shares_per_sim": 434.98,
   "mean": -0.157,
   "se": 0.046,
   "retail_mean": 0.347,
   "retail_se": 0.039,
   "arb_mean": -0.504,
   "arb_se": 0.045,
   "share_of_total": -0.0018,
   "share_of_retail": 0.0031,
   "share_of_arb": 0.0201,
   "class": "cross_rest_below",
   "name": "crossing purchase resting one tick under p (ammo branch 3)",
   "count": 2016
  },
  {
   "sims_with_fills": 355,
   "shares_per_sim": 3764.17,
   "mean": -4.178,
   "se": 0.669,
   "retail_mean": 0.086,
   "retail_se": 0.039,
   "arb_mean": -4.263,
   "arb_se": 0.668,
   "share_of_total": -0.0479,
   "share_of_retail": 0.0008,
   "share_of_arb": 0.1697,
   "class": "tick1_bank",
   "name": "tick-1 bank (q1)",
   "count": 664
  },
  {
   "sims_with_fills": 1000,
   "shares_per_sim": 22.38,
   "mean": -0.224,
   "se": 0.004,
   "retail_mean": 0.013,
   "retail_se": 0.0,
   "arb_mean": -0.238,
   "arb_se": 0.004,
   "share_of_total": -0.0026,
   "share_of_retail": 0.0001,
   "share_of_arb": 0.0095,
   "class": "probe_bid",
   "name": "probe bids",
   "count": 2238249
  },
  {
   "sims_with_fills": 1000,
   "shares_per_sim": 22.97,
   "mean": -0.234,
   "se": 0.004,
   "retail_mean": 0.013,
   "retail_se": 0.0,
   "arb_mean": -0.247,
   "arb_se": 0.005,
   "share_of_total": -0.0027,
   "share_of_retail": 0.0001,
   "share_of_arb": 0.0098,
   "class": "probe_ask",
   "name": "probe asks",
   "count": 2297010
  },
  {
   "sims_with_fills": 0,
   "shares_per_sim": 0.0,
   "mean": 0.0,
   "se": 0.0,
   "retail_mean": 0.0,
   "retail_se": 0.0,
   "arb_mean": 0.0,
   "arb_se": 0.0,
   "share_of_total": 0.0,
   "share_of_retail": 0.0,
   "share_of_arb": -0.0,
   "class": "other",
   "name": "other (pre branch; disabled, pre=0)",
   "count": 0
  },
  {
   "sims_with_fills": 1000,
   "shares_per_sim": 45.35,
   "mean": -0.458,
   "se": 0.008,
   "retail_mean": 0.026,
   "retail_se": 0.0,
   "arb_mean": -0.484,
   "arb_se": 0.008,
   "share_of_total": -0.0052,
   "share_of_retail": 0.0002,
   "share_of_arb": 0.0193,
   "class": "probes",
   "name": "probes, bid+ask combined",
   "count": 4535259
  }
 ],
 "paired": null,
 "failures": 0,
 "seconds_per_simulation": 1.4,
 "notes": "seconds_per_simulation is single-process wall time on 20 seeds (28 s/20); parallel runs shared about one core (~1 sim/s aggregate). share_of_* = class mean / incumbent mean of total, retail or arb (main ask 90% of total edge, 80% of retail). Shares of arb sum to 1. Premium cover fills only in 100 of 1000 sims, all arbitrage fills. No oracle was run."
}