zeph 0.22.4

Lightweight AI agent with hybrid inference, skills-first architecture, and multi-channel I/O
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
name: CI

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read
  pull-requests: write
  security-events: write

env:
  CARGO_TERM_COLOR: always
  RUSTC_WRAPPER: ""
  CARGO_INCREMENTAL: "0"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  detect-changes:
    name: Detect Changes
    runs-on: ubuntu-latest
    timeout-minutes: 2
    outputs:
      docs-only: ${{ steps.classify.outputs.docs-only }}
      specs-only: ${{ steps.classify.outputs.specs-only }}
      run-full-ci: ${{ steps.classify.outputs.run-full-ci }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - name: Filter changed paths
        uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
        id: filter
        with:
          filters: |
            docs:
              - 'book/src/**'
              - 'docs/**'
              - '**.md'
              - '.local/testing/**'
            specs:
              - 'specs/**'
            code:
              - 'crates/**'
              - 'src/**'
              - 'Cargo.toml'
              - 'Cargo.lock'
              - 'build.rs'
              - 'docker/**'
            workflows:
              - '.github/workflows/**'
              - '.github/nextest.toml'
              - '.github/testcontainers-images.txt'
              - '.cargo/**'
            shell:
              - 'install/**'
      - name: Classify changes
        id: classify
        run: |
          DOCS="${{ steps.filter.outputs.docs }}"
          SPECS="${{ steps.filter.outputs.specs }}"
          CODE="${{ steps.filter.outputs.code }}"
          WORKFLOWS="${{ steps.filter.outputs.workflows }}"
          SHELL_SCRIPTS="${{ steps.filter.outputs.shell }}"

          # docs-only: docs or specs changed, nothing that requires building
          if [[ "$CODE" == "false" && "$WORKFLOWS" == "false" && "$SHELL_SCRIPTS" == "false" && ("$DOCS" == "true" || "$SPECS" == "true") ]]; then
            echo "docs-only=true" >> "$GITHUB_OUTPUT"
          else
            echo "docs-only=false" >> "$GITHUB_OUTPUT"
          fi

          # specs-only: specs changed, no code or workflow changes
          if [[ "$SPECS" == "true" && "$CODE" == "false" && "$WORKFLOWS" == "false" && "$SHELL_SCRIPTS" == "false" && "$DOCS" == "false" ]]; then
            echo "specs-only=true" >> "$GITHUB_OUTPUT"
          else
            echo "specs-only=false" >> "$GITHUB_OUTPUT"
          fi

          # run-full-ci: any code, workflow, or shell change triggers full CI
          if [[ "$CODE" == "true" || "$WORKFLOWS" == "true" || "$SHELL_SCRIPTS" == "true" ]]; then
            echo "run-full-ci=true" >> "$GITHUB_OUTPUT"
          else
            echo "run-full-ci=false" >> "$GITHUB_OUTPUT"
          fi

  cla:
    name: CLA Check
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    timeout-minutes: 5
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: contributor-assistant/github-action@ca4a40a7d1004f18d9960b404b97e5f30a505a08 # v2.6.1
        with:
          path-to-signatures: cla-signatures.json
          path-to-document: https://github.com/bug-ops/zeph/blob/main/.github/CLA.md
          branch: cla-signatures
          allowlist: bug-ops,dependabot[bot],github-actions[bot],renovate[bot]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  lint-shellcheck:
    name: Lint (shellcheck)
    needs: detect-changes
    # Run when shell scripts changed, or when doing full CI (workflows changed)
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - name: Run shellcheck
        uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # 2.0.0
        with:
          scandir: install
      - name: Transcript-integrity audit gate (issue #6360)
        run: bash .github/scripts/check_integrity_audit.sh
      - name: ACP permission-gate test-isolation guard (issue #6515)
        run: bash .github/scripts/check_acp_permission_gate.sh

  lint-fmt:
    name: Lint (fmt)
    needs: detect-changes
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@7c8d7d138f5c09cef361f8214cf96882cd029cdb # nightly
        with:
          toolchain: nightly
          components: rustfmt
      - name: Check formatting
        run: cargo +nightly fmt --check

  lint-clippy:
    name: Lint (clippy, ${{ matrix.label }})
    needs: detect-changes
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 10
    strategy:
      fail-fast: false
      matrix:
        include:
          - features: "desktop,ide,server,chat,pdf,scheduler,registry,testing,deep-link"
            label: desktop-ide-server-chat-pdf-scheduler
          - features: bench
            label: bench
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: stable
          components: clippy
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          shared-key: "ci"
      - name: Clippy
        run: cargo clippy --profile ci --workspace --all-targets --features ${{ matrix.features }} -- -D warnings

  msrv:
    name: MSRV check (1.97, ${{ matrix.label }})
    needs: detect-changes
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 20
    strategy:
      fail-fast: false
      matrix:
        include:
          - features: "desktop,ide,server,chat,pdf,scheduler,registry,deep-link"
            label: desktop-ide-server-chat-pdf-scheduler
          - features: bench
            label: bench
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: "1.97"
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          shared-key: "msrv-${{ matrix.label }}"
      - name: cargo check (MSRV, --all-targets)
        run: cargo check --workspace --all-targets --features ${{ matrix.features }} --locked

  build-tests:
    # Linux-only: macOS/Windows builds live in the on-demand ci-non-linux.yml
    # workflow. The artifact name keeps the -ubuntu-latest suffix for naming
    # parity with the per-OS archives produced there.
    # Nightly + -Z threads=4 (issue #6737), pinned to a dated toolchain so new
    # nightly lints don't fail this gate via build.warnings = "deny". RUSTFLAGS
    # set here, not .cargo/config.toml (af1be7ba/cf75b63f).
    name: Build Tests
    needs: detect-changes
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 45
    env:
      RUSTC_WRAPPER: sccache
      SCCACHE_GHA_ENABLED: "true"
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@7c8d7d138f5c09cef361f8214cf96882cd029cdb # nightly
        with:
          toolchain: nightly-2026-08-07
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          cache-targets: "false"
          shared-key: "ci-nightly-threads"
      - uses: mozilla-actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
      - uses: taiki-e/install-action@4f74fa8a3d358e568049b7b1a7fbb4fceabda454 # nextest
      - name: Build and archive tests
        env:
          RUSTFLAGS: "-Z threads=4"
        run: cargo nextest archive --config-file .github/nextest.toml --cargo-profile ci --workspace --features "desktop,ide,server,chat,pdf,scheduler,registry,deep-link" --lib --bins --tests --archive-file nextest-archive.tar.zst
      - name: Upload test archive
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: nextest-archive-ubuntu-latest
          path: nextest-archive.tar.zst
          retention-days: 1
      - name: Upload binary
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: zeph-binary
          path: target/ci/zeph
          retention-days: 1

  build-tests-postgres:
    # The four postgres archives build RUNNABLE test binaries (with
    # test-utils = testcontainers) consumed by the integration matrix. They do
    # not duplicate the build-postgres job, which is check-only: it type-checks
    # the whole workspace under the postgres backend and produces no artifacts.
    # Split out of build-tests so they compile in parallel with the (longer)
    # main workspace archive instead of serially after it — integration jobs
    # start as soon as the slower of the two build jobs finishes.
    name: Build Tests (postgres archives)
    needs: detect-changes
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 20
    env:
      RUSTC_WRAPPER: sccache
      SCCACHE_GHA_ENABLED: "true"
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          cache-targets: "false"
          shared-key: "ci"
      - uses: mozilla-actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
      - uses: taiki-e/install-action@4f74fa8a3d358e568049b7b1a7fbb4fceabda454 # nextest
      - name: Build and archive zeph-db postgres integration tests
        run: cargo nextest archive --config-file .github/nextest.toml --cargo-profile ci -p zeph-db --no-default-features --features test-utils --tests --archive-file nextest-archive-zeph-db-postgres.tar.zst
      - name: Upload zeph-db postgres test archive
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: nextest-archive-zeph-db-postgres
          path: nextest-archive-zeph-db-postgres.tar.zst
          retention-days: 1
      - name: Build and archive zeph-memory postgres integration tests
        # sqlite and postgres are mutually exclusive (zeph-db's compile_error!
        # fires if both are active), so default features (which include "sqlite")
        # must be disabled here; "jsonschema" is re-added explicitly since it was
        # previously pulled in via zeph-memory's default feature set.
        # --lib --bins (not just --tests) is required so cfg!(feature = "postgres")
        # branches inside src/ (e.g. dialect-selected SQL literals) get archived too —
        # see the "Run zeph-memory postgres unit tests" step in the integration
        # job (#5540).
        run: cargo nextest archive --config-file .github/nextest.toml --cargo-profile ci -p zeph-memory --no-default-features --features test-utils,jsonschema --lib --bins --tests --archive-file nextest-archive-zeph-memory-postgres.tar.zst
      - name: Upload zeph-memory postgres test archive
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: nextest-archive-zeph-memory-postgres
          path: nextest-archive-zeph-memory-postgres.tar.zst
          retention-days: 1
      - name: Build and archive zeph-index postgres integration tests
        # sqlite and postgres are mutually exclusive; default features (which
        # include "sqlite") must be disabled so only postgres is active.
        run: cargo nextest archive --config-file .github/nextest.toml --cargo-profile ci -p zeph-index --no-default-features --features test-utils --tests --archive-file nextest-archive-zeph-index-postgres.tar.zst
      - name: Upload zeph-index postgres test archive
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: nextest-archive-zeph-index-postgres
          path: nextest-archive-zeph-index-postgres.tar.zst
          retention-days: 1
      - name: Build and archive zeph-orchestration postgres integration tests
        # sqlite and postgres are mutually exclusive; default features (which
        # include "sqlite") must be disabled so only postgres is active.
        # test-utils implies llm-planning: tests/postgres_integration.rs exercises
        # PlanCache, which lives behind that feature gate (#5839).
        run: cargo nextest archive --config-file .github/nextest.toml --cargo-profile ci -p zeph-orchestration --no-default-features --features test-utils --tests --archive-file nextest-archive-zeph-orchestration-postgres.tar.zst
      - name: Upload zeph-orchestration postgres test archive
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: nextest-archive-zeph-orchestration-postgres
          path: nextest-archive-zeph-orchestration-postgres.tar.zst
          retention-days: 1

  test:
    name: "Test (shard ${{ matrix.partition }})"
    needs: [detect-changes, lint-fmt, lint-clippy, build-tests]
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 10
    strategy:
      fail-fast: false
      matrix:
        # Increased from 8 (issue #6737) — real timing data showed ~23%
        # avoidable tail from hash-partition skew.
        partition:
          [
            "1/12",
            "2/12",
            "3/12",
            "4/12",
            "5/12",
            "6/12",
            "7/12",
            "8/12",
            "9/12",
            "10/12",
            "11/12",
            "12/12",
          ]
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: taiki-e/install-action@4f74fa8a3d358e568049b7b1a7fbb4fceabda454 # nextest
      - name: Download test archive
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
        with:
          name: nextest-archive-ubuntu-latest
      - name: "Run tests (shard ${{ matrix.partition }})"
        run: |
          cargo nextest run \
            --config-file .github/nextest.toml \
            --archive-file nextest-archive.tar.zst \
            --workspace-remap . \
            --profile ci-partition \
            --partition hash:${{ matrix.partition }}

  integration:
    # One job per container-backed suite so the suites run in parallel instead
    # of serially — the job was the tail of the critical path. Non-ignored
    # tests in *integration* binaries (e.g. zeph-acp's stdio tests) already run
    # in the sharded test job; only #[ignore]d container-backed tests run here.
    name: Integration Tests (${{ matrix.suite }})
    needs: [detect-changes, lint-fmt, lint-clippy, build-tests, build-tests-postgres]
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 15
    strategy:
      fail-fast: false
      matrix:
        include:
          - suite: qdrant
            # qdrant_integration and document_integration are both Qdrant-backed
            # (document_integration fakes embeddings in-test — no extra services);
            # without the second binary those #[ignore]d tests would run nowhere
            # in CI. Container concurrency is capped by the qdrant-containers
            # test-group in .github/nextest.toml.
            archive: nextest-archive-ubuntu-latest
            file: nextest-archive.tar.zst
            run_args: "-E 'binary(qdrant_integration) or binary(document_integration)'"
          - suite: zeph-db-postgres
            archive: nextest-archive-zeph-db-postgres
            file: nextest-archive-zeph-db-postgres.tar.zst
            run_args: ""
          - suite: zeph-memory-postgres
            # Scoped to the postgres_integration binary: zeph-memory's archive also
            # contains hela_spreading_activation.rs (SQLite `:memory:` ignored tests,
            # unrelated to postgres). This archive is built postgres-only (sqlite is
            # disabled, see the archive step's comment in build-tests-postgres) — the
            # vast majority of zeph-memory's tests use a `SqliteStore::new(":memory:")`
            # fixture unconditionally (not gated on `#[cfg(feature = "sqlite")]`), so
            # they'd try to parse ":memory:" as a Postgres URL and fail; running
            # crate-wide would hit those unrelated failures.
            archive: nextest-archive-zeph-memory-postgres
            file: nextest-archive-zeph-memory-postgres.tar.zst
            run_args: "-E 'binary(postgres_integration)'"
          - suite: zeph-index-postgres
            archive: nextest-archive-zeph-index-postgres
            file: nextest-archive-zeph-index-postgres.tar.zst
            run_args: "-E 'binary(postgres_integration)'"
          - suite: zeph-orchestration-postgres
            archive: nextest-archive-zeph-orchestration-postgres
            file: nextest-archive-zeph-orchestration-postgres.tar.zst
            run_args: "-E 'binary(postgres_integration)'"
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: taiki-e/install-action@4f74fa8a3d358e568049b7b1a7fbb4fceabda454 # nextest
      - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Restore testcontainer image cache
        id: tc-image-cache
        uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
        with:
          path: /tmp/testcontainer-images
          key: testcontainer-images-${{ hashFiles('.github/testcontainers-images.txt') }}
      - name: Pull and save testcontainer images (cache miss)
        if: steps.tc-image-cache.outputs.cache-hit != 'true'
        run: |
          mkdir -p /tmp/testcontainer-images
          while IFS= read -r image; do
            [ -z "$image" ] && continue
            echo "Pulling $image"
            docker pull "$image"
            fname=$(echo "$image" | tr '/:' '__')
            docker save "$image" | zstd -T0 -3 -o /tmp/testcontainer-images/"$fname".tar.zst
          done < .github/testcontainers-images.txt
          ls -lh /tmp/testcontainer-images/
      - name: Load testcontainer images (cache hit)
        if: steps.tc-image-cache.outputs.cache-hit == 'true'
        run: |
          for f in /tmp/testcontainer-images/*.tar.zst; do
            echo "Loading $f"
            zstd -d -c "$f" | docker load
          done
          docker image ls
      - name: Download test archive
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
        with:
          name: ${{ matrix.archive }}
      - name: Run integration tests (testcontainers)
        run: cargo nextest run --config-file .github/nextest.toml --archive-file ${{ matrix.file }} --workspace-remap . --profile ci --run-ignored ignored-only ${{ matrix.run_args }}
      - name: Run zeph-memory postgres unit tests (#5540)
        if: matrix.suite == 'zeph-memory-postgres'
        # Runs the --lib/--bins portion of the same archive (built postgres-only
        # via test-utils, see the archive step in build-tests-postgres), so
        # cfg!(feature = "postgres") branches inside src/ get unit-test coverage in
        # CI, not just integration-test coverage that depends on happening to exercise
        # the right code path. Scoped by name (not `kind(lib) + kind(bin)`) because the
        # vast majority of zeph-memory's ~1500 lib unit tests open a `SqliteStore::new(
        # ":memory:")` fixture unconditionally — under this postgres-only build, those
        # unrelated tests would try to parse ":memory:" as a Postgres URL and fail.
        # `_matches_active_dialect` is this codebase's established naming convention
        # (see store/overflow.rs) for pure dialect-literal pinning tests that take no
        # DB connection and are safe to run under either feature build.
        run: cargo nextest run --config-file .github/nextest.toml --archive-file nextest-archive-zeph-memory-postgres.tar.zst --workspace-remap . --profile ci -E 'kind(lib) and test(matches_active_dialect)'
      - name: Reap orphaned testcontainers
        # Defense-in-depth, not a fix: testcontainers-rs 0.27.3 (pinned) has no Ryuk
        # reaper and can leak containers on SIGKILL or a StartupTimeout cancel under
        # concurrent load (#5546, #5547). Runs even if a prior step failed/timed out.
        if: always()
        run: docker ps -aq --filter "label=org.testcontainers.managed-by=testcontainers" | xargs -r docker rm -f

  coverage:
    name: Coverage
    if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.detect-changes.outputs.run-full-ci == 'true'
    needs: [detect-changes, lint-fmt, lint-clippy]
    runs-on: ubuntu-latest
    timeout-minutes: 20
    # coverage uses -C instrument-coverage which produces different artifacts than
    # normal builds; sccache still helps for unchanged crates between main pushes.
    # This job also builds with `--features full`, which includes crates (classifiers,
    # profiling, sandbox, gonka, cocoon) outside the lint-clippy matrix, so a warning
    # could appear here that lint-clippy never sees. CARGO_BUILD_WARNINGS overrides the
    # repo-wide `.cargo/config.toml` deny-by-default to prevent that from promoting
    # workspace lint warnings to errors during instrumented compilation — linting is
    # enforced by the dedicated lint-clippy job.
    env:
      RUSTC_WRAPPER: sccache
      SCCACHE_GHA_ENABLED: "true"
      CARGO_BUILD_WARNINGS: "allow"
      # -C instrument-coverage inflates per-frame size on top of already-large
      # Config-heavy async test frames (same root cause as the daemon-startup
      # stack overflow fixed in #5394); tests that build more than one Agent/
      # ServeAgentDeps in the same frame (e.g.
      # build_agent_factory_gates_trust_state_independently_per_session, which as of
      # #6699 spawns its own 32 MiB-stack thread and so no longer depends on this var
      # itself) can overflow the default per-test thread stack under instrumentation
      # even though they pass in the non-instrumented `test` job. Keep this set — it
      # protects any other, unnamed multi-agent test that doesn't manage its own stack.
      RUST_MIN_STACK: "33554432"
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          cache-targets: "false"
          shared-key: "coverage"
      - uses: mozilla-actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
      - uses: taiki-e/install-action@eba66cc6f87204a1e73f96e528e759b6c1fcf573 # cargo-llvm-cov
      - uses: taiki-e/install-action@4f74fa8a3d358e568049b7b1a7fbb4fceabda454 # nextest
      - name: Generate coverage
        run: cargo llvm-cov nextest --config-file .github/nextest.toml --cargo-profile ci --workspace --features full --lib --bins --lcov --output-path lcov.info
      - name: Upload coverage
        uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: lcov.info
          fail_ci_if_error: false

  docker-build-and-scan:
    name: Docker Build and Security Scan
    needs: [detect-changes, lint-fmt, lint-clippy, build-tests]
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - name: Download binary
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
        with:
          name: zeph-binary
          path: target/ci
      - name: Prepare binaries for Docker
        run: |
          mkdir -p binaries
          cp target/ci/zeph binaries/zeph-amd64
          cp target/ci/zeph binaries/zeph-arm64
      - uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
      - name: Build Docker image
        uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
        with:
          context: .
          file: docker/Dockerfile
          load: true
          tags: zeph:local
          push: false
          cache-from: type=gha
          cache-to: type=gha,mode=max
      - name: Run Trivy vulnerability scanner
        uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
        # continue-on-error: trivy exits 1 when vulnerabilities are found; without
        # this the upload step would be skipped and findings lost from the dashboard.
        continue-on-error: true
        with:
          image-ref: zeph:local
          format: sarif
          output: trivy-results.sarif
          severity: CRITICAL,HIGH
          exit-code: '1'
          limit-severities-for-sarif: true
      - name: Upload Trivy results to GitHub Security tab
        uses: github/codeql-action/upload-sarif@d1ba80a13dd99fba24a470575428917156a28b43 # v4
        with:
          sarif_file: trivy-results.sarif

  bundle-check:
    name: Bundle Check (${{ matrix.bundle }})
    needs: detect-changes
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 15
    strategy:
      fail-fast: false
      matrix:
        bundle: [desktop, ide, server, chat, ml, bench, full]
        include:
          - bundle: ml
            allow_failure: true
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          shared-key: "ci"
      # --all-targets compiles test/bench/example targets too, so per-bundle
      # test-cfg-gate mismatches (e.g. #6607) are caught here, not just by the
      # broader combined-feature jobs above (lint-clippy, msrv, release-build).
      - name: Check bundle
        continue-on-error: ${{ matrix.allow_failure == true }}
        run: cargo check --all-targets --features ${{ matrix.bundle }}

  release-build:
    name: Release Build Check
    needs: [detect-changes, lint-fmt, lint-clippy]
    if: needs.detect-changes.outputs.run-full-ci == 'true' && github.event_name == 'push'
    runs-on: ubuntu-latest
    timeout-minutes: 45
    env:
      RUSTC_WRAPPER: sccache
      SCCACHE_GHA_ENABLED: "true"
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          cache-targets: "false"
          shared-key: "release-build"
      - uses: mozilla-actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
      - name: cargo build (release, --all-targets)
        # `cargo check --release` does not reproduce the release-profile query-depth overflow
        # class of bug fixed by #5407/#5408 (verified empirically: it passes even without the
        # `#![recursion_limit]` fix) because it skips codegen/LTO layout finalization. Only a
        # real `cargo build --release` with this workspace's `[profile.release]` (lto = true,
        # codegen-units = 1) exercises the same query depth CI is meant to gate on.
        run: cargo build --release --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,registry,testing,deep-link"

  release-build-full:
    name: Release Build Check (full)
    needs: [detect-changes, lint-fmt, lint-clippy]
    if: needs.detect-changes.outputs.run-full-ci == 'true' && github.event_name == 'push'
    runs-on: ubuntu-latest
    timeout-minutes: 45
    env:
      RUSTC_WRAPPER: sccache
      SCCACHE_GHA_ENABLED: "true"
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          cache-targets: "false"
          shared-key: "release-build-full"
      - uses: mozilla-actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
      - name: cargo build (release, --all-targets, full)
        # Best-effort candle/ml coverage under the release profile, mirroring the
        # bundle-check `ml` matrix leg (#5418): step-level continue-on-error keeps
        # this job's overall result `success` so it never blocks ci-status, while
        # still surfacing genuine full-feature release-build breakage in the logs.
        continue-on-error: true
        run: cargo build --release --workspace --all-targets --features full

  build-postgres:
    name: Build (postgres)
    needs: detect-changes
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          shared-key: "ci"
      - name: Verify sqlite+postgres compile_error guard
        # Intentionally attempts the forbidden both-enabled combination and asserts it
        # fails with the expected compile_error! message. Guards against a future
        # accidental deletion of the mutual-exclusivity guard in zeph-db/src/lib.rs —
        # this exact regression (guard silently dropped for #5377) is how #5571 happened.
        # `cargo check` here is EXPECTED to fail (exit 101, the compile_error firing).
        # GitHub Actions runs `run:` blocks under `bash -eo pipefail`, so piping that
        # exit code directly into `grep` would poison the pipeline status regardless of
        # whether grep matches — `|| true` swallows the expected failure so only the
        # grep result (checked separately against the redirected log) determines pass/fail.
        run: |
          cargo check -p zeph-db --features postgres > /tmp/guard.log 2>&1 || true
          if grep -q "mutually exclusive for \`zeph-db\`" /tmp/guard.log; then
            echo "guard fired as expected"
          else
            echo "::error::compile_error! guard did not fire — sqlite+postgres both-enabled regression"
            cat /tmp/guard.log
            exit 1
          fi
      - name: Check postgres build (workspace)
        # `full` is backend-agnostic (does not include sqlite or postgres); the default
        # sqlite feature must be disabled explicitly since Cargo features are
        # additive-only and cannot "override" an already-active default. Every
        # "sqlite"/"postgres"-gated crate's workspace-dependency entry in the root
        # Cargo.toml has `default-features = false` (with explicit forwarding through
        # each crate's own `sqlite`/`postgres` feature) precisely so this cascades
        # cleanly instead of silently pulling in a conflicting default via a
        # `foo.workspace = true` edge somewhere in the graph.
        run: cargo check --workspace --all-targets --no-default-features --features full,postgres
      - name: Check sqlite build (workspace, no-default-features parity)
        run: cargo check --workspace --all-targets --no-default-features --features full,sqlite

  rustdoc:
    name: Rustdoc
    needs: detect-changes
    if: needs.detect-changes.outputs.run-full-ci == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 10
    # `build.warnings` (repo-wide .cargo/config.toml) denies ALL local-package rustdoc
    # warnings, not just what RUSTDOCFLAGS explicitly denies below — overriding to "allow"
    # here keeps this job's enforcement scoped to exactly the three lints RUSTDOCFLAGS names,
    # unchanged from before this migration (#5873). `rustdoc::private_intra_doc_links` and
    # `rustdoc::redundant_explicit_links` are denied explicitly (not just left to
    # `build.warnings`, which this env var disables) so the 39-site cleanup from #5894 has a
    # forward regression guardrail in both CI and local dev, not just a one-time sweep.
    env:
      RUSTDOCFLAGS: "--deny rustdoc::broken_intra_doc_links --deny rustdoc::private_intra_doc_links --deny rustdoc::redundant_explicit_links"
      CARGO_BUILD_WARNINGS: "allow"
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
        with:
          shared-key: "ci"
      - name: Build docs (all features except candle)
        run: cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler,registry,deep-link"
      - name: Doc-tests
        run: cargo test --doc --workspace --features "desktop,ide,server,chat,pdf,scheduler,registry,deep-link"

  validate-specs:
    name: Validate Specs
    needs: detect-changes
    if: needs.detect-changes.outputs.specs-only == 'true'
    runs-on: ubuntu-latest
    timeout-minutes: 2
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - name: Check spec structure
        run: |
          echo "Spec files found:"
          find specs -name "*.md" -type f | sort
          echo "Total: $(find specs -name "*.md" -type f | wc -l)"
          # Verify README index exists
          test -f specs/README.md || (echo "::error::specs/README.md index is missing" && exit 1)

  ci-status:
    name: CI Status
    if: always()
    needs: [detect-changes, cla, lint-shellcheck, lint-fmt, lint-clippy, msrv, build-tests, build-tests-postgres, test, integration, coverage, docker-build-and-scan, bundle-check, validate-specs, build-postgres, rustdoc, release-build, release-build-full]
    runs-on: ubuntu-latest
    timeout-minutes: 1
    steps:
      - name: Check all jobs
        run: |
          results=(
            "${{ needs.detect-changes.result }}"
            "${{ needs.cla.result }}"
            "${{ needs.lint-shellcheck.result }}"
            "${{ needs.lint-fmt.result }}"
            "${{ needs.lint-clippy.result }}"
            "${{ needs.msrv.result }}"
            "${{ needs.build-tests.result }}"
            "${{ needs.build-tests-postgres.result }}"
            "${{ needs.test.result }}"
            "${{ needs.integration.result }}"
            "${{ needs.coverage.result }}"
            "${{ needs.docker-build-and-scan.result }}"
            "${{ needs.bundle-check.result }}"
            "${{ needs.validate-specs.result }}"
            "${{ needs.build-postgres.result }}"
            "${{ needs.rustdoc.result }}"
            "${{ needs.release-build.result }}"
            "${{ needs.release-build-full.result }}"
          )
          for r in "${results[@]}"; do
            if [[ "$r" != "success" && "$r" != "skipped" ]]; then
              echo "::error::One or more jobs failed or were cancelled"
              exit 1
            fi
          done
          echo "All jobs passed"