Repository navigation
Sanitize command names in HDR output file names - #629
Conversation
|
🤖 Automated first-pass review. A human maintainer's review is still required before merge. Thanks for this. I went through the diff and the tests, and I have a few comments below. The core fix looks right to me. I like that sanitizing happens before the #587 dedup pass, and the
Nitpicking: The fix and tests look solid. I'd mainly like the spaces question answered before this merges, since that's what decides how many existing file names change. (I'd file this as a comment, not a formal block.) |
--hdr-file-prefix builds per-command file names from the display name, so --scan-incremental-iteration writes "<prefix>_SCAN <cursor>_command_run_1.hgrm". '<' and '>' are reserved file-name characters on Windows (fopen() fails and the histogram is silently lost once the native build from #553 lands), and actions/upload-artifact rejects them, so CI jobs cannot upload these files. Replace spaces, control characters and < > : " / \ | ? * with '_' in the command part of the HDR file names. The prefix, the stderr messages, the .hgrm header and the JSON keys keep the display name. Sanitizing runs before the #587 duplicate-name pass, so names that map to the same string (e.g. "A:" and "A?") still get distinct "_N" suffixes. The suffix pass now also skips an ordinal whose label is already taken by another name (e.g. a literal "A__1"), so a suffixed label can no longer overwrite another command's file. This changes user-visible file names: "SCAN <cursor>" becomes SCAN__cursor_, "SCAN 0" becomes SCAN_0, and --command-stats-breakdown=line names such as "GET (Line 1)" become GET_(Line_1). Fixes #627 Co-Authored-By: Claude Opus 5.5 <[email protected]>
3c77b9e to
3032667
Compare
|
Thanks for the review. Answers point by point: 1. Spaces in the replacement set. You're right that Windows and 2. stderr / 3. Display and file numbering can differ (e.g. Other changes in this push:
Interaction with #631. #631 (reserved-name fix: 🤖 Generated with Claude Code |
Problem
--hdr-file-prefixuses the command display name as part of the per-command file names. With--scan-incremental-iteration, master (013cb85) writes:Windows reserves
<and>in file names, sofopen()fails there and the histogram is lost after a singleperror(). This will matter once the native Windows build from #553 lands.actions/upload-artifactalso rejects these paths. Any command name containing< > : " / \ | ? *, a control character or a space has the same problem.Root cause
run_stats::save_hdr_arbitrary_commands()passescommand_namestraight into"%s_%s_command_run_%d.{txt,hgrm}". The only mapping applied today is the_Ndedup suffix from #587/#588.Fix
sanitize_file_name_component()replaces spaces, control characters (0x00-0x1f, 0x7f) and< > : " / \ | ? *with_. It is used only for the command part of the HDR file names. The prefix, stderr messages,.hgrmheader and JSON keys keep the display name; the header uses the same#Nform as the JSON keys._Nsuffixes. For example,A:andA?both becomeA_, and they are written asA__2andA__3.make_unique_labels()now skips an ordinal whose label is already taken by another name or label. Without that, a literalA__1would be overwritten by the first suffixedA_. JSON keys use the same function, so they gain the same guarantee for the equivalent" #N"case.User-visible change
HDR file names change for any command whose name contains a space or one of the listed characters:
SCAN 0<p>_SCAN 0_command_run_1.hgrm<p>_SCAN_0_command_run_1.hgrmSCAN <cursor><p>_SCAN <cursor>_command_run_1.hgrm<p>_SCAN__cursor__command_run_1.hgrmGET (Line 1)(--command-stats-breakdown=line)<p>_GET (Line 1)_command_run_1.hgrm<p>_GET_(Line_1)_command_run_1.hgrmPlain names (
GET,SET,GET_1,FULL_RUN) are unchanged. For the existing #587 duplicate-name case, the stderr "Writing ..." line and the.hgrmheader now print the JSON-key form (GET #1) instead of the file-label form (GET_1). The file names are unchanged. Scripts that glob on the old names with spaces need updating.Test evidence
Two new tests in
tests/test_hdr_histogram.py:test_hdr_file_names_are_sanitized_for_scan_cursor: SCAN with--scan-incremental-iterationover 200 keys. It asserts that no<prefix>_*file contains an unsafe character, and that theSCAN_0andSCAN__cursor_files exist. It skips on cluster, liketest_scan.py, and cleans up its keys.test_hdr_file_names_stay_unique_after_sanitizing:--command="A: __key__" --command-ratio=3 --command="A? __key__" --command="A__1 __key__" --command='A/\|*"x" __key__'with 120 requests. It asserts that no file contains an unsafe character and that each file holds the right sample count (A__2=60,A__3=20,A__1=20,A_____X_=20), so a file that was overwritten cannot pass. The fourth command covers/ \ | * "(its display name isA/\|*"x").Standalone redis,
--env existing-env, 3 runs each:histogram_SCAN <cursor>_command_run_1.hgrm, ...)histogram_A:_...,histogram_A?_...)The whole
test_hdr_histogram.pymodule, including the #587 duplicate-name test, passed in 9 local runs with the fix.test_scan.pypassed in 6 runs. CI covers the TLS, cluster and sanitizer matrix.Fixes #627. Related: #553 (native Windows build), #587/#588 (duplicate-name
_Nsuffixes).Affected versions
2.3.0 through 2.5.2 (latest) and master, as recorded in #627:
SCAN <cursor>row name. The first tag containing it is 2.3.0.🤖 Generated with Claude Code
Note
Low Risk
Scoped to HDR file path construction and label deduplication; JSON and console output keep display names. Filename changes may affect scripts that glob old paths with spaces or angle brackets.
Overview
HDR per-command output files (
--hdr-file-prefix) now use sanitized command labels in.txt/.hgrmpaths only: spaces, control characters, and< > : " / \ | ? *become_, while stderr, JSON keys, and histogram headers still use the original display names.Sanitization runs before the existing
_Nduplicate-name logic, so names that collapse to the same string (e.g.A:andA?→A_) still get distinct files.make_unique_labelsalso skips suffix ordinals already taken by another command or label (fixes collisions with a literal name likeA__1).The README documents the naming scheme and examples (
SCAN <cursor>, line-breakdown stats). RLTest adds coverage for--scan-incremental-iterationand post-sanitize uniqueness/sample counts.User-visible: HDR filenames change when command names contained unsafe characters; plain names like
GET/SETare unchanged.Reviewed by Cursor Bugbot for commit 3032667. Bugbot is set up for automated code reviews on this repo. Configure here.