Skip to content

Add a mock-isolated gateway latency report for main CI - #591

Merged
kfallah merged 10 commits into
mainfrom
cursor/gateway-latency-report-a764
Aug 23, 2026
Merged

Add a mock-isolated gateway latency report for main CI#591
kfallah merged 10 commits into
mainfrom
cursor/gateway-latency-report-a764

Conversation

@kfallah

@kfallah kfallah commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Gateway latency

Adds a lightweight, secret-free CI report that measures Experiential gateway-added latency against one local OpenAI-compatible mock. The same sampler, payload, warmup, concurrency, and request counts hit:

  1. the mock directly
  2. the Experiential native gateway

Reported overhead is the client-observed difference (gateway minus mock) for p50, p95, and p99. This is not end-to-end model latency. The static research writeup in docs/research/rust-gateway-engine.md is unchanged. README.md is not edited.

Rebased onto current main. The only conflict was native_engine_disconnect_test.py; this branch now keeps main's escalated-alias fallback coverage.

Methodology

  • local mock upstream
  • discarded warmup requests
  • sequential mock-direct then gateway arms
  • fixed request and concurrency counts
  • nearest-rank percentiles
  • success and failure rate plus RPS
  • several repeats
  • one representative run: the median by gateway non-stream p50

Streaming time-to-first-token is included because the mock emits the first content token immediately, so TTFT is a first-byte measurement rather than a model-generation race.

Routine PR and main pushes stay on ubuntu-latest. workflow_dispatch uses gateway-benchmark-32core so public PRs cannot consume the larger runner.

Schema

exp.gateway.latency_report v1. The JSON records commit SHA, runner OS, CPU count and model, Python, Experiential engine, every repeat, and signed overhead versus the mock baseline. Functional request failures fail the job. Latency differences do not.

Sample result (ubuntu-latest)

Official job: https://github.com/experientiallabs/experiential/actions/runs/32597320092

Commit 45c59dac, GitHub-hosted ubuntu-latest, Linux 6.17 Azure, 4 x AMD EPYC 9V74, Python 3.12.3, Experiential rust, 0 failures. Representative run 1 of 3. Shared-runner tails are noisy: mock-direct p95 can include a one-second hitch, which makes gateway-added p95/p99 negative. Read p50 as the overhead signal.

Non-stream (warmup 10, 40 requests, concurrency 8):

Arm Failures RPS p50 (ms) p95 (ms) p99 (ms) added p50
mock direct 0 37.92 7.62 1032.85 1042.16
experiential 0 209.52 22.20 95.13 189.16 14.58

Streaming TTFT (warmup 5, 20 requests, concurrency 4):

Arm Failures RPS p50 (ms) added p50
mock direct 0 701.30 5.11
experiential 0 222.57 8.37 3.26

Commands

uv sync --extra dev
uv run python -m exp.runtime.gateway.latency_report \
  --output-json gateway-latency.json

Limitations

  • Mock-isolated overhead only. Real-provider TTFT and tokens/s are out of scope.
  • ubuntu-latest is a shared 4-vCPU hosted VM. Percentiles on n=40 are coarse, especially p99.
  • Negative gateway-added tails mean the mock arm had a larger hitch, not that the gateway is faster than the mock.
  • No hard latency regression gate. Functional failures fail CI.

Badge (README approval needed)

The badge above is in this PR description only. A README insertion still needs explicit README approval:

