Skip to content

cortheon: own words find each closer in one pass, so unclosed tags no longer rescan the message - #1898

Merged
ashhart merged 3 commits into
ashhart:mainfrom
jishnuvenugopal:fix/cortheon-own-words-closers
Nov 2, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
jishnuvenugopal:fix/cortheon-own-words-closers

Conversation

@jishnuvenugopal

Copy link
Copy Markdown
Contributor

Thank you, @ashhart, for ownWords itself, which keeps the context a harness wraps in <tag> blocks out of Cortheon's research decision, and for
the fuzz harness and linear_time.fastest (#1482): that gate measured the fix below and now holds it, as it holds html.toText and hrefs.

What this changes

program.ownWords (zig/src/server/cortheon/program.zig) paired each <name> or <name opener with its closer by searching the rest of the
message for </name>, so every opener that never closes searched to the end, once per opener. closersOf now reads every </name> once, into
each name's start positions in order, and an opener takes the first one at or after its name, the one indexOfPos found; openers only move
forward, 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.zig keeps the old search as ownWordsByRescan and requires the same bytes from both on every seed and edit, adds
ownWords to the readers timed by "every reader takes linear time on long inputs", and adds two seeds (a harness's context blocks; names either
side of 61 bytes).

Verified outcome

  • Why: with --cortheon, every user message of every chat request goes through this before the model sees it. A message of many unclosed
    tags slowed with the square of its length: <a repeated to 256 KiB took 41.5 s, and each doubling took four times as long, while a request
    may carry 32 MiB.
  • What was done: the closing tags are found in one read of the message, instead of one search to the end of the message per opening tag.
  • Result: that message now takes 2 ms, and a 32 MiB one 0.1 s, and every message reads exactly as before: the old and new code give the same bytes on
    the fuzz harness's seeds and 100,000 edits, and the harness fails if they ever differ.

Receipt

  • Environment: main at 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, ownWords alone, ReleaseSafe as the server is built, the thread's CPU clock:

    Message main this branch
    <a x 32 KiB 618 ms 0.36 ms
    <a x 64 KiB 2,466 ms 0.72 ms
    <a x 128 KiB 10,065 ms 1.3 ms
    <a x 256 KiB 41,550 ms 2.2 ms
    <a1 <a2 <a3 <a4 x 256 KiB 11,465 ms 0.80 ms
    <a x 32 MiB not run (about a week at 4x per doubling) 102 ms
  • Fails before: on main's ownWords, zig build fuzz-cortheon fails "every reader takes linear time on long inputs" with "ownWords took 1101 ms
    on 128 KiB and 70504 ms on 1024 KiB" (64x for 8x the bytes); the new program.zig test "a message of unclosed tags reads its own words in
    linear time" did not finish in 10 minutes. The new behaviour test passes on main too: it pins what ownWords already 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-cortheon fails "own words" and prints the input.

  • Tests: zig build fuzz-cortheon 19 pass, 0 fail (main: 19 pass). zig build test: 7932 of 7972 pass, 38 skip, 2 fail; on main 7928 of
    7968, 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 main too. 57 steps cannot run without Xcode (xcrun metal), the
    same on main; zig fmt --check build.zig zig and git diff --check origin/main clean; 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 --cortheon request (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.fastest to return ns and work. The new test in program.zig reads ns[0] and ns[1], so whichever
    lands 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

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (No engine change.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (n/a: no engine change.)
  • No precision traded for speed. (n/a: no arithmetic.)
  • A new or changed GPU kernel is registered with the kernel contract. (n/a: no kernel.)
  • Prompt processing is no slower than the last release. (n/a: runs before the engine.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (Host code, run on M1 Pro.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@ashhart

ashhart commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thanks @jishnuvenugopal, reviewed: this lands now. It's gated and queued, and we've written the changelog line.

@ashhart
ashhart force-pushed the fix/cortheon-own-words-closers branch from 40fb7dc to 4472b6f Compare November 2, 2026 21:50
@ashhart
ashhart merged commit 6c74670 into ashhart:main Nov 2, 2026
0 of 7 checks passed
@ashhart

ashhart commented Nov 2, 2026

Copy link
Copy Markdown
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.

ashhart added a commit that referenced this pull request Nov 2, 2026
…t's fields

#1854 made linear_time.fastest return Fastest{ns, work}; #1898's new test in
program.zig, landed after it, still indexed the old [2]u64, so main's test build
failed to compile (8e35d52). Same change #1854 made in html.zig: the time bound
on ns, the 8x growth bound on work.
@jishnuvenugopal
jishnuvenugopal deleted the fix/cortheon-own-words-closers branch November 3, 2026 07:03
@ashhart

ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants