drizzle 0.1.16

A type-safe SQL query builder for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
name: Runners

on:
  workflow_dispatch:
    inputs:
      benchmark_size:
        description: Benchmark workload to run
        required: false
        type: choice
        options:
          - full
          - preview
          - single
          - saturation
        default: full
      publish_to_r2:
        description: Publish main or release-tag runs to Cloudflare R2
        required: false
        type: boolean
        default: false

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always
  RUST_VERSION: "1.95"
  NODE_VERSION: "24"
  BENCHMARK_SIZE: ${{ inputs.benchmark_size || 'full' }}
  BENCH_COHORT_ID: gh-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.sha }}-throughput-http
  PUBLISH_TO_R2: ${{ inputs.publish_to_r2 && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) }}
  R2_BUCKET: drizzle-bench

# Every family job is a thin caller of `.github/actions/bench-runner-run`, which
# owns the prebuild / run / validate / upload / baseline sequence. `plan`
# resolves the class and workload once so the resolution cannot drift between
# families, and so job-level `if:` can read it (the `env` context is not
# available in `jobs.<id>.if`).
jobs:
  plan:
    name: Plan
    runs-on: ubuntu-latest
    timeout-minutes: 5
    outputs:
      size: ${{ steps.resolve.outputs.size }}
      class: ${{ steps.resolve.outputs.class }}
      workload: ${{ steps.resolve.outputs.workload }}
      publish: ${{ steps.resolve.outputs.publish }}
      paced_trials: ${{ steps.resolve.outputs.paced_trials }}
      cross_family: ${{ steps.resolve.outputs.cross_family }}
      cross_workload: ${{ steps.resolve.outputs.cross_workload }}
      cross_trials: ${{ steps.resolve.outputs.cross_trials }}
    steps:
      - uses: actions/checkout@v6

      - name: Resolve run class and workload
        id: resolve
        shell: bash
        run: |
          size="${BENCHMARK_SIZE}"
          publish="${PUBLISH_TO_R2}"

          class="full"
          workload="bench/spec/workload.throughput.v1.json"
          if [[ "$size" == "preview" && "$publish" != "true" ]]; then
            class="small"
            workload="bench/spec/workload.preview.v1.json"
          elif [[ "$size" == "single" ]]; then
            workload="bench/spec/workload.single-throughput.v1.json"
            if [[ "$publish" == "true" ]]; then
              class="publish"
            fi
          elif [[ "$size" == "saturation" ]]; then
            # Capacity, not latency-at-fixed-load: an unpaced ramp until p99
            # breaches the workload's SLO. This is the only suite that can
            # produce a throughput number at all — the paced suites cap every
            # target at `VUs / think_time`, so their rps describes the load
            # generator rather than the target.
            workload="bench/spec/workload.saturation.v1.json"
            if [[ "$publish" == "true" ]]; then
              class="publish"
            fi
          elif [[ "$publish" == "true" ]]; then
            class="publish"
          fi

          # The workflow now runs only by explicit dispatch. Release creation
          # dispatches a full publish run, while a person can select `preview`
          # from a branch to exercise the topology cheaply. Every run includes
          # the cross-family jobs so the manual and release paths stay identical.
          cross_family="true"

          # The `*-all` jobs always run the saturation ramp, whatever `$workload`
          # resolved to for the per-family jobs. A cross-family ranking needs a
          # number that describes the target, and the paced suites cap every
          # target at `VUs / think_time` — their rps describes the load
          # generator. The paced reading is not lost: the per-family jobs still
          # produce it, and it is what the latency views are built from.
          cross_workload="bench/spec/workload.saturation.v1.json"
          cross_trials="2"
          if [[ "$size" == "preview" ]]; then
            # Smoke-test the topology itself without a five-hour run.
            cross_workload="bench/spec/workload.saturation-preview.v1.json"
            cross_trials="1"
          fi

          # Paced trials: 3 for full/publish, class default (3) for small.
          # 5 trials does not fit any grouped-job structure inside GitHub's
          # 360-minute cancellation (27 targets x 5 x ~7 min is 15.6 h on
          # Linux alone). Measured cost of 3 vs 5 on the recorded five-trial
          # cohorts: rps.avg medians move <=2.6% (median 0.1%), whole-ramp p95
          # <=12.5% (median 1.1%); the sustained-latency reference median is
          # the loosest — its per-trial jitter measured 5-39% on slower
          # targets — and spread.trials discloses the count either way.
          paced_trials=""
          if [[ "$class" != "small" ]]; then
            paced_trials="3"
          fi

          {
            echo "size=$size"
            echo "class=$class"
            echo "workload=$workload"
            echo "publish=$publish"
            echo "paced_trials=$paced_trials"
            echo "cross_family=$cross_family"
            echo "cross_workload=$cross_workload"
            echo "cross_trials=$cross_trials"
          } >> "$GITHUB_OUTPUT"

          echo "size=$size class=$class workload=$workload publish=$publish cross_family=$cross_family"
          echo "cross_workload=$cross_workload cross_trials=$cross_trials"

      # Every benchmark job is a serial sequence of family runs, so any of them
      # can walk into GitHub's hard 360-minute job cancellation. Adding a
      # target to a family spec silently lengthens every job carrying that
      # family. Estimate each job up front and fail the run here, in five
      # minutes, rather than at minute 350 with most of the ranking missing.
      - name: Check per-job time budgets
        shell: bash
        env:
          PACED_WORKLOAD: ${{ steps.resolve.outputs.workload }}
          PACED_TRIALS: ${{ steps.resolve.outputs.paced_trials }}
          CROSS_FAMILY: ${{ steps.resolve.outputs.cross_family }}
          CROSS_WORKLOAD: ${{ steps.resolve.outputs.cross_workload }}
          CROSS_TRIALS: ${{ steps.resolve.outputs.cross_trials }}
          CLASS: ${{ steps.resolve.outputs.class }}
        run: |
          python3 - <<'PY'
          import json, os, sys

          SPEC = {
              "sqlite": "bench/spec/targets.sqlite.v1.json",
              "sqlite-ts": "bench/spec/targets.sqlite-ts.v1.json",
              "libsql": "bench/spec/targets.libsql.v1.json",
              "turso": "bench/spec/targets.turso.v1.json",
              "postgres": "bench/spec/targets.postgres.v1.json",
              "postgres-rust-orms": "bench/spec/targets.postgres-rust-orms.v1.json",
              "postgres-ts": "bench/spec/targets.postgres-ts.v1.json",
              "spacetimedb": "bench/spec/targets.spacetimedb.v1.json",
          }

          small = os.environ["CLASS"] == "small"
          # Empty means "class default", which is 3 for small.
          paced_trials = int(os.environ["PACED_TRIALS"] or "3")
          cross_trials = int(os.environ["CROSS_TRIALS"])
          cross = os.environ["CROSS_FAMILY"] == "true"

          # Keep in sync with the job definitions below: (job, families,
          # workload env var, trials, timeout minutes, runs on this event).
          JOBS = [
              ("paced-linux-embedded", ["sqlite", "sqlite-ts", "turso"],
               "PACED_WORKLOAD", paced_trials, 150 if small else 300, True),
              ("paced-linux-isolated", ["libsql", "spacetimedb"],
               "PACED_WORKLOAD", paced_trials, 150 if small else 240, True),
              ("paced-linux-postgres", ["postgres", "postgres-ts", "postgres-rust-orms"],
               "PACED_WORKLOAD", paced_trials, 150 if small else 350, True),
              ("paced-desktop-embedded", ["sqlite", "sqlite-ts", "turso", "spacetimedb"],
               "PACED_WORKLOAD", paced_trials, 150 if small else 350, True),
              ("paced-desktop-postgres", ["postgres", "postgres-ts", "postgres-rust-orms"],
               "PACED_WORKLOAD", paced_trials, 150 if small else 350, True),
              ("linux-all", list(SPEC),
               "CROSS_WORKLOAD", cross_trials, 350, cross),
              ("desktop-all", [f for f in SPEC if f != "libsql"],
               "CROSS_WORKLOAD", cross_trials, 350, cross),
          ]

          # Per-target-per-trial cost that is not the ramp itself: process
          # spawn, seed, LISTENING wait, teardown. Run 31773786939 measured
          # ~10-15 s with a hot cargo cache; padded to double.
          OVERHEAD_S = 30
          # Toolchain install, cargo release build of the runner plus the
          # external target crates, bun install, database and SpacetimeDB
          # setup — the cold-cache day, not the usual one.
          BUILD_MIN = 55

          failed = False
          for job, families, workload_env, trials, timeout, active in JOBS:
              if not active:
                  continue
              workload = json.load(open(os.environ[workload_env]))
              ramp_s = sum(s["sec"] for s in workload.get("stages", []))
              targets = sum(len(json.load(open(SPEC[f]))) for f in families)
              total = round(targets * trials * (ramp_s + OVERHEAD_S) / 60 + BUILD_MIN)
              status = "ok" if total <= timeout - 10 else "OVER BUDGET"
              print(
                  f"{job}: {targets} targets x {trials} trials x "
                  f"({ramp_s}s ramp + {OVERHEAD_S}s overhead) + {BUILD_MIN} min build "
                  f"= ~{total} min (timeout {timeout}) {status}"
              )
              if total > timeout - 10:
                  print(
                      f"::error::{job} needs ~{total} min against a {timeout} min timeout. "
                      f"Lower trials, regroup its families, or split the job — GitHub "
                      f"hard-cancels at 360 and the ranking would come back partial."
                  )
                  failed = True
          if failed:
              sys.exit(1)
          PY

  # ---------------------------------------------------------------------------
  # Job structure: three benchmark jobs per desktop OS, four on Linux.
  #
  # "One job per OS" does not fit GitHub's hard 360-minute cancellation and
  # never can: the paced ladder is a byte-for-byte transcription of upstream
  # bench.js (400 s per target-trial including the probe rungs), and run
  # 31773786939 measured ~415 s per target-trial wall (~99% benchmark, build
  # sub-minute). Linux hosts 27 targets, so even a single paced trial of every
  # family is 27 x 6.9 min = 187 min, and the previous five-trial suite summed
  # to ~15.6 h of paced benchmarking. The ladder is near-inviolable — shortening
  # it forfeits the upstream comparability that primary.rps exists to preserve —
  # so the levers are trials and grouping:
  #
  #   trials 5 -> 3 for the paced suite. Measured from the recorded five-trial
  #   cohorts: the median-of-3 moves rps.avg by <=2.6% (median 0.1%) and the
  #   whole-ramp p95 by <=12.5% (median 1.1%) versus the median-of-5. The cost
  #   lands on the sustained-latency reference figure, whose per-trial jitter
  #   measured 5-39% on slower targets — its cross-trial median is real but
  #   looser at 3 than at 5. Disclosed in spread.trials, not hidden.
  #
  #   families grouped by shared infrastructure, PostgreSQL families together
  #   (a service container cannot be started conditionally, so a job either
  #   carries the database or must not), embedded families together, and the
  #   two resident-daemon families (libsql's feature-gated build, SpacetimeDB's
  #   daemon) on Linux in their own job.
  #
  # Every paced group stays inside its timeout under the deliberately padded
  # model the `plan` job enforces (30 s overhead per target-trial — double the
  # measured ~15 s — plus 55 min for a cold build): 12 targets x 3 trials is
  # ~313 min padded, ~260 min at measured rates. The saturation jobs are
  # unchanged in method (2 trials, unpaced ramp) and now cover every family the
  # OS can host, PostgreSQL included.
  # ---------------------------------------------------------------------------
  paced-linux-embedded:
    name: Paced embedded (linux)
    needs: plan
    runs-on: ubuntu-latest
    timeout-minutes: ${{ needs.plan.outputs.class == 'small' && 150 || 300 }}

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_VERSION }}

      - name: Install Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ env.NODE_VERSION }}
          check-latest: true
          package-manager-cache: false

      - name: Install Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Cache Rust dependencies
        if: ${{ !env.ACT }}
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: runner-paced-linux-embedded
          save-if: ${{ env.PUBLISH_TO_R2 == 'true' }}

      - name: Install TS target dependencies
        uses: ./.github/actions/install-ts-targets

      - name: Benchmark SQLite family
        uses: ./.github/actions/bench-runner-run
        with:
          family: sqlite
          targets: bench/spec/targets.sqlite.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}

      # No database service: both targets seed their own file-backed temp
      # database via `bench-runner seed-sqlite` before announcing LISTENING.
      - name: Benchmark SQLite TS family
        uses: ./.github/actions/bench-runner-run
        with:
          family: sqlite-ts
          targets: bench/spec/targets.sqlite-ts.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}

      - name: Benchmark Turso family
        uses: ./.github/actions/bench-runner-run
        with:
          family: turso
          targets: bench/spec/targets.turso.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          # toasty-turso is an external cargo target in this family.
          prebuild-manifests: bench/targets/toasty/Cargo.toml

  paced-linux-isolated:
    name: Paced libSQL + SpacetimeDB (linux)
    needs: plan
    runs-on: ubuntu-latest
    timeout-minutes: ${{ needs.plan.outputs.class == 'small' && 150 || 240 }}
    env:
      SPACETIME_URI: "ws://127.0.0.1:3000"
      SPACETIME_MODULE: "bench-module"

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_VERSION }}

      - name: Cache Rust dependencies
        if: ${{ !env.ACT }}
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: runner-paced-linux-isolated
          save-if: ${{ env.PUBLISH_TO_R2 == 'true' }}

      # libsql is Linux-only, deliberately: it has a history of segfaulting the
      # benchmark process on Windows and macOS — that is why it was dropped
      # from the criterion benches — and `bench-runner` only links it when the
      # `libsql` cargo feature is on, so no other job is affected by this
      # family existing.
      - name: Benchmark libSQL family
        uses: ./.github/actions/bench-runner-run
        with:
          family: libsql
          targets: bench/spec/targets.libsql.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          # The builtin libsql targets are behind this cargo feature; without it
          # the prebuilt `$BENCH_RUNNER_BIN` rejects their ids.
          runner-features: libsql

      # SpacetimeDB's daemon starts after libsql has finished measuring, so it
      # is not sitting resident underneath another family's run.
      - name: Install SpacetimeDB CLI
        uses: ./.github/actions/install-spacetime

      - name: Start SpacetimeDB
        shell: bash
        run: |
          rm -rf "$HOME/.local/share/spacetime/data" "$HOME/.config/spacetime"
          pkill -f spacetimedb-standalone 2>/dev/null || true
          sleep 1
          spacetime start --listen-addr 127.0.0.1:3000 --pg-port 5433 &
          for i in $(seq 1 30); do
            if spacetime server ping http://127.0.0.1:3000 2>/dev/null; then
              echo "SpacetimeDB WebSocket ready"
              break
            fi
            sleep 1
          done
          for i in $(seq 1 15); do
            if (echo > /dev/tcp/127.0.0.1/5433) 2>/dev/null; then
              echo "SpacetimeDB PGWire ready on :5433"
              break
            fi
            sleep 1
          done

      - name: Build and publish SpacetimeDB module
        shell: bash
        run: |
          spacetime build -p bench/targets/spacetime-module
          spacetime publish bench-module -p bench/targets/spacetime-module --server http://127.0.0.1:3000

      - name: Extract SpacetimeDB identity token
        id: spacetime-token
        shell: bash
        run: |
          config="$HOME/.config/spacetime/cli.toml"
          if [[ ! -f "$config" ]]; then
            echo "WARNING: $config not found"
            exit 0
          fi
          token=$(sed -n 's/^[[:space:]]*spacetimedb_token[[:space:]]*=[[:space:]]*"\(.*\)"/\1/p' "$config" | head -n1)
          if [[ -z "$token" ]]; then
            echo "WARNING: No token found in $config"
            cat "$config"
            exit 0
          fi
          echo "::add-mask::$token"
          echo "SPACETIME_TOKEN=$token" >> "$GITHUB_ENV"

      - name: Benchmark SpacetimeDB family
        uses: ./.github/actions/bench-runner-run
        with:
          family: spacetimedb
          targets: bench/spec/targets.spacetimedb.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          prebuild-manifests: bench/targets/spacetime-native-rs/Cargo.toml

  paced-linux-postgres:
    name: Paced PostgreSQL (linux)
    needs: plan
    runs-on: ubuntu-latest
    timeout-minutes: ${{ needs.plan.outputs.class == 'small' && 150 || 350 }}

    services:
      postgres:
        image: postgres:18-alpine
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: drizzle_test
        ports:
          - 5432/tcp
        # Pinned to the top core of the SUT half, matching the saturation job's
        # topology so the two suites measure the same arrangement. The previous
        # per-family paced jobs left the service floating over the whole VM;
        # this job's slugs are new, so no stale baseline compares the pinned
        # numbers against unpinned ones — the regression gate re-baselines.
        options: >-
          --cpuset-cpus 3
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_VERSION }}

      - name: Install Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ env.NODE_VERSION }}
          check-latest: true
          package-manager-cache: false

      - name: Install Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Cache Rust dependencies
        if: ${{ !env.ACT }}
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: runner-paced-linux-postgres
          save-if: ${{ env.PUBLISH_TO_R2 == 'true' }}

      - name: Install TS target dependencies
        uses: ./.github/actions/install-ts-targets

      - name: Resolve DATABASE_URL
        id: pgurl
        uses: ./.github/actions/resolve-postgres-url
        with:
          port: ${{ job.services.postgres.ports[5432] }}
          service-id: ${{ job.services.postgres.id }}

      - name: Benchmark PostgreSQL family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres
          targets: bench/spec/targets.postgres.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          database-url: ${{ steps.pgurl.outputs.url }}
          db-cpuset: '3'

      - name: Benchmark PostgreSQL TS family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres-ts
          targets: bench/spec/targets.postgres-ts.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          database-url: ${{ steps.pgurl.outputs.url }}
          db-cpuset: '3'

      - name: Benchmark PostgreSQL Rust ORM family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres-rust-orms
          targets: bench/spec/targets.postgres-rust-orms.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          database-url: ${{ steps.pgurl.outputs.url }}
          db-cpuset: '3'
          prebuild-manifests: |
            bench/targets/rust-pg-orms/Cargo.toml
            bench/targets/toasty/Cargo.toml

  paced-desktop-embedded:
    name: Paced embedded (${{ matrix.platform }})
    needs: plan
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: windows-latest
            platform: windows
          - os: macos-latest
            platform: macos
    runs-on: ${{ matrix.os }}
    timeout-minutes: ${{ needs.plan.outputs.class == 'small' && 150 || 350 }}
    env:
      SPACETIME_URI: "ws://127.0.0.1:3000"
      SPACETIME_MODULE: "bench-module"

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_VERSION }}

      - name: Install Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ env.NODE_VERSION }}
          check-latest: true
          package-manager-cache: false

      - name: Install Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Cache Rust dependencies
        if: ${{ !env.ACT }}
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: runner-paced-desktop-${{ matrix.platform }}
          save-if: ${{ env.PUBLISH_TO_R2 == 'true' }}

      - name: Install TS target dependencies
        uses: ./.github/actions/install-ts-targets

      # No libsql here, and that is not a choice this job makes: libsql has a
      # history of segfaulting the benchmark process on both of these
      # platforms. Nothing on these platforms is pinned — the runner's affinity
      # call is Linux-only and Darwin exposes no usable affinity API — and the
      # manifest's `topology.cpu_pinning: null` records exactly that.
      - name: Benchmark SQLite family
        uses: ./.github/actions/bench-runner-run
        with:
          family: sqlite
          platform: ${{ matrix.platform }}
          targets: bench/spec/targets.sqlite.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}

      - name: Benchmark SQLite TS family
        uses: ./.github/actions/bench-runner-run
        with:
          family: sqlite-ts
          platform: ${{ matrix.platform }}
          targets: bench/spec/targets.sqlite-ts.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}

      - name: Benchmark Turso family
        uses: ./.github/actions/bench-runner-run
        with:
          family: turso
          platform: ${{ matrix.platform }}
          targets: bench/spec/targets.turso.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          prebuild-manifests: bench/targets/toasty/Cargo.toml

      # SpacetimeDB last: its daemon starts only after the in-process families
      # have finished measuring. The desktop daemon is unpinned like everything
      # else on these platforms (Linux pins it with taskset; there is no
      # equivalent here and the topology block says so by carrying null).
      - name: Install SpacetimeDB CLI
        uses: ./.github/actions/install-spacetime

      - name: Start SpacetimeDB
        shell: bash
        run: |
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            # A process backgrounded from a bash step dies with the step's
            # console on Windows; Start-Process detaches it properly.
            powershell -NoProfile -Command \
              "Start-Process spacetime -WindowStyle Hidden -ArgumentList 'start','--listen-addr','127.0.0.1:3000','--pg-port','5433'"
          else
            rm -rf "$HOME/.local/share/spacetime/data" "$HOME/.config/spacetime"
            nohup spacetime start --listen-addr 127.0.0.1:3000 --pg-port 5433 >/dev/null 2>&1 &
          fi
          for i in $(seq 1 60); do
            if spacetime server ping http://127.0.0.1:3000 2>/dev/null; then
              echo "SpacetimeDB WebSocket ready"
              break
            fi
            sleep 1
          done
          spacetime server ping http://127.0.0.1:3000

      - name: Build and publish SpacetimeDB module
        shell: bash
        run: |
          spacetime build -p bench/targets/spacetime-module
          spacetime publish bench-module -p bench/targets/spacetime-module --server http://127.0.0.1:3000

      - name: Extract SpacetimeDB identity token
        shell: bash
        run: |
          config="$HOME/.config/spacetime/cli.toml"
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            config="$LOCALAPPDATA/SpacetimeDB/config/cli.toml"
            [[ -f "$config" ]] || config="$HOME/.config/spacetime/cli.toml"
          fi
          if [[ ! -f "$config" ]]; then
            echo "WARNING: spacetime cli.toml not found"
            exit 0
          fi
          token=$(sed -n 's/^[[:space:]]*spacetimedb_token[[:space:]]*=[[:space:]]*"\(.*\)"/\1/p' "$config" | head -n1)
          if [[ -z "$token" ]]; then
            echo "WARNING: No token found in $config"
            exit 0
          fi
          echo "::add-mask::$token"
          echo "SPACETIME_TOKEN=$token" >> "$GITHUB_ENV"

      - name: Benchmark SpacetimeDB family
        uses: ./.github/actions/bench-runner-run
        with:
          family: spacetimedb
          platform: ${{ matrix.platform }}
          targets: bench/spec/targets.spacetimedb.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          prebuild-manifests: bench/targets/spacetime-native-rs/Cargo.toml

  paced-desktop-postgres:
    name: Paced PostgreSQL (${{ matrix.platform }})
    needs: plan
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: windows-latest
            platform: windows
          - os: macos-latest
            platform: macos
    runs-on: ${{ matrix.os }}
    timeout-minutes: ${{ needs.plan.outputs.class == 'small' && 150 || 350 }}

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_VERSION }}

      - name: Install Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ env.NODE_VERSION }}
          check-latest: true
          package-manager-cache: false

      - name: Install Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Cache Rust dependencies
        if: ${{ !env.ACT }}
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: runner-paced-desktop-pg-${{ matrix.platform }}
          save-if: ${{ env.PUBLISH_TO_R2 == 'true' }}

      - name: Install TS target dependencies
        uses: ./.github/actions/install-ts-targets

      # Service containers are Linux-only, so these platforms run a natively
      # installed PostgreSQL 18 — the same major as the Linux service image, or
      # the action fails and the platform gets no PostgreSQL rather than a
      # mismatched one. diesel needs no native libpq (pq-sys is bundled).
      - name: Set up PostgreSQL 18
        id: pgnative
        uses: ./.github/actions/setup-postgres-native

      - name: Benchmark PostgreSQL family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres
          platform: ${{ matrix.platform }}
          targets: bench/spec/targets.postgres.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          database-url: ${{ steps.pgnative.outputs.url }}

      - name: Benchmark PostgreSQL TS family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres-ts
          platform: ${{ matrix.platform }}
          targets: bench/spec/targets.postgres-ts.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          database-url: ${{ steps.pgnative.outputs.url }}

      - name: Benchmark PostgreSQL Rust ORM family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres-rust-orms
          platform: ${{ matrix.platform }}
          targets: bench/spec/targets.postgres-rust-orms.v1.json
          workload: ${{ needs.plan.outputs.workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.paced_trials }}
          database-url: ${{ steps.pgnative.outputs.url }}
          prebuild-manifests: |
            bench/targets/rust-pg-orms/Cargo.toml
            bench/targets/toasty/Cargo.toml

  # ---------------------------------------------------------------------------
  # Per-OS cross-family ranking.
  #
  # The leaderboard puts every family in one table, so a rank is only meaningful
  # if the rows came off one machine. No machine runs all three operating
  # systems, so the ranking is scoped per OS instead: one job per OS, every
  # family that OS can host, run back to back on that job's VM.
  #
  # Which families an OS can host is a platform fact, not a policy choice:
  #   linux    everything, with the PostgreSQL service container pinned to its
  #            own core.
  #   macos    everything but libsql (segfault history), unpinned: Darwin
  #            exposes no usable CPU-affinity API, so `topology.cpu_pinning`
  #            comes back null and the dashboard reports the absence rather
  #            than implying isolation that never happened. PostgreSQL runs
  #            natively at the same major as the Linux service image (service
  #            containers are Linux-only), also unpinned.
  #   windows  everything but libsql, unpinned, PostgreSQL native like macOS.
  #
  # These jobs run the saturation ramp whatever `plan` resolved for the paced
  # group jobs, and they do not replace them. The paced latency reading still
  # comes from the parallel paced groups, under its own artifact names, on
  # every event; `slug-suffix: cross` is what keeps the two apart. The two
  # cohorts of one CI run share the `gh-<run>-...` prefix, which is what lets
  # a consumer join them per target — latency columns from the paced cohort,
  # capacity from this one — without ever comparing numbers across cohorts.
  #
  # All three share ONE cohort id — do not split it per OS. The dashboard shows a
  # cohort at a time and scopes the ranking by operating system inside it, so a
  # per-OS cohort id splits the three rankings across three cohorts and leaves the
  # `?os=` pills with a single entry: macOS and Windows become unreachable from
  # the ranking page, which is the exact thing the scoping was built to offer.
  # Hardware differences are already carried by the OS badge and the scope's own
  # provenance line, so the cohort does not need to encode them too.
  # ---------------------------------------------------------------------------
  linux-all:
    name: All families (linux)
    needs: plan
    if: ${{ needs.plan.outputs.cross_family == 'true' }}
    runs-on: ubuntu-latest
    # `plan` estimates this sequence and fails the run up front when it does not
    # fit. GitHub hard-cancels at 360, so never raise this past 350 — lower
    # `cross_trials` or shorten the ramp instead.
    timeout-minutes: 350
    env:
      SPACETIME_URI: "ws://127.0.0.1:3000"
      SPACETIME_MODULE: "bench-module"

    services:
      postgres:
        image: postgres:18-alpine
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: drizzle_test
        ports:
          - 5432/tcp
        # Pinned to the top core of the SUT half so load / client / database are
        # three disjoint sets. Before this the service floated over the whole
        # VM while the in-process engines were confined to the upper half — a
        # silent handicap for every one of them in the same table.
        #
        # A service container cannot be started mid-job, so PostgreSQL is
        # resident for the whole sequence. It is idle with no connections during
        # the in-process families' runs, and it shares only the core those
        # families would have used for the engine anyway.
        options: >-
          --cpuset-cpus 3
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_VERSION }}

      - name: Install Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ env.NODE_VERSION }}
          check-latest: true
          package-manager-cache: false

      - name: Install Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Cache Rust dependencies
        if: ${{ !env.ACT }}
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: runner-linux-all
          save-if: ${{ env.PUBLISH_TO_R2 == 'true' }}

      - name: Install TS target dependencies
        uses: ./.github/actions/install-ts-targets

      - name: Resolve DATABASE_URL
        id: pgurl
        uses: ./.github/actions/resolve-postgres-url
        with:
          port: ${{ job.services.postgres.ports[5432] }}
          service-id: ${{ job.services.postgres.id }}

      # Every family below passes `runner-features: libsql`, so `bench-runner`
      # is built once and the identical binary serves all eight. Building it
      # per family would put a cargo rebuild between measured families and
      # leave the ranking's rows running on binaries that differ in which
      # drivers are linked in.
      #
      # Order is fixed and in-process first: the two out-of-process engines are
      # the ones with a resident daemon, and SpacetimeDB's is started last so it
      # is not sitting idle underneath anything else.
      - name: Benchmark SQLite family
        uses: ./.github/actions/bench-runner-run
        with:
          family: sqlite
          slug-suffix: cross
          targets: bench/spec/targets.sqlite.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          runner-features: libsql

      - name: Benchmark SQLite TS family
        uses: ./.github/actions/bench-runner-run
        with:
          family: sqlite-ts
          slug-suffix: cross
          targets: bench/spec/targets.sqlite-ts.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          runner-features: libsql

      - name: Benchmark libSQL family
        uses: ./.github/actions/bench-runner-run
        with:
          family: libsql
          slug-suffix: cross
          targets: bench/spec/targets.libsql.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          runner-features: libsql

      - name: Benchmark Turso family
        uses: ./.github/actions/bench-runner-run
        with:
          family: turso
          slug-suffix: cross
          targets: bench/spec/targets.turso.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          runner-features: libsql
          prebuild-manifests: bench/targets/toasty/Cargo.toml

      - name: Benchmark PostgreSQL family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres
          slug-suffix: cross
          targets: bench/spec/targets.postgres.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          runner-features: libsql
          database-url: ${{ steps.pgurl.outputs.url }}
          db-cpuset: '3'

      - name: Benchmark PostgreSQL Rust ORM family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres-rust-orms
          slug-suffix: cross
          targets: bench/spec/targets.postgres-rust-orms.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          runner-features: libsql
          database-url: ${{ steps.pgurl.outputs.url }}
          db-cpuset: '3'
          prebuild-manifests: |
            bench/targets/rust-pg-orms/Cargo.toml
            bench/targets/toasty/Cargo.toml

      - name: Benchmark PostgreSQL TS family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres-ts
          slug-suffix: cross
          targets: bench/spec/targets.postgres-ts.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          runner-features: libsql
          database-url: ${{ steps.pgurl.outputs.url }}
          db-cpuset: '3'

      - name: Install SpacetimeDB CLI
        uses: ./.github/actions/install-spacetime

      # Started last and pinned to the same core the PostgreSQL service owns.
      # PostgreSQL is idle by this point, and both are the out-of-process engine
      # for their own family, so the two never contend.
      - name: Start SpacetimeDB
        shell: bash
        run: |
          rm -rf "$HOME/.local/share/spacetime/data" "$HOME/.config/spacetime"
          pkill -f spacetimedb-standalone 2>/dev/null || true
          sleep 1
          taskset -c 3 spacetime start --listen-addr 127.0.0.1:3000 --pg-port 5433 &
          for i in $(seq 1 30); do
            if spacetime server ping http://127.0.0.1:3000 2>/dev/null; then
              echo "SpacetimeDB WebSocket ready"
              break
            fi
            sleep 1
          done
          for i in $(seq 1 15); do
            if (echo > /dev/tcp/127.0.0.1/5433) 2>/dev/null; then
              echo "SpacetimeDB PGWire ready on :5433"
              break
            fi
            sleep 1
          done

      - name: Build and publish SpacetimeDB module
        shell: bash
        run: |
          spacetime build -p bench/targets/spacetime-module
          spacetime publish bench-module -p bench/targets/spacetime-module --server http://127.0.0.1:3000

      - name: Extract SpacetimeDB identity token
        id: spacetime-token
        shell: bash
        run: |
          config="$HOME/.config/spacetime/cli.toml"
          if [[ ! -f "$config" ]]; then
            echo "WARNING: $config not found"
            exit 0
          fi
          token=$(sed -n 's/^[[:space:]]*spacetimedb_token[[:space:]]*=[[:space:]]*"\(.*\)"/\1/p' "$config" | head -n1)
          if [[ -z "$token" ]]; then
            echo "WARNING: No token found in $config"
            cat "$config"
            exit 0
          fi
          echo "::add-mask::$token"
          echo "SPACETIME_TOKEN=$token" >> "$GITHUB_ENV"

      - name: Benchmark SpacetimeDB family
        uses: ./.github/actions/bench-runner-run
        with:
          family: spacetimedb
          slug-suffix: cross
          targets: bench/spec/targets.spacetimedb.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          runner-features: libsql
          db-cpuset: '3'
          prebuild-manifests: bench/targets/spacetime-native-rs/Cargo.toml

  desktop-all:
    name: All families (${{ matrix.platform }})
    needs: plan
    if: ${{ needs.plan.outputs.cross_family == 'true' }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: macos-latest
            platform: macos
          - os: windows-latest
            platform: windows
    runs-on: ${{ matrix.os }}
    # Twenty-four targets (everything but linux-only libsql) at 2 trials on the
    # ~215 s saturation ramp: ~196 min padded benchmark + build + the native
    # PostgreSQL and SpacetimeDB setups. `plan` estimates this sequence and
    # fails the run up front when it does not fit.
    timeout-minutes: 350
    env:
      SPACETIME_URI: "ws://127.0.0.1:3000"
      SPACETIME_MODULE: "bench-module"

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_VERSION }}

      - name: Install Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ env.NODE_VERSION }}
          check-latest: true
          package-manager-cache: false

      - name: Install Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest

      - name: Cache Rust dependencies
        if: ${{ !env.ACT }}
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: runner-desktop-all-${{ matrix.platform }}
          save-if: ${{ env.PUBLISH_TO_R2 == 'true' }}

      - name: Install TS target dependencies
        uses: ./.github/actions/install-ts-targets

      # Everything the platform can host, in-process families first. libsql is
      # the one absence and it is not a choice this workflow makes: it has a
      # history of segfaulting the benchmark process on both of these
      # platforms. PostgreSQL runs natively (service containers are
      # Linux-only) at the same major as the Linux service image, and the
      # SpacetimeDB daemon starts last so it is not resident under anything
      # else. Nothing on these platforms is pinned — the runner's affinity call
      # is Linux-only and Darwin has no usable affinity API — and the
      # manifest's `topology.cpu_pinning: null` records exactly that, which is
      # why these rankings are presented per OS rather than folded into one
      # table with the pinned linux rows.
      - name: Benchmark SQLite family
        uses: ./.github/actions/bench-runner-run
        with:
          family: sqlite
          platform: ${{ matrix.platform }}
          slug-suffix: cross
          targets: bench/spec/targets.sqlite.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}

      - name: Benchmark SQLite TS family
        uses: ./.github/actions/bench-runner-run
        with:
          family: sqlite-ts
          platform: ${{ matrix.platform }}
          slug-suffix: cross
          targets: bench/spec/targets.sqlite-ts.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}

      - name: Benchmark Turso family
        uses: ./.github/actions/bench-runner-run
        with:
          family: turso
          platform: ${{ matrix.platform }}
          slug-suffix: cross
          targets: bench/spec/targets.turso.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          prebuild-manifests: bench/targets/toasty/Cargo.toml

      - name: Set up PostgreSQL 18
        id: pgnative
        uses: ./.github/actions/setup-postgres-native

      - name: Benchmark PostgreSQL family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres
          platform: ${{ matrix.platform }}
          slug-suffix: cross
          targets: bench/spec/targets.postgres.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          database-url: ${{ steps.pgnative.outputs.url }}

      - name: Benchmark PostgreSQL TS family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres-ts
          platform: ${{ matrix.platform }}
          slug-suffix: cross
          targets: bench/spec/targets.postgres-ts.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          database-url: ${{ steps.pgnative.outputs.url }}

      - name: Benchmark PostgreSQL Rust ORM family
        uses: ./.github/actions/bench-runner-run
        with:
          family: postgres-rust-orms
          platform: ${{ matrix.platform }}
          slug-suffix: cross
          targets: bench/spec/targets.postgres-rust-orms.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          database-url: ${{ steps.pgnative.outputs.url }}
          prebuild-manifests: |
            bench/targets/rust-pg-orms/Cargo.toml
            bench/targets/toasty/Cargo.toml

      - name: Install SpacetimeDB CLI
        uses: ./.github/actions/install-spacetime

      - name: Start SpacetimeDB
        shell: bash
        run: |
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            # A process backgrounded from a bash step dies with the step's
            # console on Windows; Start-Process detaches it properly.
            powershell -NoProfile -Command \
              "Start-Process spacetime -WindowStyle Hidden -ArgumentList 'start','--listen-addr','127.0.0.1:3000','--pg-port','5433'"
          else
            rm -rf "$HOME/.local/share/spacetime/data" "$HOME/.config/spacetime"
            nohup spacetime start --listen-addr 127.0.0.1:3000 --pg-port 5433 >/dev/null 2>&1 &
          fi
          for i in $(seq 1 60); do
            if spacetime server ping http://127.0.0.1:3000 2>/dev/null; then
              echo "SpacetimeDB WebSocket ready"
              break
            fi
            sleep 1
          done
          spacetime server ping http://127.0.0.1:3000

      - name: Build and publish SpacetimeDB module
        shell: bash
        run: |
          spacetime build -p bench/targets/spacetime-module
          spacetime publish bench-module -p bench/targets/spacetime-module --server http://127.0.0.1:3000

      - name: Extract SpacetimeDB identity token
        shell: bash
        run: |
          config="$HOME/.config/spacetime/cli.toml"
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            config="$LOCALAPPDATA/SpacetimeDB/config/cli.toml"
            [[ -f "$config" ]] || config="$HOME/.config/spacetime/cli.toml"
          fi
          if [[ ! -f "$config" ]]; then
            echo "WARNING: spacetime cli.toml not found"
            exit 0
          fi
          token=$(sed -n 's/^[[:space:]]*spacetimedb_token[[:space:]]*=[[:space:]]*"\(.*\)"/\1/p' "$config" | head -n1)
          if [[ -z "$token" ]]; then
            echo "WARNING: No token found in $config"
            exit 0
          fi
          echo "::add-mask::$token"
          echo "SPACETIME_TOKEN=$token" >> "$GITHUB_ENV"

      - name: Benchmark SpacetimeDB family
        uses: ./.github/actions/bench-runner-run
        with:
          family: spacetimedb
          platform: ${{ matrix.platform }}
          slug-suffix: cross
          targets: bench/spec/targets.spacetimedb.v1.json
          workload: ${{ needs.plan.outputs.cross_workload }}
          class: ${{ needs.plan.outputs.class }}
          cohort-id: ${{ env.BENCH_COHORT_ID }}-cross
          publish: ${{ needs.plan.outputs.publish }}
          trials: ${{ needs.plan.outputs.cross_trials }}
          prebuild-manifests: bench/targets/spacetime-native-rs/Cargo.toml

  dashboard-preview:
    name: Dashboard preview data
    runs-on: ubuntu-latest
    timeout-minutes: 30
    needs:
      - plan
      - paced-linux-embedded
      - paced-linux-isolated
      - paced-linux-postgres
      - paced-desktop-embedded
      - paced-desktop-postgres
      - linux-all
      - desktop-all
    # Assemble whatever succeeded. One flaky family used to void the preview
    # data for every other family; now the assembly step is the gate and it
    # fails only when nothing at all was produced.
    if: ${{ always() && !cancelled() }}

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_VERSION }}

      - name: Install Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ env.NODE_VERSION }}
          check-latest: true
          package-manager-cache: false

      - name: Download runner artifacts
        # A run where every family failed downloads nothing; the assembly step
        # below reports that as the failure instead of an opaque action error.
        continue-on-error: true
        uses: actions/download-artifact@v8
        with:
          pattern: runner-*
          path: bench-preview/artifacts

      - name: Build publish tool
        shell: bash
        run: |
          cargo build --release -p bench-runner
          bin="$GITHUB_WORKSPACE/target/release/bench-runner"
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            bin="${bin}.exe"
          fi
          echo "BENCH_RUNNER_BIN=$bin" >> "$GITHUB_ENV"

      - name: Assemble dashboard object store
        shell: bash
        run: |
          out="bench-out/dashboard-data"
          index="$out/index.json"
          rm -rf "$out"
          mkdir -p "$out/runs"
          echo '{"version":"v1","runs":[]}' > "$index"

          manifests=()
          if [[ -d bench-preview/artifacts ]]; then
            mapfile -t manifests < <(find bench-preview/artifacts -name manifest.json | sort)
          fi

          assembled=0
          skipped=()
          for manifest in "${manifests[@]}"; do
            run_dir="$(dirname "$manifest")"
            run_id="$(sed -n 's/^[[:space:]]*"run_id"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$manifest" | head -n1)"
            if [[ -z "$run_id" ]]; then
              echo "::warning::manifest is missing run_id, skipping: $manifest"
              skipped+=("$manifest")
              continue
            fi
            dest="$out/runs/$run_id"
            mkdir -p "$dest"
            cp -R "$run_dir"/. "$dest"/

            if ! "$BENCH_RUNNER_BIN" publish --run "$dest" --index "$index"; then
              echo "::warning::publish failed for $run_id, dropping it from the index"
              rm -rf "$dest"
              skipped+=("$manifest")
              continue
            fi
            assembled=$(( assembled + 1 ))
          done

          if (( assembled == 0 )); then
            echo "::error::no runner manifests could be assembled (${#manifests[@]} found, ${#skipped[@]} skipped)"
            exit 1
          fi

          if (( ${#skipped[@]} > 0 )); then
            echo "::warning::assembled $assembled run(s); skipped ${#skipped[@]}"
          fi

          echo "Dashboard data contains $assembled run(s):"
          find "$out" -maxdepth 3 -type f | sort

      - name: Upload dashboard preview data
        uses: actions/upload-artifact@v7
        with:
          name: dashboard-bench-data
          path: bench-out/dashboard-data
          retention-days: 30

      - name: Publish dashboard data to R2
        if: ${{ env.PUBLISH_TO_R2 == 'true' && !env.ACT }}
        shell: bash
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
        run: |
          if [[ -z "$CLOUDFLARE_API_TOKEN" ]]; then
            echo "No R2 credentials, skipping publish"
            exit 0
          fi

          # Install once, outside the workspace. `npx wrangler` per object
          # re-resolved the package for every file in the store.
          npm install --no-audit --no-fund --prefix "$RUNNER_TEMP/wrangler" 'wrangler@^4.116.0'
          wrangler="$RUNNER_TEMP/wrangler/node_modules/.bin/wrangler"

          # --remote is load-bearing: wrangler v4 defaults `r2 object put` to
          # LOCAL simulated storage, which "succeeds" while publishing nothing.
          #
          # A store is hundreds of objects, so a single transient upstream blip
          # (R2 has returned 10001 "internal error" here) would otherwise abort
          # the whole publish under `set -e` and leave the bucket half-written.
          # Each object retries with backoff; index.json is uploaded last so a
          # partial store never becomes visible to the dashboard.
          put_object() {
            local key="$1" file="$2" attempt
            for attempt in 1 2 3 4 5; do
              if "$wrangler" r2 object put "$R2_BUCKET/$key" --file "$file" --remote; then
                return 0
              fi
              echo "::warning::r2 put failed for $key (attempt $attempt), retrying"
              sleep $(( attempt * 5 ))
            done
            echo "::error::r2 put failed for $key after 5 attempts"
            return 1
          }

          failed=0
          while read -r file; do
            key="${file#bench-out/dashboard-data/}"
            [[ "$key" == "index.json" ]] && continue
            put_object "$key" "$file" || failed=1
          done < <(find bench-out/dashboard-data -type f | sort)

          if (( failed )); then
            echo "::error::one or more objects failed to publish; index.json withheld"
            exit 1
          fi

          put_object "index.json" "bench-out/dashboard-data/index.json"