[![Gateway latency](https://github.com/experientiallabs/experiential/actions/workflows/gateway-latency.yml/badge.svg?branch=main)](https://github.com/experientiallabs/experiential/actions/workflows/gateway-latency.yml?query=branch%3Amain)

Review

Rebased onto current main at 12c57212. Greptile last scored the pre-rebase receipt-timeout fix at 5/5 (safe to merge); that unknown engine path is unchanged. Please re-review the rebased tip.

Open in Web Open in Cursor 

@greptile-apps

greptile-apps Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a secret-free CI benchmark that compares a local OpenAI-compatible mock directly against the Experiential gateway and publishes a versioned latency report.

  • Adds a pull-request, main-push, and manually dispatched gateway-latency workflow with commit-pinned actions.
  • Adds mock-server, gateway-launch, sampling, percentile, streaming-TTFT, and report-generation helpers with focused tests.
  • Documents the benchmark methodology, artifact schema, runner selection, and interpretation limits.
  • Preserves accurate engine provenance by waiting for launch receipts and reporting unknown when none is observed.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
.github/workflows/gateway-latency.yml Adds the benchmark workflow with routine jobs on ubuntu-latest, explicit large-runner dispatch, read-only permissions, and full-SHA action pins.
exp/runtime/gateway/latency_measure.py Adds the loopback mock, concurrent request sampler, gateway configuration and lifecycle helpers, and corrected launch-receipt engine detection.
exp/runtime/gateway/latency_report.py Adds the versioned report schema, repeated direct-versus-gateway measurements, functional-failure enforcement, output rendering, and CLI entry point.
exp/runtime/gateway/latency_measure_test.py Covers Rust and Python receipt parsing, delayed receipt publication, missing receipts, and the corrected timeout behavior.
exp/runtime/gateway/latency_report_test.py Exercises report aggregation, rendering, configuration, output generation, and benchmark integration behavior.
docs/reference/gateway-latency.md Documents the mock-isolated methodology, execution schedule, artifact contract, workflow behavior, and interpretation limits.

Sequence Diagram

sequenceDiagram
    participant CI as GitHub Actions
    participant R as Latency reporter
    participant M as Local mock
    participant G as Experiential gateway
    CI->>R: Run benchmark
    R->>M: Start loopback mock
    R->>G: Configure and start gateway
    G->>M: Route latency alias
    R->>M: Warm up and sample directly
    R->>G: Warm up and sample through gateway
    G->>M: Forward requests
    R->>R: Compute gateway-minus-mock percentiles
    R-->>CI: JSON artifact and Markdown summary
Loading

Reviews (8): Last reviewed commit: "Remove the third-party proxy comparison ..." | Re-trigger Greptile

Comment thread exp/runtime/gateway/latency_measure.py Outdated
Comment thread .github/workflows/gateway-latency.yml Outdated
@cursor

cursor Bot commented Aug 22, 2026

Copy link
Copy Markdown

Addressed both Greptile findings on 1d1e472d (engine-receipt wait + SHA-pinned Actions) and resolved the review threads. Please re-review that commit. The gate failure is test_dead_fallback_engine_degrades_only_escalated_routes in an untouched native-engine file, not this latency report.

Comment thread exp/runtime/gateway/latency_measure.py Outdated
@cursor

cursor Bot commented Aug 23, 2026

Copy link
Copy Markdown

@greptileai Please re-review e6a30a38. The latency report now measures only mock-direct versus the Experiential gateway.

cursoragent and others added 10 commits August 23, 2026 00:10
Measure a local OpenAI-compatible mock directly and through the
Experiential gateway, then publish gateway-added p50/p95/p99, throughput,
and failure rate without calling paid providers.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
Run the mock-isolated report on main, pull requests, and workflow_dispatch.
Publish a job summary and versioned JSON artifact without secrets or a
hard latency threshold.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
TTFT clients close the SSE body after the first content token. The mock
now ignores the resulting write error instead of dumping a traceback.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
HTTP readiness can beat the stdout pump thread. Parse rust versus python
only after a ready receipt arrives, and pin third-party Actions to SHAs.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
Pin litellm[proxy]==1.97.0, measure mock-direct plus both proxies with
one sampler, and rotate gateway order across repeats. Schema v2 records
hardware, versions, and signed overhead. Functional failures fail CI;
latency differences do not.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
Rich was wrapping Markdown rows at the default terminal width, which
made the same-run comparison harder to read in the Actions log.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
The latency and python-package workflows already accept a manual start.
Gate now matches so the full CI set can be re-run on a feature branch.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
HTTP readiness can beat the stdout pump. After the receipt wait times
out, the report now records unknown instead of guessing python.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
Keep the mock-direct versus Experiential measurement, JSON artifact, workflow, badge, and hosted-runner matrix. Drop the extra proxy process, CLI flag, schema fields, CI install, and docs.

Co-authored-by: Kion Fallah <kfallah@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/gateway-latency-report-a764 branch from e6a30a3 to 12c5721 Compare August 23, 2026 00:12
@cursor

cursor Bot commented Aug 23, 2026

Copy link
Copy Markdown

@greptileai Please re-review 12c57212. The branch is rebased onto current main and still measures only mock-direct versus the Experiential gateway.

@kfallah
kfallah merged commit 9d93875 into main Aug 23, 2026
15 checks passed
@kfallah
kfallah deleted the cursor/gateway-latency-report-a764 branch August 23, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants