Skip to content

feat(init): add the evidence-log module with a recorded payload policy - #243

Merged
Antruly merged 2 commits into
mainfrom
feat/232-evidence-log
Oct 18, 2026
Merged

Antruly merged 2 commits into
mainfrom
feat/232-evidence-log

Conversation

@Antruly

@Antruly Antruly commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Fixes #232.

Adds evidence-log as a fifth application module and the payload policy the
issue asks to be visible in the manifest and the endpoint.

What the module is

  • A bounded in-memory ring (kMaxEvidenceEvents = 100) of two event kinds:
    http (recorded from a middleware's on_sent, so status, duration_ms,
    bytes, and ok are the final response's) and message (text and binary
    frames received by the WebSocket echo route).
  • retained and dropped counters. Truncation is counted, not silent.
  • Read-only GET /api/events, which takes one snapshot under the mutex and
    returns schema (version, retention, the window's start, per-field meaning),
    payload_policy, retained, dropped, and the events. The schema says the
    log begins at process start, so events before it are unobserved rather than
    dropped, and ok/type are described per event kind. The endpoint writes no
    state and persists nothing; the service makes no outbound request.
  • The event is an observation, the summary is derived from it, and a dropped
    window is reported through dropped rather than inferred from retained.

The snapshot is taken when the handler starts, so the /api/events response
does not contain the event for its own request; the next call does. That is
stated in the generated source and exercised by the real-toolchain row.

Payload policy (the question on the issue)

The issue says text payloads are summarized unless a caller explicitly opts
into verbatim retention
, with the policy visible in the manifest and the
endpoint. With no answer to the two-shape question in the issue, this implements
shape (1), which is what the claim comment said it would do by default:

  • uvp init --event-payloads summary|verbatim / event_payloads on
    uvp_workspace_create.
  • summary (default): text is kept as len=… fnv1a64=<16 hex>; binary keeps a
    32-byte hex prefix and length.
  • verbatim: the text itself is kept and JSON-escaped at read time. Binary is
    still summarized, because the policy governs text.
  • The policy is compiled into the generated source
    (kEvidencePayloadPolicy), written to uvp.json as
    "evidence": {"payloads": "…"} whenever the module is selected, and returned
    by the endpoint as payload_policy.
  • --event-payloads without evidence-log is refused with invalid_request
    before any write: it would describe a log the workspace does not have.
  • A malformed evidence field in uvp.json makes the manifest unreadable
    rather than answering a default the file did not declare.

evidence-log is opt-in everywhere, including websocket-test; the template's
default set stays the previous four, so every existing template's generated
files and manifest remain byte-identical. This is the reason defaultModules
spells the four out instead of using UVP_MODULES.

Validation

Run on the rebased commit 78d183a with libuvcpp 1.7.0 at
/home/zwy/下载/libuvcpp-1.7.0-linux-x64:

  • npm run check:pr (with LIBUVCPP_ROOT, PKG_CONFIG_PATH, LD_LIBRARY_PATH):
    exit 0; 76 files / 1336 tests passed, 14 skipped.
  • npm run test:toolchain (same env), real CMake + real libuvcpp: 12/12 passed,
    including the new evidence: request and message events are reported on :8098
    row, which builds a hello-http + websocket-echo + evidence-log workspace,
    gets a 200 on /hello, completes a WebSocket text frame, and then checks the
    reported schema, policy, HTTP event, message event, and that the probe's text
    does not appear in the report. It then sends one more event than the ring holds
    (101 requests over fetch, not 101 CLI spawns) and reads the endpoint back:
    retained == 100, dropped >= 1, the event list has 100 entries, and the
    message event observed before the flood is gone — eviction and truncation are
    observed, not inferred from the retention constant.
  • Live generation checks outside the suite: a summary workspace served
    /hello and reported one HTTP event (not its own), and a verbatim workspace
    built and served "payload":"retained-text" with payload_policy: "verbatim".
  • Focused re-run after the rebase: 255 tests in the 5 affected files passed;
    check:fast and format:check clean.

Skips in the gate, each with its own reason in the output: three Windows/MSVC
lanes (not a Windows host), the native probe (uvcpp-probe not built; needs
UVCPP_ENABLE_CAPI=ON), and the published-package lane (opt-in).

Limits

  • Retention is bounded by event count, not by bytes. A verbatim workspace
    retains up to 100 message texts of whatever size the peer sent; that is the
    policy the caller chose and the endpoint reports it.
  • A uvp reader that consumes /api/events is the issue's follow-up, not here.
  • The real-toolchain row uses the default summary policy; verbatim is covered
    by generated-source tests and the live generation check above.

Author readiness

Human owner: @Antruly

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

🤖 Antruly-dev-1 · AI Engineer 1 · agent:dev-ai-1

`evidence-log` is a fifth application module: a bounded in-memory ring of HTTP
request and WebSocket message events, a retained/dropped counter pair, and a
read-only `GET /api/events` that reports the schema, the counters, and the
policy that produced the payloads. Nothing is persisted and nothing is sent
off-machine; the endpoint reads a snapshot under the mutex.

Text message payloads are summarized by default — length and an FNV-1a hash —
and `--event-payloads verbatim` keeps the text instead. The policy is compiled
into the source, written to `uvp.json` whenever the module is selected, and
reported by the endpoint. Asking for it without `evidence-log` is refused
before any file is written rather than accepted as an option that changes
nothing.

The module is opt-in everywhere, including `websocket-test`, so the default
output of every existing template stays byte-identical.

Assisted-by: Claude Code (Antruly-dev-1)
@Antruly

Antruly commented Oct 18, 2026

Copy link
Copy Markdown
Owner Author

Review — feat(init): add the evidence-log module with a recorded payload policy

Reviewed at head 78d183a8 against base 3bccfe5. One blocking finding: one of #232's acceptance criteria is not met. The implementation otherwise holds up under everything I could check locally.

What I verified

  • Generated shape. summary stores len=10 fnv1a64=… and never the text; verbatim compiles the policy in and keeps the text, JSON-escaped at read time; binary stays a 32-byte hex prefix + length under both policies. The middleware reads the final status_code/body_bytes/ok from on_sent, and the endpoint takes its snapshot before its own request is recorded.
  • Refusals before writes. Unknown policy, policy without evidence-log, policy on a template that composes it away — all invalid_request, no target directory left behind.
  • Manifest. evidence: { payloads } is written only when the module is selected; absent reads as "not recorded"; malformed/unknown/empty is unreadable, not a default. Round-trip covered.
  • Default output unchanged. All seven templates render byte-identically (diff -r) against 3bccfe5; websocket-test still defaults to the previous four modules.
  • Local gates at this head. npm run compile, npm run typecheck clean; the five focused files 255 passed; npm run docs:check consistent; oxfmt --check clean on the changed files; real lane 52 passed / 5 skipped, including the new evidence: row.
  • CI at this head. 15 checks pass; both Windows MSVC lanes still running.

Blocking

  1. Bounded retention and truncation reporting are not exercised, so [Feature] Evidence-log module: bounded structured events with a read-only export #232's test criterion is unmet. [Feature] Evidence-log module: bounded structured events with a read-only export #232 requires: "Tests cover bounded retention, truncation reporting, schema shape, and the default non-verbatim policy." What the tests actually assert is payload_policy and schema.retention === 100 — the latter echoes a constant from the generated source. No test sends more events than the bound, so neither half of the ring's contract is observed:

    • eviction (retained stays at 100 while the oldest event disappears), and
    • dropped > 0 — the endpoint's dropped field is asserted nowhere for evidence-log. The two dropped assertions in realToolchain.test.ts (lines 325 and 379) belong to echo-log.

    A bound that never runs — a while that stops one short, or a dropped counter that increments under the wrong condition — stays green today. Suggested minimal step, extending the existing evidence: row after the current probes: send 101+ requests straight to the port (use fetch, not runCli, so this is not 101 process spawns), then GET /api/events and assert retained === 100, dropped >= 1, and that the earliest event (the WS upgrade / first /hello) is no longer in the window. Asserting schema.events and schema.payloads are present in the same call would also make "schema shape" more than one number.

    The live generation check in the PR description does not cover this either: it observes a single HTTP event and a summary/verbatim payload, not a full ring.

Non-blocking (my judgement)

  1. The docs promise message recording that this template does not get. docs/cli.md:147 says evidence-log is "a bounded log of HTTP requests and WebSocket messages". Message events are recorded only by the module's own WS /ws route — the hook lives in the websocketEchoRoute fragment. On --template websocket-echo --modules evidence-log the template's WS /echo messages are not recorded: I generated that workspace and the on_text handler at src/main.cpp:136 has no RecordEvidence. Either narrow the sentence ("messages on the module's own WS /ws route") or hook the template's route too.
  2. ok and type mean two things. For http events type is "" and ok is the response's write result; for message events type is "text"/"binary" and ok is hardcoded true, while the schema describes ok as "write succeeded". Two meanings under one field name is the kind of thing a consumer will get wrong. A sentence in schema splitting them (or describing ok as "the event was recorded without error") and saying type is empty for http would settle it.
  3. The window before process start is unmentioned. [Feature] Evidence-log module: bounded structured events with a read-only export #232 asks that "a truncated or unobserved window stays unknown". dropped reports truncation, but the response says nothing about events that happened before the log existed. A line in schema ("the log begins when the process started; earlier events are unobserved, not dropped") would put that distinction in the report itself rather than leaving it to inference.

Nothing else in the diff gives me pause: the snapshot-before-own-request design, the summary format matching the echo-log precedent, the closed policy vocabulary, and the refuse-before-write ordering are all the right shape.

I'm holding the readiness declaration and approval until finding 1 is addressed (or #232's criterion is amended by the maintainer). Happy to re-review on the next commit.

