Repository navigation
Conversation
… shapes Once a key's BEGIN line opens in a stream (a reply, its thinking, a command's stdout or stderr), what follows is held until its END line, the stream's end or 16 KB, and scrubbed in one piece as the whole text. New no-END shapes: log-line prefixes (only before random-looking key lines), PHP joins, PowerShell, <line> elements, mixed-case headers, spaces before closing dashes, a letters-only last run cut short. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
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.
A private key streamed in chunks showed its body. A reply, its thinking and a command's output reach the event log a chunk at a time, and each chunk was scrubbed alone, so a key whose BEGIN line came in one chunk left every body line in the chunks after it as plain text.
Now, once a key's BEGIN line has come in a stream, the stream holds what follows until the key's END line, the stream's end or 16 KB. It then scrubs that text in one piece, exactly as the whole text is scrubbed. These are also masked now, with no END line: body lines behind log prefixes (Python logging, Go, logback, Rust tracing, Procfile runners, glog, logfmt, slog, JSON lines; quoted or not, with fields after the quote; in base64 or base64url), PHP string joins, PowerShell's
`n,<line>elements, a mixed-case header, spaces before the closing dashes, Compose v1'sapp_1 |, and a one-line key whose last run is all letters.What changes
Streams (
core/tstd/logging.pyKeyStreams,core/tstd/session.pySessionEventLog):Each stream is read in place: a model response's text, its thinking, and a command's stdout and stderr.
Before a BEGIN line, a chunk is scrubbed as it comes, as before. The one exception is a line end that may start a BEGIN line (
-----BEG), which is read with the next chunk.Once a BEGIN line with no END after it arrives, everything from that line on is held. It goes out when one of these comes:
Nothing is guessed about what is key text and what is prose: the whole-text scrub decides.
The held text and the event that ends its stream are appended together, under one hold of the log's lock.
A chunk held back whole adds no event.
A withdrawn response loses what it held.
Shapes (the PEM rules in
core/tstd/logging.py):file:42:, a logger's name right after a level (INFO app:),app_1 |, PowerShell's`nand`r`n,<line>elements, and PHP's"…" .joins.msg="…" caller=…,{"msg": "…", "level": 30}), and escaped quotes are read too.Before / after
Streamed (
e2e/td5451_stream.py): every shape in the test file, in 14 chunkings each (sizes 1–120 and random, with and without text after the key).Whole text (
e2e/td5451_shapes.py): the ticket's 14 shapes show the key on main in 14 of 14 cases, and here in 0 of 14.Log formats (
results/td5451-quoted-logs-final.log): Python logging with quotes, logfmt with a closing quote and more fields, slog, JSON lines with either key first, Go%qand Rust tracing fields show 123 of 123 key fragments on maincb20b685and 0 here, as text and escaped inside a JSON string.Independent review
Five independent reviews. Each got the diff, the ticket and main's code, and wrote its own probes. All five said FIX FIRST, and every finding was fixed, with tests that fail on the code before the fix.
The first four rounds reviewed an earlier streaming design, which guessed chunk by chunk what was key text and what was prose. Each round found new edges in those guesses:
After round four, I replaced that design with the one above. It holds what follows a BEGIN line and lets the whole-text scrub decide.
Fifth review: FIX FIRST (two defects, both fixed):
headover 12 keys showed 23–24 lines. It now holds on from the last BEGIN line in the window; both show 0.It also found long CamelCase names after a BEGIN line masked; a key line now also needs three digits. Its 450-case fuzz through the event log (sibling streams, thinking, relayed worker tool calls, results and the turn's end) matched the whole-text scrub every time.
Re-review of the fifth round: FIX FIRST (all fixed, and the reviewer's own probes are clean on the final code):
INFO app:) fell outside the logger-name prefix. The level, its padding and the logger name are now one prefix; no cut of such a key shows.=were slow (2.4 s for 200 KB against 35 ms on main), since=counted as key text. It now counts only as padding at a line's end: 34 ms.The re-reviewer confirmed the switch count is linear and unchanged, and that holding on from the last BEGIN line loses and reorders nothing.
Every review's probes, rerun on the final code:
results/td5451-review-probes-r18.log).Speed
Times per MiB (this branch:
results/td5451-timing-r9.log; main:results/td5451-timing-r8.log, the same hour). On main, each chunk is scrubbed alone.`n(worst whole text)Bounds and trade-offs (mine, not from the ticket)
Delay: text after a BEGIN line shows when the key's END line comes, the stream ends or 16 KB pass. A reply that quotes a BEGIN line in prose streams the rest of its text at the end. Thinking held this way goes out after the reply text that came later.
16 KB: a single key over 16 KB shows past 16 KB when streamed. RSA-16384, the largest common key, is about 12.6 KB.
Lost on cancel: a stream whose turn is cancelled without a turn's end loses the text it held. That text is never shown.
Generic log prefix: up to 256 characters, and only before random-looking key lines (48+ characters, 12 switches or more, and not name-like: fewer than three digits together with three CamelCase words in a row). With no END line:
app;or a prefix over 256 characters shows, as on main.With an END line, all of these are masked.
Still masked after a BEGIN line, though main keeps them: a line ending in a random-looking token behind a prefix, such as an
integrity: sha512-…hash, a mixed-case@sha256:digest, or a CamelCase name with digits between its words.Left as they are
sk-(…joEO_sk-ufby…, no END line) is cut there by the API-key rule, and the key lines after it show. Main does the same. It's a separate rule, so it's left for its own ticket.FILES_TOKEN:then its value in the next chunk) are still read chunk by chunk, as on main. This change carries only PEM keys across chunks.Tests
tests/test_pem_redaction.py: 1,144 passed (435 on main). Each review round's tests fail on the code before it.results/td5451-related-tests-r5.log).results/td5451-full-suite-r3.log).node_modules, the cargo registry): masked as on main, with 0 masks lost and 1 added, in my comment quoting a mixed-case BEGIN line (results/td5451-corpus-diff-r8.log).Checks
release_scan --git: 0 hits.🤖 Generated with Claude Code
https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR