Skip to content

server: an opt-in request journal with replay and crash quarantine - #3221

Merged
ashhart merged 3 commits into
mainfrom
lead/request-log-replay
Nov 19, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/request-log-replay

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

TENSORFOLD_REQUEST_JOURNAL=PATH turns on a request journal for chat and completion requests. Each request writes three JSON lines: start before any work (reply id, route, fingerprint, the client's seed, the redacted body), prepared before the engine sees it (the seed and sampling the server resolved, the prompt's token count and SHA-256) and finish after the reply (status, outcome, the reply's size, SHA-256 and token hash, and its bytes up to 4 MiB).

Privacy: off unless set, and only PATH and its siblings are written. The journal holds prompts and replies in full and the docs say so. PATH and PATH.lock are created owner-only (0600); a symbolic link or a file others can read is refused, and a second server on the same journal does not start. Image URLs and PDF data are redacted as in TENSORFOLD_REQUEST_LOG, which is unchanged. No HTTP header is journaled, so API keys never reach it, and benchmark child servers drop the variable.

Size: a file rotates at 64 MiB and four are kept (256 MiB at most); a record is at most 8 MiB, past which a body or reply keeps its size and hash. Each record is one write with no sync. A failed write loses that record and is logged once; the request is never failed or held. The start record is written before the engine runs (that is what makes quarantine work), so keep the journal on a local disk.

Crash quarantine: on the next start, every request a crash left unfinished is flagged and never retried. A request in flight at two crashes is refused with a 400 request_quarantined before the engine sees it. The match is a SHA-256 of the API key's label, the route and the body, so other keys and other bodies are served as before; the check is one hash lookup. A quarantine lapses after 24 hours, tools/replay_request.py --clear lifts one, and a clean stop flags nothing.

Replay: tools/replay_request.py lists, clears and replays a journaled request. A replay sends the journaled body, adding the drawn seed when the client sent none, and compares the generated output and tensorfold.token_sha256, so equal means the same tokens; ids, timestamps, timings and cache hits are left out, and --whole-body compares every byte. Replay is exact on the same build, checkpoint, drafter and server flags; not across builds, for redacted media, or for unseeded multi-generation (Cortheon) requests.

With the variable unset, the request path is unchanged: nothing is hashed and no record is built.

Tests: zig build test-request-journal-host runs ten host tests on a fake engine: the records and exact reply bytes, replay by the drawn seed (and a mismatch without it), redaction and file modes, the two-crash rule per key, clean stops, clears, lapses, torn and unreadable lines, rotation, a failing write, and the journal-off path. tools/test_replay_request.py covers the replay tool. test-server-cpu, test-golden and test-server-security pass.

Still owed: a served check on a real checkpoint (journal on and off giving the same tokens, latency, and a kill-and-restart cell).

Fixes #3188

  • Synthena (Ash's Agent)

TENSORFOLD_REQUEST_JOURNAL=PATH journals each chat and completion request
as three JSON lines: start before any work (reply id, route, fingerprint,
the client's seed, the redacted body), prepared before the engine sees it
(the seed and sampling the server resolved, the prompt's token count and
SHA-256), and finish once the reply has gone (status, outcome, the reply's
size, SHA-256 and token hash, and its bytes when they fit 4 MiB).

- Privacy: off unless set. PATH and PATH.lock are created 0600, a link or
 a file others can read is refused, and one server holds the lock. Image
 URLs and PDF data are redacted as in TENSORFOLD_REQUEST_LOG, which is
 unchanged; no header is journaled; benchmark child servers drop the
 variable.
- Size: a file rotates at 64 MiB and four are kept; a record is at most
 8 MiB, past which a body or reply keeps its size and hash. Each record is
 one write with no sync: a failed write loses that record, is logged once,
 and the request goes on.
- Quarantine: the next start flags every request a crash left unfinished.
 A fingerprint (the API key's label, the route, the body) in flight at two
 crashes is refused with a 400 request_quarantined before the engine sees
 it; other keys and other bodies are served. It lapses after a day, a
 clear record lifts it, and a clean stop flags nothing.
- tools/replay_request.py lists, clears and replays a request, adding the
 drawn seed when the client sent none, and compares the reply's output
 and token hash, or every byte with --whole-body.

With the variable unset the trace hands back the caller's own output and
writes nothing. Host tests on a fake engine cover the records and reply
bytes, replay by the drawn seed, redaction and file modes, the two-crash
rule per key, clean stops, clears, lapses, torn and unreadable lines,
rotation, a failing write and the journal-off path
(zig build test-request-journal-host).

Fixes #3188
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.

Request log with replay and crash quarantine

1 participant