Skip to content

[Rewrite P6] Hardening: fuzz, benchmark gate, 72h soak, security review #868

Open

Description

@chappie-daemon

Parent: #860
Milestone: Phase 6: Hardening + benchmark
Host: both · Expected cost: $3.30

Prove the rewrite before cutover: security review, the benchmark gate, and the long-run soak.

  • Six-lens factory review of the whole nostream-relay + nostream-storage surface (security, architecture, performance at minimum; code/UX on the admin+MCP surface)
  • Fuzzing: cargo-fuzz targets on the message parser, filter parser, NIP-11 doc generator, settings loader — 24h fuzz run on tauceti, zero crashes (crashes found → issues → re-fuzz)
  • Benchmark gate (chappie rig, from [Rewrite P3] Storage seam + LMDB backend (strfry-style) + PG→LMDB migration #864's baseline): LMDB backend within 1.5× of Postgres on REQ p95 latency, ≥ 1× on ingest throughput, at 1M and 10M event corpora; results published in docs/rewrite/benchmarks.md
  • Soak: 72h run on tauceti under synthetic load (mixed subscribe/event/COUNT/negentropy traffic, restarts injected) — memory flat, no fd leaks, event-store checksums stable across restarts
  • Security review of the new surface: the MCP auth model, the settings surface, the migration tool (it holds DB credentials), LMDB file permissions
  • Docs: docs/rewrite/ completed — architecture map TS→Rust crate, deployment guide, operator migration runbook

Acceptance: fuzz clean, benchmark gate green, soak green with published evidence, review lenses PASS, docs complete.

  • Prometheus /metrics endpoint (feat: add Prometheus metrics endpoint #595): the soak's acceptance is that the relay stays healthy under sustained load, and health is unmeasurable from outside the process until this exists — connections, throughput and queue depth have to be scraped live, or the soak produces a log rather than a measurement. One build pass, inside this issue's estimate rather than as a row of its own.

Estimate basis (2026-10-24): $3.30 - the 72-hour soak is wall-clock, not tokens; fuzzing, the benchmark gate and an independent security review cost about two large jobs' review rounds. Model and per-unit costs: .factory/estimates.md.

Activity

  1. added
    rewrite
    factory
    on Oct 17, 2026
  2. chappie-daemon commented on Nov 29, 2026

    @chappie-daemon
    CollaboratorAuthor

    Row split for this issue, taken 2026-11-29 on the operator's steer to run the rewrite programme before defect tickets.

    Six rows, in this order, with the reason each is where it is:

    row issue what lands why here
    1 #595 relay counters + GET /metrics in Prometheus text format, and the admin SSE snapshot upgraded from its unavailable shape to the real numbers every row below is a measurement, and this is the instrument; the soak's acceptance is "the relay stays healthy under load", which is unobservable from outside the process until a scrape exists
    2 new, filed from the fuzz row cargo-fuzz targets for the message parser, filter parser, NIP-11 generator and settings loader, plus a short local run authorable now; the 24 h run waits on tauceti
    3 new, filed from the benchmark row the gate script and docs/rewrite/benchmarks.md, run against #864's baseline corpus depends on row 1 for the latency series and on nothing from tauceti
    4 new, filed from the soak row 72 h soak under synthetic load with restarts injected blocked on tauceti: the charter holds tauceti until the #871 runbook is agreed with Ada
    5 new, filed from the review row six-lens factory review of nostream-relay + nostream-storage, code/UX on admin+MCP, plus the security review of MCP auth, settings, the migration tool and LMDB permissions last among the reviews, so the lenses read the surface the other rows built rather than one still moving
    6 new, filed from the docs row the TS→Rust crate map, deployment guide and operator migration runbook settles once rows 1–5 say what is true

    Rows 2–6 are filed when their turn comes, not now, so each spec is written against the tree it will land on. This issue closes when all six are done.

    Starting row 1 (#595).

  3. chappie-daemon commented on Nov 29, 2026

    @chappie-daemon
    CollaboratorAuthor

    Row 1 amended after recon (job 042) — the SSE snapshot upgrade comes out of this row and becomes its own.

    Measured, not assumed: the console's snapshot updateSnapshot renders seven numeric keys, and two of them (eventsPerSecond, eventsRejectedPerSecond) need a rate window the process does not keep while cpuLoadPercent/memoryUsedMb need process statistics with no crate behind them (libc/sysinfo absent; the only procfs reader sits in nostream-cli). Doing the text endpoint and an honest snapshot in one pass, with the four parity/route/SSE fixtures it moves, is where this row would exceed one build pass and, per the recon's risks, turn an instrument into two jobs.

    So row 1 is #595 alone: the counters the relay can keep honestly, and a scrape endpoint with an auth a Prometheus target can actually use. The SSE snapshot upgrade is filed as a row of its own when it is picked up — it is still Phase 6 work, not dropped.

    Second finding worth the board: nostreamd still composes unavailable::stores() (main.rs:235,247), so an accepted-throughput counter reads 0 at this commit and every query duration times an error return. Rows 3 and 4 (benchmark gate, 72 h soak) cannot measure anything real until #1206 lands; row 1 is startable because the counters instrument the relay's own paths and are testable against a real-store harness.

  4. chappie-daemon commented on Nov 29, 2026

    @chappie-daemon
    CollaboratorAuthor

    Row 1 done: #595 merged as bb00f82eb350d291de47220ca3e4592fe00843ba (PR #1282), issue closed.

    The relay now keeps the counters #595 names and serves them as Prometheus text at GET <prefix>/metrics, behind Authorization: Bearer $METRICS_TOKEN (constant-time) and METRICS_ENABLED, outside the admin gate because <prefix>/admin/metrics is the console's SSE stream. ADR 0021 records the four decisions and their costs. AUTH's replies are carved out of the accepted/rejected families — before the carve-out a successful NIP-42 AUTH counted as an accepted event.

    Two corrections the job had to make to its own record, worth naming so the next row does not repeat them: ADR 0021 first claimed the accepted counter reads 0 until #1206, which the rebase onto 1514e7f2 made false; and Greptile caught a torn histogram read that six independent atomic loads made possible, fixed with a monotone clamp and a seam-backed regression case.

    Cost: $3.01 against a $1.85 first estimate, re-estimated to $2.75 at pr-open, then extended to $3.25 on Cameri's call to cover the histogram fix round. 21 sessions. The estimate was wrong because it priced one pass for a row that introduced a surface, a credential and an encoder; the regret line's forward rule is that a credential-plus-ADR row is priced as a two-round row.

    Rows 2–5 of the split are unaffected; row 3 and 4 no longer wait on #1206 (it merged), only on tauceti's runbook.

  5. chappie-daemon commented on Nov 30, 2026

    @chappie-daemon
    CollaboratorAuthor

    Row 3 done: #1296 merged as 7398527491bcfb2dfcaf6e14746415b6679cdf77 (PR #1297), issue closed.

    The cutover rule now has a decision, not only a document: src/scripts/bench-gate.ts reads two schema-2 artifacts and applies #868's 1.5×/1× rule as the band median and the failing edge (REQ p90, ingest p10), with a straddle counted as fail, ≥3 LMDB repeats required, a completeness refusal, and a refusal rather than a pass without a Postgres artifact. docs/rewrite/benchmarks.md D8 is now the rule's reading with the script's constants named as its definition. The REQ set is the four find_by_filters shapes — D3's old sentence contradicted its own count bullet and is corrected.

    Two defects came from CI rather than from a lens, and both were real: the gate could PASS an artifact written by a run whose verify failed (the rig writes before verifying), and spawn-only tests left the tool at zero in-process coverage (Coveralls unit is now +0.3% to 75.356%). The Coveralls integration status stays red by construction — .nycrc.json is all: true over src/** and a CLI tool has no integration path; both required jobs pass and the policy is #1298.

    Cost: $2.43 against $1.90, re-estimated to $2.45 with the reason. Three builder passes and three rounds: the rule it implements is exactly what reviewers re-derive, so the first pass was never going to be the last.

  6. chappie-daemon commented on Nov 30, 2026

    @chappie-daemon
    CollaboratorAuthor

    Row 5 done: #1299 merged as 9c25d7430d6d98b4c2c92627643bed1f01bc2740 (PR #1335), issue closed. The record is docs/rewrite/reviews/2026-11-30-relay-storage.md.

    45 findings from six lenses over 28,560 lines — 35 filed as issues, 5 linked, 2 accepted with their reason. The findings that justify the row are the ones no diff-scoped review could reach: a rejected settings document silently swapping an LMDB deployment onto the default Postgres backend (#1305); a migration verify that proves the store matches its own manifest rather than the source, so a short source read verifies clean (#1306); the daemon and the CLI opening one store through two copies of one match with the CLI dropping the settings gates (#1302); and two measured hot paths — 110 allocations per candidate row in the NIP-50 verdict (#1307) and a NIP-42 guard rebuilt per delivered row, 143 ms per maxLimit REQ at a thousand AUTHs (#1308).

    Cost: $4.49 against $2.60, re-estimated to $4.55. The overrun is worth naming plainly: ~$0.95 of it is this manager's own criteria being wrong three times — the document checks were written as prose, each version had a shell bug, and the third had to become a tested script. The rule recorded: a review row's checks are a runnable script tested against a stub record before the lenses start, and lens files are produced in the record's label shape from the first line.

    Row 6 (docs completion) is the last unblocked row; row 4 stays blocked on tauceti/#871.

  7. chappie-daemon commented on Nov 30, 2026

    @chappie-daemon
    CollaboratorAuthor

    Row 6 done: #1336 merged as 781d8d379e4c8991a963ea7779acf3449a6a6633 (PR #1338), issue closed. Rows 1, 2, 3, 5 and 6 are complete; row 4 — the 72 h soak — is the only one left, blocked on tauceti and the #871 runbook.

    The three documents are docs/rewrite/crate-map.md (357 rows: 296 capture + 61 added after the capture, every target existing), deploying.md and migrating.md, each checked by check-docs.sh — eleven scripted checks, proved by four inversions — and each command carrying its real transcript in the job record, failures included.

    What the review chain changed was content, not prose: the map's left column measured the working tree rather than the capture commit; 49 rows named a crate lib.rs or an all-stub module instead of the module that holds the port; eight capture files were labelled post-capture. Greptile found two no lens had: the deployment guide claimed Postgres migrations run in process, and they do not — stores.rs:57 → from_lookup → with_pools, migrate_pool's only non-test caller is examples/bench.rs, so an operator against an empty database gets missing-table errors; and the rollback section did not state that switching back is lossless only until the LMDB store accepts its first write.

    Cost: $2.26 against $1.40, re-estimated to $2.30. Three writer passes, because the map is not prose but a 357-row claim against two trees; the $1.50 checkpoint was crossed between the second and third pass and reported only at close-out — the rule recorded is to check the gate after every agent finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    factoryrewrite

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions