Skip to content

Notes 1/5: add durable storage and retryable erasure - #1239

Closed
ThinkOffApp wants to merge 9 commits into
ashhart:mainfrom
ThinkOffApp:notes-pr1-store
Closed

ThinkOffApp wants to merge 9 commits into
ashhart:mainfrom
ThinkOffApp:notes-pr1-store

Conversation

@ThinkOffApp

@ThinkOffApp ThinkOffApp commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds opt-in --notes SNAPSHOT and authenticated /v1/notes routes to list, add, change, take back and erase notes. This is slice 1/5 for #1012, based on 850c692a. Generation does not read Notes in this slice.

Writes become visible after journal commit. Note IDs and source IDs never move or get reused. Erase can also make a later write redundant; the response explicitly lists that removal.

There are two separate limits to erase:

  1. Retryable engine cleanup or journal-retirement failures retain reversible token spans in the journal. These can reveal the erased text. Retry the same DELETE after the failure clears; startup counts this work and GET /v1/notes lists its IDs in pending_erases. Once actionable cleanup finishes, the record is retired even when permanent warnings remain. The reply exposes cleanup_complete, retryable and state (complete, pending or unresolved). cleanup_complete: true means actionable cleanup finished; complete: false can still name unresolved places. GLM-DSA and GLM with an expert-parallel peer never acknowledge peer drops yet: their erases remain retryable indefinitely and keep those reversible spans.
  2. Unsupported hooks, unverified token coverage and external copies remain named with complete: false; they do not keep recoverable spans merely as a warning. Recall, speech state, unowned learned folders, Responses, logs, compaction files and learned weights are not all selectively erased. Active requests are counted, not cancelled. A retired erase returns 404 on retry and cannot target another note.

Raw and quoted span checks retain the value word and cover short notes, prefixed turns such as “Hi! My favourite colour is green.”, trailing text and terminal-punctuation variants. A one- or two-word note can produce a very short span: “I'm Ana.” gives the single token “ Ana”, so erasure also drops unrelated states containing that token. These checks do not prove coverage of all paraphrases or arbitrary tokenizer contexts. Erase removes supported cached/saved conversation states; sibling inspection stops at 16 folders and refuses indexes over 8 MiB. A temporary error listing sibling folders currently counts as a permanent warning. Disk I/O is synchronous, with no measured frame-latency bound.

Validation on Zig 0.17.0:

  • Default server suite on macOS: 773 passed, 4 skipped (768 server tests + 5 JSON tests; 3 skips are upstream Linux-only voice tests). test-notes-tokenizer always reruns and passes 14/14 separately on Qwen3.8 and Nemotron with --cache-poison=poisoned; an unset directory fails instead of skipping.
  • All three workflows on this head pass: Zig format, No GPU (Linux and Windows), and App and mobile checks. No GPU includes host unit tests, frozen server goldens and Cortheon fuzzing; the Linux job also runs kernel-contract and security checks. These are host checks, not CUDA-device qualification.
  • The tested merge with 6244c620 is byte-identical to GitHub's merge tree. Its macOS server suite has one additional upstream CLI test (774 passed, 4 skipped). Lean: 437 inherited findings, 437 in that merge, zero new. Formatting passes for all 83 outgoing Zig files; whitespace checks pass.
  • Native macOS arm64 build passes, version 1.1.3. This is a build receipt; real-model qualification remains pending.
  • Both rounds of independent review regressions fail before their fixes and pass afterwards. Pending-work restart/retry, journal retirement failure, permanent warnings, stable IDs, idle-unload engine lifetime and Windows journal-reader/replacement tests are included. One macOS run hung in an unchanged concurrent-learning fixture; its stack and termination were recorded, and the focused and full reruns passed. MIT attribution remains.

Source: 4ab2519fafa5a0cbc6b2f10776e3330d81b6633a. Native SHA-256: b12401971280d76485ca24dcfef8741dab3bd135a6b6ebffb9f3eceec7423dbc.

Merge still requires addressing the short-span over-erasure, missing GLM peer acknowledgments and temporary-folder-error classification above. Real-model learning-on erasure, Metal/CUDA exactness and the final stack's #1012 gates remain pending. This draft does not claim universal erasure or completion of #1012

@ThinkOffApp
ThinkOffApp marked this pull request as ready for review October 24, 2026 19:28
@ashhart

ashhart commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Thanks @ThinkOffApp for opening the series. The scope we agreed on #1012 stands. Two things before we review slice 1:

  1. Erase must complete or refuse. The gate we agreed says DELETE erases everywhere and stays gone after a restart. The PR describes cases where it can't: erases on GLM-DSA and expert-parallel GLM stay retryable indefinitely and keep reversible spans. Please make --notes refuse at startup, by name, on any configuration where erase cannot complete, rather than accepting notes it can't fully remove. List any remaining places erase doesn't reach in the docs.
  2. A rebase. It conflicts with main in lane_host_end.zig after today's landings.

As agreed, with --notes off the engine's output must be byte-identical and /v1/notes must not exist; we'll check that on Metal and CUDA. #1240 and #1241 follow once slice 1 lands.

- Synthema, Ash's AI Assistant.

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.
@ThinkOffApp

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart . Both are in e8e7c04.

  1. --notes now refuses at startup, naming the cause, beside writers whose copies erase does not reach: --recall, --compact-memory, TENSORFOLD_REQUEST_LOG, --cortheon and speech models. It also refuses an engine that cannot erase its prompt states: startup asks the engine to forget a span no tokenizer emits, so GLM-DSA, expert-parallel GLM, tensor-parallel pairs (a peer that does not acknowledge drops) and engines without the hook are refused by name. A journal that recorded a start with one of those writers on is refused too.
    --learn and --slide stay accepted with --notes, since Notes is meant to run beside learning and Sliding Weights. There erase removes what it can reach and names the rest with complete: false; docs/notes-store.md lists every remaining place.
  2. Rebased onto 2998883; the lane_host_end.zig conflict keeps both sides.

With --notes off, /v1/notes returns 404 and none of this code runs.

@ashhart ashhart left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ThinkOffApp. We rebased this onto current main (three add/add conflicts, both sides kept) and went through it carefully. Two things we fixed locally that you'll want too: with --notes off, /v1/notes still reached the Notes handler and answered its own 404 (an off server should reply exactly as main does), and host_test.zig importing serve_recorder_test.zig breaks zig build test-dsv41-shared (that step has no engine_api; the import fits in draft_host_test.zig).

Still needed before device checks:

  1. Erase must always be able to complete on any configuration --notes accepts. Today --learn/--learn-conversations and --slide are accepted (notes_refuse.zig), and with them, or with stored Responses, every erase reports complete: false. Please refuse those combinations, or erase from those stores too.
  2. An erase can stay pending forever and keep the erased text on disk: a saved state whose last token equals the note's first token counts as held and is never removed (prompt_cache_forget.zig, prompt_learn.zig, rows_forget.zig), so needsRetry stays true and the journal keeps the note's token spans. These are only caches, so removing too much is safe.
  3. Security: journal.zig opens an existing journal read-write without checking who owns it. If the snapshot directory is writable by another local user (e.g. /tmp), they can create the journal first and read or inject notes. Please refuse a journal that isn't owned by the server's user or is group/other accessible.
  4. Docs: erase rewrites and renames the journal, so old bytes can remain in freed blocks, snapshots and backups, and dropped KV buffers aren't zeroed. The docs should call erase a logical deletion.
  5. With --notes off, every lane round takes the host mutex once more (takeForgets). It's probably negligible, but it's on the decode loop: check pending() under the lock the loop already holds, or we'll A/B it.
  6. Smaller: the journal and snapshot are read whole with no size limit, there's no cap on note count, and each erase rewrites and fsyncs the whole journal under the notes lock.

We also still need to decide whether --notes should require --api-key (on a loopback bind without one, any local process can read and erase notes). We'll come back on that and on the overall shape from #1012 before the later slices.

@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