Repository navigation
server: an opt-in request journal with replay and crash quarantine - #3221
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/request-log-replay
branch
from
November 14, 2026 01:00
b5e1301 to
c96bb77
Compare
4 tasks done
ashhart
force-pushed
the
lead/request-log-replay
branch
3 times, most recently
from
November 18, 2026 17:39
d35a6f0 to
c5a2329
Compare
This was referenced Nov 19, 2026
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
ashhart
force-pushed
the
lead/request-log-replay
branch
from
November 19, 2026 05:45
c5a2329 to
69ed6e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TENSORFOLD_REQUEST_JOURNAL=PATHturns on a request journal for chat and completion requests. Each request writes three JSON lines:startbefore any work (reply id, route, fingerprint, the client's seed, the redacted body),preparedbefore the engine sees it (the seed and sampling the server resolved, the prompt's token count and SHA-256) andfinishafter 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_quarantinedbefore 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 --clearlifts one, and a clean stop flags nothing.Replay:
tools/replay_request.pylists, 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 andtensorfold.token_sha256, so equal means the same tokens; ids, timestamps, timings and cache hits are left out, and--whole-bodycompares 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-hostruns 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.pycovers the replay tool.test-server-cpu,test-goldenandtest-server-securitypass.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