Repository navigation
cortheon: own words find each closer in one pass, so unclosed tags no longer rescan the message - #1898
Merged
ashhart merged 3 commits intoNov 2, 2026
Conversation
Owner
|
Thanks @jishnuvenugopal, reviewed: this lands now. It's gated and queued, and we've written the changelog line. |
… longer rescan the message
…, and read long ones in linear time
ashhart
force-pushed
the
fix/cortheon-own-words-closers
branch
from
November 2, 2026 21:50
40fb7dc to
4472b6f
Compare
Owner
|
Thank you @jishnuvenugopal. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Owner
|
Thanks @jishnuvenugopal! This is in TensorFold 1.2.2, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.2 |
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.
Thank you, @ashhart, for
ownWordsitself, which keeps the context a harness wraps in<tag>blocks out of Cortheon's research decision, and forthe fuzz harness and
linear_time.fastest(#1482): that gate measured the fix below and now holds it, as it holdshtml.toTextandhrefs.What this changes
program.ownWords(zig/src/server/cortheon/program.zig) paired each<name>or<nameopener with its closer by searching the rest of themessage for
</name>, so every opener that never closes searched to the end, once per opener.closersOfnow reads every</name>once, intoeach name's start positions in order, and an opener takes the first one at or after its name, the one
indexOfPosfound; openers only moveforward, so each name's positions are passed once, also when every opener has a different name. Names over 61 bytes still never match, and the
output is unchanged.
fuzz.zigkeeps the old search asownWordsByRescanand requires the same bytes from both on every seed and edit, addsownWordsto the readers timed by "every reader takes linear time on long inputs", and adds two seeds (a harness's context blocks; names eitherside of 61 bytes).
Verified outcome
--cortheon, every user message of every chat request goes through this before the model sees it. A message of many unclosedtags slowed with the square of its length:
<arepeated to 256 KiB took 41.5 s, and each doubling took four times as long, while a requestmay carry 32 MiB.
the fuzz harness's seeds and 100,000 edits, and the harness fails if they ever differ.
Receipt
Environment:
mainat 4fbfb5a, Zig 0.17.0, Apple M1 Pro, macOS 26.6. Host code: no model or GPU.Exactness: n/a. No engine change; Cortheon's program, prompt and tokens are the same.
Decode speed: n/a, this runs before the request reaches the engine.
Prompt speed: n/a, same reason.
Timing,
ownWordsalone, ReleaseSafe as the server is built, the thread's CPU clock:<ax 32 KiB<ax 64 KiB<ax 128 KiB<ax 256 KiB<a1 <a2 <a3 <a4x 256 KiB<ax 32 MiBFails before: on
main'sownWords,zig build fuzz-cortheonfails "every reader takes linear time on long inputs" with "ownWords took 1101 mson 128 KiB and 70504 ms on 1024 KiB" (64x for 8x the bytes); the new
program.zigtest "a message of unclosed tags reads its own words inlinear time" did not finish in 10 minutes. The new behaviour test passes on
maintoo: it pins whatownWordsalready did.The equivalence check fails on purpose: with the skip past a closer off by one byte, and with the 61-byte name limit removed,
zig build fuzz-cortheonfails "own words" and prints the input.Tests:
zig build fuzz-cortheon19 pass, 0 fail (main: 19 pass).zig build test: 7932 of 7972 pass, 38 skip, 2 fail; onmain7928 of7968, 38 skip, the same 2 fail: the four new tests are this branch's two, run from both server test roots. The 2 failures are request_log's
"a log others can read" test, which assumes umask 022 (this Mac's is 077), on
maintoo. 57 steps cannot run without Xcode (xcrun metal), thesame on
main;zig fmt --check build.zig zigandgit diff --check origin/mainclean; lean 0 new (424 on the base, 424 here).zig build test-golden: 55/55 equal to the goldens.zig build test-kernel-contract: 157/157 pass.Not run: a served
--cortheonrequest (needs a model); the Metal kernel builds, which need Xcode on this Mac; CUDA (host code only).Overlap: Tests: the server's linear-time checks compare the thread's cycles on Windows #1854 changes
linear_time.fastestto returnnsandwork. The new test inprogram.zigreadsns[0]andns[1], so whicheverlands second needs the same one-line change Tests: the server's linear-time checks compare the thread's cycles on Windows #1854 makes in
html.zig.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a: no engine change.)