Skip to content

Notes 3/5: look up a chat request's notes, who first - #1241

Closed
ThinkOffApp wants to merge 26 commits into
ashhart:mainfrom
ThinkOffApp:notes-pr3-lookup
Closed

ThinkOffApp wants to merge 26 commits into
ashhart:mainfrom
ThinkOffApp:notes-pr3-lookup

Conversation

@ThinkOffApp

@ThinkOffApp ThinkOffApp commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

This adds the note lookup on top of the store (1/5) and the index (2/5). It sits on top of Notes 2/5 (1c47f39d), so until 1/5 and 2/5 merge this diff also shows their commits; this slice's own changes are the last 10 commits. The first of them is two small help fixes for 2/5: the --notes-index help says the index is rebuilt on every write and erase, and the Notes help rows print only on -h.

What it adds:

  • A chat completion that sends "notes": true (or notes_exclude) has its last user message looked up. The notes found go into one block, put first as a system message, cut to the cap by the served tokenizer. The reply's notes field and the log name the ids, tokens and times.
  • Who first is the default. The block holds the notes of the subjects the question names (entity phrases, the user, names from current name notes) and of the entities those notes name. A question that names nobody known gets no block.
  • "notes_lookup": "plain" or --notes-lookup plain keeps the reference retrieve(). German and Finnish questions use it too (notes_language, --notes-language). Both flags live in notes_flags.zig with the other Notes flags, so this slice adds no lines to cli.zig.
  • Request fields: notes_exclude, notes_past, notes_cap, notes_echo, notes_language, notes_lookup.
  • The lookup reads the current index under the store's lock. An erase drops the lookup's kept memory.
  • zig build notes-golden compares the lookup with the Python reference question by question: 1344/1344 equal on the L6 and five nightly stores, plain and who first, with either index.

Tests (Zig 0.17.0): test-server-cpu on macOS 823 passed, 4 skipped (818 server tests plus 5 json tests; the skips are 3 upstream platform tests and 1 real-tokenizer test that needs TF_NOTES_TOKENIZER_DIR). GitHub CI on this head passes on Linux and Windows. Lean: 437 inherited, zero new, also when merged with current main. Formatting and whitespace checks pass. The test socket helpers use the platform layer, so the Windows test binary builds.

Limits:

  • "Send nothing when nobody known is named" applies only to notes stored under a named subject. Notes written as free text without a subject are filed under the user and can still reach the block.
  • The name reader still misses forms like "was called X until DATE; now he is called Y".
  • Who first is English only.
  • No live fetch, chat write or promotion. Those are later slices.
  • lang_tables.zig is generated and is exempted from the line limit in lean_check.py

@ThinkOffApp
ThinkOffApp marked this pull request as ready for review October 24, 2026 19:29
Open the journal fixture for directory iteration on Linux. Use the platform libc and socket surfaces on Windows, preserve temporary-file identity with volume and file index, and refuse reparse points for no-follow opens. Keep POSIX fork and privileged symlink tests separate from the portable hardlink ownership regression.

Refresh tokenizer example build configuration so the selected tokenizer directory is observed.
Keep the stable sidecar writer lock on Windows without mandatory locks on journal data. Replace an open destination through FileRenameInfoEx when MoveFileEx cannot, preserving old readers. Cover replacement with an open reader and refusal of another writer at the rename seam.

Move Notes flag parsing into notes_flags so the merge with current main remains within the CLI line limit.
Startup refuses --notes, naming the cause, with --recall, --compact-memory,
TENSORFOLD_REQUEST_LOG, --cortheon or a speech model; on an engine that cannot
erase its prompt states (no hook, or a peer that does not acknowledge drops,
found by forgetting a span no tokenizer emits); and on a journal that recorded
a start with one of those writers on. --learn and --slide stay accepted: each
erase names their places with complete: false. The docs list every place erase
does not yet fully reach.
A request log, an engine without prompt-state erase and a peer that does not
acknowledge drops each exit 2 without appending a run to the journal; an
accepted start serves /v1/notes, takes a write and appends its run, so the
journal-size check can fail.
Each refused start runs on its own thread with a 20 s deadline; a start that
listens instead is stopped with SIGTERM and fails as NotRefused, so a lost
refusal is a red test, not a CI timeout.
cli.zig keeps one notes field. This slice adds path and index; later slices add language and lookup in the same struct. Flag table rows and help come from notes_flags so cli.zig does not grow.
overlay.zig has no caller at the pin; past.zig belongs with lookup.
Add NOTES-CODE-COMMENTS.md so the remaining section pointers resolve.
Storage still rebuilds the whole index on every write and erase.
The journal errdefer only covered replay. Index build and alias
populate sit after that block, so an unsupported suffix-array
vocabulary leaked the open journal. The cleanup now covers them,
and a test loads that case with a journal path.
A response reader waiting for EOF could leave the host suite blocked in join after dispatch. Bound its full read, retry interrupted write shutdown, and report timeout or shutdown failure. A peer-withheld EOF control fails without the deadline and completes with it.
…s help shows only on -h

The --notes-index help row now says the index is rebuilt whole on every write and erase, as notes/storage.zig does. It no longer names the side buffer, which the served store never fills.

The Notes help rows print for -h and --help only. A usage error prints the usage line and the error, as before PR2.
These files come from 861d6c99 unchanged: notes/lookup.zig, notes/past.zig,
notes/lang.zig, notes/lang_tables.zig, the fixtures l6_bytes_cases.json,
lang_cases.json and tb_empty_bytes_snapshot.json, and the Python tools that
write them (tools/notes/fixture.py, live_intake.py, lang_cues.py,
lang_tables.py, lang_cases.py, past_cases.py and ml_overlay.py, which
fixture.py imports for its --lang fixtures).