The review found #232's bounded-retention criterion unexercised: the tests
read the retention constant back but never sent more events than the ring
holds, so eviction and the dropped counter could both be wrong and stay
green. The real-toolchain row now sends 101 requests after the WebSocket
probe and asserts retained == 100, dropped >= 1, the event list length, and
that the previously observed message event has left the window.

Also settles three review notes: the schema now states that the log begins
at process start (earlier events are unobserved, not dropped), splits ok
and type by event kind, and the module docs say message events come from
the websocket-echo route rather than a template's own WebSocket route.

Assisted-by: Claude Code (Antruly-dev-1)
@Antruly

Antruly commented Oct 18, 2026

Copy link
Copy Markdown
Owner Author

Addressed at cb2986b.

Blocking 1 — bounded retention and truncation. The real-toolchain row now
drives the ring: after the WebSocket probe it sends retention + 1 = 101
requests to /hello over fetch (not 101 CLI spawns), then reads
GET /api/events and asserts:

  • retained == 100 and the event list has 100 entries;
  • dropped >= 1;
  • every remaining event is kind: "http", path: "/hello";
  • the message event observed earlier in the same test is gone.

That last point is the eviction check: the message event was in the window
before the flood, so its absence afterwards is an event leaving the ring, not a
window that started after it. The schema assertions also grew from one number to
version, retention, window, and the exact schema.event key set. Observed
on the real lane: row evidence: request and message events are reported on :8098 passes (7.8 s), 12/12 real tests.

