Repository navigation
TD-5449: Scrubber: the sk- rule reads a run once - #309
Merged
Merged
Conversation
The sk- rule's words lookahead (TD-5160) ran at every "sk-" after a
lowercase letter and read to the end of the run, so "xsk-" * n took
n^2/2 steps: redact_secrets("xsk-" * 8000) took 2.9 s, and every
reply's scrub runs this rule.
_SkKeys finds exactly the regex's matches in one pass: the text after
"sk-" starts a segment of its run, so "the rest reads as words" is
"every segment from here reads as a word", known for every segment
start from one pass from the right. The regex is kept as
_SkKeys.pattern and the two are checked against each other. The UI
belt (redact.ts) had the same rule and gets the same reading.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
Review of #309: _sk_words_from (and wordsFrom in redact.ts) kept a list and a dict entry per segment of a run, so "xsk-" + "a-" * N peaked at 90x a 1 MiB input in Python and grew the node heap by 284 MiB at 4 MiB. A body reads as words exactly when it starts after the run's last segment that isn't a word, so that one number is all a run keeps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
captcrock
force-pushed
the
td/5449-sk-rule-linear
branch
from
December 3, 2026 22:12
5b4b7af to
3d9a6cc
Compare
…49 sections) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The sk- key rule was quadratic. Its words check (TD-5160) ran at every "sk-" after a lowercase letter and read to the end of the run, so
redact_secrets("xsk-" * 8000)took 2.9 s. Every reply's scrub (scrub_wire_json) runs this rule, so any model output, file or Code feed line of that shape froze the daemon. Now each run is read once, and the rule finds exactly the same keys as before.Was stacked on #306 (TD-5447), which also changes
core/tstd/logging.py. #306 is merged, and this branch is rebased onto main: two commits.What changes
core/tstd/logging.py:_SkKeysreplaces the sk- regex inSECRET_PATTERNS, with thesub,finditerandsearchits callers use. The regex is kept as_SkKeys.pattern.ui/src/lib/redact.ts: the UI belt had the same rule and the same cost.skKeySpansreads it the same way.Before / after
redact_secrets("xsk-" * n), one core:71a29921)The UI belt,
"xsk-" * n: the old regex in node took 0.014 s at 2,000, 0.225 s at 8,000 and 3.734 s at 32,000.skKeySpanstakes 0.002 s at 2,000, 0.038 s at 32,000 and 0.078 s at 128,000.Same keys as before:
suboutput (e2e/td5449_sk_equivalence.py, run again on the final commit).SK_KEY_SOURCE.New tests:
group,span,start/endfor groups 0 and 1, a function asrepl,count,finditer) answers like the regex's;xsk-foo-Ask-…,xsk-foo-sk-…) is still caught;xsk-,xsk_andask-word-are left alone within 5 s (0.19 s here; the regex would take minutes, est. from its growth);xsk-within 2 s.Independent review
A fresh reviewer agent with read-only access, and no access to my conclusions, reviewed the first version and wrote its own scripts, run on one core.
redact.tsagainstSK_KEY_SOURCE). Spans,group(),searchandsubmatched the regex every time.xsk-took 28 ms throughredact_secrets; a 390,000-character word run ending in a key took 50 ms._SkKeyscopied only part of there.Patterninterface. Every current caller was fine, butgroup(1),start()/end(), a function asreplandcountdidn't work, andfinditerreturned a list. Now they work as the regex's do. A regex template string (\1) is refused rather than put in literally._SkKeys.patternkeeps the regex's group, and a test checks each of these against it.Second review (by the manager), on
5b4b7af2: about 3.99 million Python cases against the old regex, 60,000 through TS and Python, and 16.9 million TS-only all gave 0 mismatches. 32 KB ofxsk-went from 3.02 s to 0.006 s. One finding, fixed in the second commit:Map) entry for every segment of a run."xsk-" + "a-" * Npeaked at 90× a 1 MiB input in Python (tracemalloc), and grew the node heap by 284 MiB at 4 MiB. Now a run keeps one number: the Python peak is 1.0× the input (the output string), and the node heap grows by 4.0 MiB at 4 MiB. A new test holds the peak under 3× the input on two such runs; it fails on5b4b7af2.Tests
Not run locally: the full suite; the machine is on a CPU hold for other work.
CI: runs on this PR now that its base is main. (Before, while it was stacked, CI was started by hand on the first commit: https://github.com/ThatSimpleTech/TST-Desk/actions/runs/47212126385.)
redact_secrets,scrub_wire_json,secret_spansorSECRET_PATTERNS(includingtest_security_suite.pyandtest_pem_redaction.py), andtests/test_steering_proposals.py: 1,246 passed.redact.test.tsandnotifications.test.tspass (59), andtsc --noEmitis clean.Checks
release_scan --git: 0 hits.🤖 Generated with Claude Code
https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR