Skip to content

Claude/phase d3 mtls handshake and header rewrite scenarios - #81

Merged
hyperpolymath merged 6 commits into
mainfrom
claude/phase-d3-mtls-handshake-and-header-rewrite-scenarios
Aug 11, 2026
Merged

Claude/phase d3 mtls handshake and header rewrite scenarios#81
hyperpolymath merged 6 commits into
mainfrom
claude/phase-d3-mtls-handshake-and-header-rewrite-scenarios

Conversation

@hyperpolymath

@hyperpolymath hyperpolymath commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #

Type of change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (would change existing behaviour)
  • 🕳️ Soundness fix (fixes a checker/proof false-negative)
  • 📖 Documentation
  • 🧹 Refactor / tech debt (behaviour-preserving)
  • ⚡ Performance
  • 🔧 Build / CI / tooling

How has this been verified?

Checklist

  • My commits are signed (git commit -S).
  • I ran the project's own checks/tests locally and they pass.
  • New files carry the correct SPDX-License-Identifier (code/config MPL-2.0,
    prose CC-BY-SA-4.0); I did not relicense existing files.
  • Docs are updated, and no public claim now overstates what the code does.
  • I have not introduced a soundness hole (or I have flagged where I might have).

Notes for reviewers


Summary by Gitar

  • Performance bench harness (Phase D-3):
    • Added dedicated trust-header rewrite scenario isolating Proxy.build_backend_headers/1 overhead
    • Added mTLS handshake and mTLS amortised (N=16 kept-alive) scenarios using an in-memory test CA chain
  • Benchmark seam:
    • Exposed Proxy.__benchmark_build_backend_headers__/1 as a @doc false hook for latency measurement
  • Documentation:
    • Updated docs/perf-contract.md to Phase D-3 status, reflecting the six total benchmark scenarios

This will update automatically on new commits.

hyperpolymath and others added 2 commits May 27, 2026 06:19
Phase D-2 (PR #14) left two cost surfaces folded into the
"exact route allow (proxy 200)" scenario: the Phase A contract-header
construction in Proxy.build_backend_headers/1, and the transport-level
mTLS handshake. A baseline collected from D-2 would have attributed
both to the proxy-200 number, so a regression in either would only
show up as an aggregate slowdown -- the comparator couldn't tell us
which leg moved.

Phase D-3 (this change, hyperpolymath/standards#99 sub-deliverable)
pulls each into its own Benchee scenario so D-4 baseline collection
attributes them independently:

  * "trust-header rewrite (Proxy.build_backend_headers)" - direct
    call to a new @doc false Proxy.__benchmark_build_backend_headers__/1
    seam over the existing private build_backend_headers/1. No policy
    lookup, no Gateway.call/2 pipeline, no network I/O. Isolates the
    cost surface the Phase A contract invariant lives on: the gateway
    sets X-Trust-Level / X-Request-ID as authoritative values that
    shadow any client-supplied header, and the cost of building that
    final header map is what this scenario measures.

  * "mTLS handshake (test CA)" - raw :ssl acceptor + :ssl.connect/4
    + immediate :ssl.close/1, using a test CA chain generated in-memory
    at bench startup via :public_key.pkix_test_data/1. Each iteration
    is one fresh handshake (verify_peer + cert chain validation +
    key exchange) closed before any application bytes are exchanged.
    Bounds the connection-spike SLO Phase E rollout has to budget for.

Why in-memory rather than reusing the committed Phase B fixture in
test/fixtures/mtls/: the fixture ships only *.crt files -- *.key is
gitignored at the repo root. Reusing the committed certs would require
committing the matching keys (or carving a fixture exception in
.gitignore), which the estate security posture prefers we don't do
for a bench fixture. The chain shape (test CA -> server peer + test CA
-> client peer, verify_peer enforced) is identical to Phase B's
fixture; only the key material differs, and it never touches disk.

bench/baseline.json gains the two new scenario keys (both TODO; the
_status stays "scaffold-placeholder" because D-3 still doesn't collect
real numbers -- D-4 does, via the `perf: rebaseline` ritual in
docs/perf-contract.md). _schema_version bumps 0.1.0 -> 0.2.0 to signal
the shape change to anyone diffing the file or running compare.exs
against an older results.json.

docs/perf-contract.md moves both items from "Out of scope" to in scope,
adds them to the scenarios table and the targets table, and re-anchors
the remaining out-of-scope list on D-4 (baseline collection), Phase E
(historical dashboard), and a possible follow-up amortised-handshake
scenario if D-4 numbers show the proxy-200 + handshake bracket is
loose. Phase D-3 is the last harness-shape change before D-4
collection: scenario keys are now stable, the comparator's per-scenario
diff stays correctly keyed across the flip from scaffold to active.

Unblocks: standards#99 D-4 (real baseline collection + gate arming)
and, downstream, the remaining items in section 1.1 of boj-server's
docs/integration/hcg-tier2-rollout-runbook.md.

Refs hyperpolymath/standards#91
Refs hyperpolymath/standards#99

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…over-keep-alive)

Closes the bracket scenarios 3 + 5 left loose: per-iteration cost is
(handshake + N * request) / N which approximates the per-request cost
the Phase E rollout sees once the handshake is amortised across a
kept-alive pool.

Adds:
  - bench/gateway_latency.exs: scenario 6
    "mTLS amortised (test CA, N requests over kept-alive)" plus a
    dedicated kept-alive acceptor on port 19_879 running an echo loop
    (separate listener from scenario 5 so its close-on-handshake shape
    doesn't kill the kept-alive connection). N=16; payload is a tiny
    8-byte ASCII frame.
  - bench/baseline.json: new scenario key with TODO placeholders;
    _schema_version bumped to 0.3.0-scaffold.
  - docs/perf-contract.md: scenarios table + targets table now list six
    scenarios; the previously deferred amortised follow-up is moved
    out of "Out of scope" into in-scope.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gitar-bot

gitar-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@hyperpolymath
hyperpolymath merged commit 3e60cbe into main Aug 11, 2026
18 of 19 checks passed
@hyperpolymath
hyperpolymath deleted the claude/phase-d3-mtls-handshake-and-header-rewrite-scenarios branch August 11, 2026 23:28
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.

1 participant