Two changes keep the lean rule. A two-line comment in lang.zig is now one
line. lang_tables.zig is generated by tools/notes/lang_tables.py, so
lean_check.py lists it with the other generated outputs.

Nothing calls the lookup yet. Its own tests and those of past.zig and
lang.zig run with the server tests.
A chat completion request that sends "notes": true, or a notes_exclude
list, now has its last user message looked up in the store. The notes
found go into one block, which is put first as a system message, as if
the client had sent it. The block is cut to the cap by the served
tokenizer. The reply's "notes" field and the server log name the ids,
tokens and times. The fields notes_past, notes_cap, notes_echo and
notes_language work as at the pin, and --notes-language sets the default
language.

The lookup is the pin's (notes/lookup.zig). notes/retrieve.zig runs it on
the store's current index under the store's lock, as the pin's
Store.retrieveWith did, with one kept scratch in the store. An erase drops
that scratch, which may hold the erased note's text. notes_route.zig is
the pin's request handling without the chat write and the live fetch.

json.quote and json.stringify now free what they took when a write fails,
as at the pin. The lookup's allocation failure tests found the leak.

notes-golden (zig/tests/notes_golden_bench.zig, from the pin) compares the
lookup with LLWZ Python's answers, question by question. On the exported
L6 and five nightly stores, bare and with 1000 distractors, it gives
1344 of 1344 equal answers with either index.

--notes-language, its field and its help row are in notes_flags.zig, so
cli.zig does not grow. The test's socket pair, reads, writes and poll go
through the platform layer, as PR1's HTTP fixtures do, so it builds on
Windows.
lookup() now runs scored() for the scores and the pool, then pack() over
the order keys. The result is the same as before. The who-first lookup
reuses both parts.
A chat request's first block now holds the notes of the subjects the
question names and the notes of the entities those notes name. The
subjects are the store's entity phrases, the user, and the entities a
current name note calls by a word of the question. A name that several
entities hold names the user's circle, or else all of them with a lower
weight. An excluded note is never shown, and the link it states is never
followed. The candidates are ranked by retrieve()'s scores and packed as
before. When the question names nobody the store knows, the block is
empty.

The user is named by I, me, mine or myself, but not by the me of tell
me, give me or show me. "my X" names the user when X is a word of one of
the user's current notes or a part of a stored attribute's name, and no
word of any entity's name. The check of X reads only the store, with no
list of attribute words.

The request field notes_lookup, "who" or "plain", picks the lookup, and
the store's default is who. German and Finnish questions keep the plain
lookup. A request without notes does not read the field.

A lookup test that compares the notes before a write and after its erase
asks for the plain lookup.
tools/notes/who_ref.py is the rule in Python on LLWZ's NoteStore.
tools/notes/who_fixture.py writes a made-up store under the byte
tokenizer, with Python's answer for each of its cases and for each case
of the L6 fixture. The new tests check the chat path and compare every
case with Python on both indexes.

notes_lookup_rig_test.zig is the tests' server: the store with its
journal in a temporary folder, as the pin's rig, on this branch's store.
The bench now prints each request whose answer differs, so a difference
can be read case by case.

The first line of the bench names its flags as [flags], to keep the lean rule.
…eads the store once

The user's notes that /v1/notes wrote without a subject
have the attribute note:SOURCE. They do not say whom they are about. Those
the plain lookup ranks are now always candidates, so a question about such a
note no longer gets an empty block.

A name is now a run of Latin, Greek or Cyrillic letters, with a hyphen
between two letters, or up to four such runs one space apart. Each run is
encoded in a scratch arena that is reset before the next run. A long
question no longer grows the request arena.

"my X" reads the entity names, the attribute names and the user's notes
once per question, whatever the number of X. The Python reference reads I,
me, mine, myself and my as ASCII, as the Zig code does.

The made-up store has new notes. Each part of the rule now decides at least
one of its cases. A new fixture writes four notes over /v1/notes and
compares the answers after them with Python.

The live fetch and the chat write belong to later slices, so the test of
the live fetch after an empty block is left out here, and the test of
notes the server wrote writes its chat statement over /v1/notes.
--notes-lookup plain gives a server the earlier lookup for every chat
request that sends no notes_lookup. The default stays who. The startup
line names the lookup.

docs/notes-store.md says how to keep the earlier lookup. German and
Finnish keep it only when the request or the server declares them.

The source commit also had tools/notes/run.py and tools/notes/live.py ask
for the plain lookup. Those tools come with later slices.

The flag, its field and its help row are in notes_flags.zig, so cli.zig
does not grow.
On the hold-out store L6-seed2 the dog's name note says the dog has a
new name and then, in a second clause, "it is called Otto now." The name
table read a name only right after the note's subject, so "What is the
colour of Otto's eyes?" named nobody and got an empty block. Python's V1
reads the stored value instead.

The snapshot (LLWZ's notes_export.py) carries no literal value per note,
and a written change of a name note has none either, so the name is
still read from the text. A naming phrase alias.zig already knows may
now also open a later clause of the note (after a full stop, comma,
colon or semicolon and a space) when one word stands before it for the
subject. No new phrase is added. tools/notes/who_ref.py reads names the
same way.

Tests: a made-up store note "Noor's goat got renamed, it is called Pim
now." with "What does Pim eat?", unit cases for the clause rule, and the
L6-seed2 teach store as a new differential against Python (224
requests). Against the code before this change the made-up case and both
differentials fail.
@ashhart

ashhart commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Closing with the rest of the Notes series; the reasons are on #1254. Thank you.

@ashhart ashhart closed this Oct 26, 2026
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