fix(tools): k3_tokenizer --ctest writes its fixture to a hardcoded /tmp path - #1229
Merged
JustVugg merged 2 commits intoAug 28, 2026
Merged
Conversation
…/tmp k3_tokenizer.py --ctest wrote its case fixture to a hardcoded "/tmp/k3_tok_cases.bin". That is the same pattern the repo has already moved away from twice: tests/test_stops.c and tests/test_pipe_block.c both carry the rule in the source, that a path must not be rooted at /tmp because the windows job builds native .exe files and that is not a Windows path, and that the whole `make check` goes red on the windows job and only there. setup.sh was moved off its own /tmp probe to OMP_PROBE=".colibri-omp-probe-$$", and test_cuda_test_makefile.test_setup_openmp_probe_does_not_require_tmp pins it there. The failure is conditional rather than universal, and worth stating precisely: fopen(..., "w") creates the file but not the directory, so on a box where something has already created C:/tmp (Git Bash does) the old line writes fine, and on a clean runner it does not. Measured both ways rather than assumed. The fixed FILENAME is a second and platform-independent bug: two concurrent runs of --ctest collide on it, and nothing ever removed it. Now tempfile.mkstemp next to the output file, in a try/finally so a failing ctest still cleans up. That directory is provably writable because the tokenizer.json was written to it successfully a few lines earlier, so this cannot trade one unwritable location for another. Not touched, but the same family and flagged for a maintainer decision: kimi_k3.c:1045 defaults K3_VALIDATE_OUT to "/tmp/k3_val". That one degrades cleanly, printing "[K3-VAL] cannot open ... disabled" and carrying on, so it is a lower-severity instance and changing a documented env-var default is not mine to make unasked. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…test Same shape as test_cuda_test_makefile.test_setup_openmp_probe_does_not_require_tmp, which pins setup.sh off its old /tmp probe. Without a pin the line comes back the next time someone needs a scratch file, since the failure is invisible on any dev box that happens to have /tmp. Three assertions: no quoted /tmp path anywhere in the file, the fixture is created via tempfile.mkstemp, and os.unlink sits inside the finally rather than on the happy path. The source is read as text rather than executed because --ctest needs tiktoken and a compiled test_tok_kimi, neither of which the python job has. Negative control run rather than assumed: reverting tools/k3_tokenizer.py alone fails all three, restoring it passes all three. Full suite is 591 tests with the same 2 pre-existing errors before and after, both of them test_cuda_test_makefile shelling out to a make that is absent on this host. Co-Authored-By: Claude Opus 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.
k3_tokenizer.py --ctestwrites its case fixture to a hardcoded path:This is the same pattern the repo has already moved away from twice, and I only found it because the existing pins pointed at it.
The rule is already written in this repo, twice
tests/test_stops.c:84andtests/test_pipe_block.c:146:And
setup.shwas moved off its own/tmpprobe toOMP_PROBE=".colibri-omp-probe-$$", withtest_cuda_test_makefile.test_setup_openmp_probe_does_not_require_tmppinning it there.tools/k3_tokenizer.pyis the file that pass missed.One correction to the obvious framing, because I checked
I expected this to fail outright on Windows and it did not.
fopen(..., "w")creates the file but not the directory, and Git Bash createsC:/tmpon install, so on my box the old line writes fine. The failure is conditional on whether/tmpalready exists, which is exactly why it survived this long: it works on most dev machines and breaks on clean ones. I measured it both ways rather than assuming, since assuming is what would have made this a bogus report.The fixed filename is the platform-independent half, and it is unconditional: two concurrent
--ctestruns collide on the same path, and nothing ever removed the file.The change
tempfile.mkstempnext to the output file, in atry/finally:The output directory rather than the system temp dir on purpose: it is provably writable, because
tokenizer.jsonwas written to it successfully a few lines earlier. So this cannot trade one unwritable location for another.Verification
Three tests in
tests/test_k3_tokenizer_tmp.py, same shape as the existingsetup.shpin: no quoted/tmppath in the file, the fixture goes throughmkstemp, andos.unlinksits inside thefinallyrather than on the happy path.Negative control run rather than assumed - reverting
tools/k3_tokenizer.pyalone fails all three, restoring it passes all three:Full python suite, before and after:
Both errors are pre-existing and unrelated:
test_cuda_test_makefileshells out tomake, which is absent on this host.The
--ctestpath itself is not exercised here, and I want to be straight about that - it needstiktokenplus a compiledtest_tok_kimi, so the tests read the source as text the way thesetup.shpin does. The edit is small enough to read, but CI is the check that matters for the runtime path.Tested on Windows, RTX 3090 (sm_86), CUDA 13.1, Python 3.11.