Files
hermes-agent/tests
kshitijk4poor 1befb8fb40 test(perf): Pattern-B scaling guards — pin hot-path complexity in CI
Pattern B (O(N²) rebuild-per-delta in hot paths) has no lintable
signature, unlike Pattern A's ASYNC ruff gate: `s += frag` is quadratic
in a hot loop and harmless elsewhere. The only durable prevention is
behavioral — pin the scaling SHAPE of each known hot path and fail CI
when it regresses.

New tests/perf_guards/test_pattern_b_scaling.py, three guards:

1. Streamed-text accumulation (fix in flight: #92166)
   Self-normalizing ratio: time at 16k deltas over 4k deltas.
   Linear ≈ 4x, quadratic ≈ 16x; main measures 9.6x → strict bound 7.0.
   xfail on today's main, PASSES on the #92166 branch (verified).

2. list_sessions_rich statement count (fix in flight: #95380)
   Deterministic — counts writer-connection SQL statements via sqlite
   trace callback, zero timing. Bounded-constant guard xfails on main
   (measured N+1: 26 stmts / 12 sessions), PASSES on #95380 (verified).
   A second, weaker budget guard (≤4·N+8) passes TODAY and catches a
   regression from N+1 to N·M immediately.

3. Tool-call fragment assembly (#92242 shape)
   Ratio guard on the buffered-parts accumulator model; sized so the
   small case takes ≥3ms (sub-ms bases jitter on CI runners).

Flake hardening: min-of-K timing, ratio thresholds with ≥2x separation
from both measured-good and measured-bad, operation counts preferred
over timing. 10/10 identical outcomes across repeated local runs.

The xfail markers are the ratchet contract: each names its fix PR and
must be removed when that PR merges, flipping the guard to enforcing.
2026-08-28 11:54:33 +05:30
..