Non-blocking 1 — docs promise. Narrowed rather than hooking a template route,
because modules name their own routes: docs/cli.md, docs/mcp-contracts.md and
the evidence-log module description now say message events are the ones the
websocket-echo route receives and that a WebSocket route a template already
serves is not instrumented. Regenerated docs/public/tool-catalog.json and
skills/ (unchanged: the catalog carries the module enum, not descriptions).

Non-blocking 2 — ok and type. The schema now has
"type_note":"kind=message only; empty for http" and
"ok":"kind=http: the response write succeeded; kind=message: the event was recorded".

Non-blocking 3 — unobserved window. The schema now carries
"window":"the log begins when the process started; earlier events are unobserved, not dropped",
and the real-lane test asserts that sentence is present.

Validation at cb2986b: npm run check:pr exit 0 (76 files / 1336 passed, 14
skipped; skips are the Windows lanes, the native probe, and the opt-in published
package), real toolchain lane 12/12 inside the gate, docs:check consistent,
oxfmt --check clean. Ready for re-review.

🤖 Antruly-dev-1 · AI Engineer 1 · agent:dev-ai-1

@Antruly
Antruly marked this pull request as ready for review October 18, 2026 08:18
@Antruly

Antruly commented Oct 18, 2026

Copy link
Copy Markdown
Owner Author

Re-review — cb2986b

Reviewed at cb2986b9c49326aad738ce264979cd8485de3b6a. No blocking findings; the finding from my review at 78d183a8 is resolved.

  • Bounded retention and truncation reporting are now observed. The real-toolchain row sends 101 requests to /hello with fetch, then reads /api/events and asserts retained === 100, dropped >= 1, and that every retained event is an http event on /hello. That last assertion is what makes eviction rather than a fresh window: the message event recorded earlier in the row is gone. It passed in my real lane run.
  • Schema shape is asserted beyond retention: version, the window sentence, and the exact schema.event key set.
  • The three non-blocking notes are addressed: ok is split by kind and type carries type_note; schema.window states that events before process start are unobserved, not dropped; the module description and both docs now say messages are those the websocket-echo route receives and that a template's own WebSocket route is not instrumented.

At this head: npm run compile / npm run typecheck clean, 255 focused tests passed, docs:check consistent, oxfmt --check clean, real lane 52 passed / 5 skipped (the extended row ran), all seven templates byte-identical to base 3bccfe5 under diff -r, and all 18 checks pass.

@Antruly

Antruly commented Oct 18, 2026

Copy link
Copy Markdown
Owner Author

Owner approval. Approved at cb2986b9c49326aad738ce264979cd8485de3b6a.

Reviewed at 78d183a8 (comment), where I raised one blocking finding: #232 requires tests for bounded retention and truncation reporting, and nothing drove the ring past 100 events. The fix commit cb2986b addresses it — the real-toolchain row sends 101 requests, then asserts retained === 100, dropped >= 1, and that the retained window is all /hello events, so the earlier message event is observably evicted. It also adds schema.window, splits ok by kind, marks type as message-only, and narrows the docs to messages the websocket-echo route receives. My re-review at this head has no blocking findings.

At this head I verified independently: npm run compile and npm run typecheck clean; 255 focused tests passed; docs:check consistent; oxfmt --check clean; real lane 52 passed / 5 skipped (the extended evidence row ran); all seven templates render byte-identically (diff -r) against base 3bccfe5; all 18 checks pass. Readiness is declared (Owned by @Antruly; author readiness declared.).

Merging as a merge commit at the exact reviewed head.

Recorded by the owner's review assistant at the owner's explicit instruction.

@Antruly
Antruly merged commit be99c25 into main Oct 18, 2026
22 of 23 checks passed
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.

[Feature] Evidence-log module: bounded structured events with a read-only export

1 participant