Pull requests / #3619

#3619 [Other] strata_bench redaction: a folder is replaced before the short user name inside it (#3326)

open · @ctr-137 · 0 コメント · GitHub で見る

BenchmarksSetup & installServer & APIModels & quantsWindowsLinux

本文

## Problem and result

`tools/strata_bench.py` writes a report you can share, and `redactor()` is what makes it shareable: home folders, the Strata folder, user and host names, IP addresses and the API key become placeholders. The substitutions were applied in the order of the **compiled pattern** length. A user or host name is wrapped in word bounds (`(?<![\w-])` … `(?![\w-])`, 19 characters more), so a short name always looked longer than the folder that holds it: the name went first, and the `<strata>` and `<home>` patterns then had nothing left to match.

Same input, before and after, measured with user `dgbox` and repository `/home/dgbox/Strata` (forward slashes; the backslash forms were checked the same way):

```
loading /home/dgbox/Strata/strata-x.json
  before  loading /home/<user>/Strata/strata-x.json
  after   loading <strata>/strata-x.json

in /home/dgbox/data
  before  in /home/<user>/data
  after   in <home>/data

engine /home/dgbox/Strata/engine/strata.exe --native /home/dgbox/models/m-IQ3_XXS.gguf --ctx 65536
  before  engine /home/<user>/Strata/engine/strata.exe --native /home/<user>/models/m-IQ3_XXS.gguf --ctx 65536
  after   engine <strata>/engine/strata.exe --native <home>/models/m-IQ3_XXS.gguf --ctx 65536
```

The name itself was still replaced in the old order, so nothing leaks the account name. What the report lost was the placeholders: on such a machine `<strata>` and `<home>` never appeared, the install layout stayed in the text (`/home/…/Strata/engine/…`), and the tool's own redaction test failed. On Windows the same ordering costs the `<home>` placeholder (`C:\Users\<user>\data` instead of `<home>\data`).

## Related discussion

Issue #3326 — it names the cause, the environment and the failing test. No scope agreement needed: one tool, no default changed, no other code reads this list.

## Approach

`subs.sort(key=lambda s: -s[2])` — by the length of the **text that is replaced**, not of the pattern that matches it. A folder is always longer than the name inside it, so the container is now always replaced before its own name. Entries of the same length keep the order they were added in (folders come before names). Which values are collected, the `len >= 4` floor, `path_user`, the IP ranges, the bearer and the key rules are untouched.

## Validation

Environment: Windows 11 Pro 10.0.26200, Python 3.14.7, no GPU. Branch from `main` at `011c9e60`; every check re-run at `26e07312`.

**Passed:**

- `python -X utf8 tools/test_strata_bench.py` -> `Ran 18 tests in 12.949s` / `OK` — the 17 tests that were there plus the new one.
- `python -X utf8 -m unittest tools.test_strata_bench.RedactionTests` -> `Ran 4 tests` / `OK`.
- New test `test_a_folder_under_a_short_home_keeps_its_own_placeholder`: it pins the reporter's machine inside the test by patching the values `redactor()` reads (`ROOT` `/home/dgbox/Strata`, home `/home/dgbox`, user `dgbox`, host `dgbox-ubuntu-server`, tmp `/tmp`), so it measures the same thing on any PC, and it covers a Windows layout in the same test.
- `python -X utf8 -m unittest tools.test_strata_bench.RedactionTests.test_paths_names_ips_and_keys` -> `Ran 1 test` / `OK`, both before and after the change. This is the reporter's own command, and it is green here in either case: the account name on this PC is one character and `add()` skips anything shorter than four, so this machine never had the condition. The failing case is carried by the pinned layout above.
- Neighbours: `python -X utf8 tools/test_bench_host.py` 5 tests `OK`, `python -X utf8 tools/test_strata_mcp.py` 41 tests `OK`, `python -X utf8 tests/terminal/test_issues_022.py` 31 tests `OK`.
- Ordering check, to show what the new order changes on a machine that did *not* report the symptom: ten realistic path and secret samples through the pre-fix redactor and the fixed one, with the machine identity pinned identically for both. `/home/dgbox/Strata` 6/10 unchanged, `/home/matthias/Strata` 6/10 unchanged, `C:\Users\matthias\Strata` 8/10 unchanged. Every changed sample is a `<home>` or `<strata>` placeholder appearing where the text used to keep `/home/<user>/Strata/…` or `C:\Users\<user>\…`. Nothing else moved.

**Failed:**

- One failure, produced on purpose, as the regression proof: the new test run against the base file (`git show HEAD:tools/strata_bench.py` over `tools/strata_bench.py`, `redactor()` unchanged) -> `Ran 1 test` / `FAILED (failures=1)` with

  `AssertionError: 'loading /home/<user>/Strata/strata-x.json' != 'loading <strata>/strata-x.json'`

  — the message from #3326. Restoring the fixed file gives `OK` again, for that test and for the whole file. No other check failed, before or after.

**Not run:**

- No Linux and no macOS run, so the command from #3326 was never run on a machine that actually has the condition. The Linux layouts above are simulated inside the test by patching `ROOT`, `Path.home`, `getpass.getuser`, `socket.gethostname`, `platform.node` and `tempfile.gettempdir` — they are not executed on Linux, and the reporter's Ubuntu 26.04.1 / Python 3.14.4 machine is not available here.
- No real benchmark against a running Strata server and no engine build: `tools/test_strata_bench.py` answers from a fake HTTP server, and no GPU, model or download is involved.
- CI coverage: `.github/workflows` runs the node scripts, the title-area check and intake only — nothing there runs these Python tools tests.

## Limits

- On a machine that had the bug, a report now reads `<strata>` and `<home>` where it used to read `/home/<user>/Strata/…`. That is the point of the change, but it does change how new reports look on such machines; the measured counts are in Validation.
- The rule is "longest text first". A container is always longer than what it holds, so no pair that matters can come out the other way; two entries of the same length keep their insertion order, and folders are added before names.
- Ordering only. The set of values, the placeholder names and the fallback rules are as before.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

関連リンク

インストール・モデル・リリースへのサイト内リンク。