A new "draft" permission lets a plugin read what's being typed in the message box (zeron.draft) and take the whole draft out and put it back later (take_draft, put_draft, swap_draft, drop_draft). Zeron keeps a taken draft itself, so a plugin never sees file paths. This is what a prompt stash needs: write in the wrong chat, set it aside, restore it in the right one.
- A key's name is judged on its own: anything that looks like a key is
refused whatever key it's for, so Rename can't be used to test guesses
- Previews can't add a key, rename an account or forget a GitHub login;
a test checks every action the code refuses is blocked
- A Pi switch over a Claude login it can't identify is refused, and the
live entry is compared before it's written
- Hermes key add: the child dies with the request; the name goes as --label
- Switching from the composer reloads the agent's models
- changed_logins dedups through a sorted set
- Hermes model names: plain files up to 64 MB, naming waits at most 5 s;
Hermes .env read is bounded
- The API key dialog's Cancel waits while a key is checked
- stores.rs module docs match what each store does
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Anthropic's profile endpoint answered a real sign-in with nothing usable
(the engine was being rate limited on Claude's usage endpoint at the same
moment), so Pi's Claude sign-in failed with 'Could not identify the
signed-in Claude account' after the token exchange had succeeded. The
token response names the account (account.uuid, account.email_address,
organization.name), as Claude Code's own sign-in already falls back to;
Pi's now does too, keyed as the profile path keys it. A refused or failed
profile lookup logs its status, never the body or the token.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A key row says its last four exactly once: named, "Work" over
"OpenRouter · API key"; unnamed, "API key ···a1b2" over "OpenRouter".
The name, when set, is kept apart (display_name); the title is derived
otherwise. Rename opens empty for an unnamed key and says which key.
- Hermes keys read the same; one seeded from an environment variable is
never titled by it ("API key ···a1b2" over "OpenRouter · from
environment"), and Hermes' own "api-key-N" labels count as unnamed.
- A key row's face is its provider's mark in the add rows' round well;
logins keep their avatars. The add dialog's name field: "Name
(optional)".
- Test servers ignore the `HEAD /` probes a preview scan in the test
process sends to every local listener: the cause of the occasional
extra hit in the GHES, spent-Claude and Pi key tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per-provider agents (Pi, OpenCode, Hermes) now look and act like every
other agent's card, take API keys in the app, and behave across devices.
Card: the same rows, rules and "In use" as Claude Code's and Codex's — a
provider's accounts together, each provider with its own one in use, the
plan line saying whose ("ChatGPT Plus", "OpenRouter · API key ···a1b2") —
and every add row at the foot (Add ChatGPT / Claude / GitHub Copilot
account, Add API key). No section chrome, no CLI hints. "Switch to this
account" only on a switchable row not in use; a refused switch says why
in a toast instead of doing nothing.
API keys: "Add API key" opens a dialog (provider select with each
provider's mark, masked key field with its placeholder shape shown plain,
optional name, Save disabled until typed, spinner and locked inputs while
the provider checks the key, the provider's refusal under the field).
Stored as each agent's CLI stores it: Pi's auth.json api_key entry,
OpenCode 1.x's api entry (OpenCode 2.x keeps keys in its own database:
refused with what to do, and a warning on the list), Hermes through
`hermes auth add <provider> --type api-key` with the key on stdin in a
session without a terminal. Keys are named (default "<Provider>
···<last4>", renamable from the row's menu; a name holding any of the key
is refused). The key is never logged, never in an error or the snapshot,
never on argv or in a child's environment, files 0600, and
AddAgentApiKey is local IPC only (refused, never forwarded, when it names
another device; refused by the relay host if a peer sends one).
Claude for Pi: Pi's own Claude Pro/Max sign-in, saved as pi saves it, a
fresh grant, swapped under pi's lock; a switch keeps a refresh the agent
made since the last list (single-use refresh tokens). OpenCode has no
Claude sign-in (verified in 2.1.2): refused with the API-key alternative.
Hermes: lists only pool entries Hermes itself uses (its
_pool_entry_is_explicit: device_code, loopback_pkce, hermes_pkce,
manual[:*], env:<VAR> while the variable holds a key) — a borrowed
gh_cli Copilot token is no longer offered.
Also: provider marks (one mono set), Select options with marks, Dialog
confirm `disabled`, TextField draws a password's placeholder unmasked,
Groq/Mistral dropped from key providers (no marks in the set).
Tests: engine agent_accounts 118 (keys stored/refused/never shown or
logged/stdin-only/0600, OpenCode 2.x refusal, names and rename, two keys
one provider, Pi Claude local and for another device, rotation kept,
Hermes explicit-only); device_routing remote per-provider list/switch,
provider refusal routed, remote key refused with no relay frame and no
file holding it; rpc routing asserts; app Rust and UI tests updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hermes's ACP adapter labels each model with its id; the catalog it keeps
beside its config ($HERMES_HOME/models_dev_cache.json) names them as their
makers do. Read-only; a model it doesn't list keeps its id. Catalog cache
schema 3 so saved id-labelled lists are rediscovered.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A model row's name and provider read as one line: where it runs past
the row its right edge fades (as FadeText's), and while the row is
highlighted (pointer or keys) it glides left until its end shows,
rests and glides back. Reduce motion keeps it still; a row that fits
never moves. Test: `a line past its row fades at its right edge, and
glides to its end while highlighted`.
- The saved model catalog's schema is 2: models name their provider and a
Hermes `<Provider> · <model>` label is split. A catalog an older engine
saved has neither, so it is fetched again rather than served as it was
(Hermes showed "Anthropic · claude-fable-5.1" from its old cache).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agents that keep a login per model provider now show and switch them per
provider, everywhere:
- Settings → Providers (and setup's Your agents): such an agent's accounts
sit under a heading per provider ("ChatGPT", "Claude", "GitHub Copilot"),
each group with its own "In use" and its own "Add <provider> account"; a
provider with none yet is a "Connect <provider>" row at the card's foot,
and a sign-in shows in its own provider's row. A provider Zeron can't
sign in to (Pi's Claude) says how the agent adds one. Hermes' pool is
grouped the same way, read-only (no actions), adding through
`hermes auth add <provider>`. Single-login agents look as before.
- Model picker: the Account row is the chosen model's provider's
("ChatGPT account" / "Claude account"), listing and switching that
provider's accounts alone, so a ChatGPT switch never touches the Claude
login; a provider with none yet says None and offers "Add <provider>
account" (Settings → Providers, its sign-in started on the composer's
device); a provider with neither has no row.
- Engine: Pi gains GitHub Copilot sign-in (GitHub device code with pi's own
Copilot app, exchanged for a Copilot session at copilot_internal/v2/token,
unconfigured models enabled and availableModelIds recorded as pi's
/login does; an account without Copilot is refused, nothing written).
Hermes gains xAI (`hermes auth add xai-oauth`, device code). Hermes
marks each provider's first pool entry in use (a model of that provider
runs on it), the active provider's rows still first. Switching and new
sign-ins already rewrite one provider's entry alone; tests now pin it.
- Proto: login_options adds Pi github-copilot and Hermes xai-oauth;
groups_by_provider, login_option, account_group_label and
account_group_hint name the groups for every app.
All serde-additive: no field renamed, older apps read the same snapshot.
Tests: proto providers (3 new); engine agent_accounts (5 new: Pi Copilot
sign-in, no-Copilot refusal, per-provider switch isolation, Hermes xAI,
Copilot session/model parsing; Hermes in-use updated); app Rust (2 new:
grouping, device rows + logins); UI (provider_groups 6, model_accounts
_providers 5).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`tool_result_images_are_stored_inside_uploads` (#1103) looked for the
stored path in the journal's JSON text as it is; on Windows the path's
`\` is escaped there, so main's Windows tests failed. It looks for the
path as JSON writes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Now that zeron-engine's tests compile on Windows they run there, and two
failed for Windows reasons:
- device_stats' sysfs fixture names files 0000:01:00.0, which Windows
refuses: the test is Unix only.
- spaces' worktree test passed git a canonicalized \?\ verbatim path,
which `git worktree add` refuses: the prefix is dropped.
(cherry picked from commit 8fb608ad68)
Two hand-run measurements read CPU time with libc::getrusage, which Windows
doesn't have, so zeron-engine's lib tests didn't compile there and the
Windows tests job stopped at its build. The measure module
(source_control.rs) and live_like_bytes_and_cpu_before_and_after
(chat_persistence.rs) now compile on Unix only.
(cherry picked from commit 02ca4e0362)
`is_powershell` took the shell's name through std::path, which splits at
`\` only on Windows, so its test (`C:\Program Files\PowerShell\7\pwsh.exe`)
failed on the Linux and macOS runners and held 0.3.4's release back. The
name is now the last part at either slash, less its extension. Windows,
where it runs, reads the same as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The app starts the engine with CREATE_NEW_PROCESS_GROUP (crates/launch
`spawn_detached`), which makes it ignore Ctrl+C, and every process
inherits that from its creator: the shell the engine opens on a
pseudoconsole, and what it runs, ignored Ctrl+C too. PowerShell got the
key (char 3) but `ping -t` ran on. The engine puts normal handling back
before it creates a shell; a process started any other way has it
already, and the engine has no console for a Ctrl+C to come from.
The new test opens PowerShell from a process ignoring Ctrl+C, runs
`ping -t localhost`, sends Ctrl+C and waits for ping's summary. Like the
other ConPTY tests in windows_tests, it doesn't run on WING-PC (input
written to the shell never arrives there, with or without this change);
the fix was checked in the app: ping stopped, the tab went on.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Windows opens its terminals through terminals/windows.rs's own
CreateProcessW launch, not portable-pty's CommandBuilder, so -NoLogo given
there never reached PowerShell. It's on that command line now, after the
quoted executable.
(cherry picked from commit a3104d46e2)
A terminal tab on Windows ran %COMSPEC%, cmd.exe: a prompt with no space
after its `>` and nothing coloured as it's typed. It now runs PowerShell 7
(pwsh.exe on PATH), else the Windows PowerShell every Windows has, else
%COMSPEC% as before (cmd.exe when that's unset too). PowerShell starts
with -NoLogo: its prompt alone, no banner on every tab.
(cherry picked from commit 817182a5d6)
Clients read a tool part's `previewPaths` as pictures as they are (zgx
reads a local chat's straight from disk, #1186), so a path an adapter put
on a result (`/dev/zero`, a picture elsewhere on the Mac) must never reach
the doc. Results with image bytes carry only the copies stored in uploads;
paths without stored pictures are dropped, with a warning. No adapter sets
them today; this keeps it that way.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-ups for #1103:
- crates/ui is back to main (the desktop is apps/zgx now), but for the
`preview_paths: Vec::new()` its initializers need to compile. The engine
still names stored copies on the tool part; zgx reads them (#1186).
- A stored picture is named `tool-<chat>-<sha256 of its bytes>`: the same
picture again in a chat (another Read, another subagent) is one file
rather than a copy per call, and a chat's pictures share a prefix for
whatever clears a chat's away. Uploads keep them as before.
- Only the CLI's own image note is bookkeeping: one line, `[Image: source:
<path>]` or `[Image: original WxH, displayed at WxH…]`. A steer that just
starts with `[Image: ` and ends with `]` reaches the subagent.
- `is_meta` and `tool_use_result` also read as the live stream spells them.
- docs/image-preview.md says what the engine does and who reads it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main added ToolResult initializers (ReadToolOutput tests in tool_output.rs
and e2e, the mock harness's long-running commands, steer_now) after this
branch last merged it. They lacked preview_paths and image_payloads, so
zeron-engine's lib tests did not compile.
Since a steer started stopping an open tool call in place (76ca2e17b),
a `send_message` from another chat did too. Claude Code words every
interrupt as the person rejecting the call ("STOP what you are doing and
wait for the user to tell you how to proceed ... The instruction to stop
and wait still stands"), so a Claude agent took the other chat's message
as an order to stop and sat waiting. Codex and Muse add no such text,
which is why only Claude stopped.
A steer carrying Zeron's "from another chat" header (which only the
engine writes) now waits for the step boundary, as the `send_message`
tool promises: the command finishes and the message lands right after
it. The person's own Steer still stops the command at once.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pi signed in to both Codex and OpenCode lists GPT-5.5 twice, and the
picker gave no way to tell the rows apart.
Engine: Model gains `provider { id, name }` (serde-additive). Pi fills it
from its provider id with a name people say (openai-codex -> Codex,
opencode -> OpenCode, unknown ids in words); OpenCode from its provider
catalog. Single-source harnesses leave it None. zgx's catalog bridge
passes it to the picker.
Picker: a model with a provider carries its name as the row's hint
(Dropdown `hint`): quiet text in the name's size, on its line, the row's
gap after it; the name fades first when the row runs short. It shows
where it disambiguates (the agent lists the same name from another
provider), on every tab including Starred, and on rows a search found by
it ("codex", "gpt-5.5 codex"). Hints follow the catalog in place, and a
hinted row's accessible name reads what is drawn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
The RPC server ran each call on a task of its own, and tasks spawned back
to back start in no set order: tokio runs the newest first (its LIFO
slot). Two WriteTerminal calls in a row reached the PTY swapped. zgx's
terminal (Ghostty on macOS) answers a program's queries through the
bridge, each answer its own write: termenv (gh, glamour) asks for the
background (OSC 11), then the cursor (CSI 6n), took the cursor report
first as "no colour" and stopped reading, and gh's prompt read the colour
answer after it as typed keys ("unexpected escape sequence from
terminal: ['\x1b' ']']"), the cursor reports left in the shell (`;22R`).
Keys typed or pasted fast went out of order the same way, and a remote
viewer's numbered input lost the older of two (write_sequenced took it
for a replay).
A terminal's WriteTerminal and ResizeTerminal calls now run one after
another, in the order the connection sent them, on a lane of their own:
one per terminal, so a write that blocks (a paste into a program that
doesn't read) holds back no other terminal on the connection. A call's
answer is sent beside its lane, so a client slow to read answers doesn't
hold the next write back. When the connection ends, input already sent
still goes in; every other call is aborted as before.
tests/terminal_query_order.rs (unix; the probe is Perl): over the
engine's own dispatch, a program in the PTY asks as termenv does, 300
times, and a viewer answers as Ghostty does (two writes, at once).
Before: 284 of 300 read the cursor first (298 in an earlier run); after:
300 of 300 in order, the colour's answer in 2.64 ms median, 4.29 ms p99.
rpc's tests: two terminals' interleaved writes and resizes reach the
service each in order, a stuck terminal holds back no other, and input
sent before the connection ends goes in, in order (all three fail on
the base).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
Wing: "this release is big so it should be 0.3.0". The workspace and both
lockfiles' own crates move to 0.3.0. REMOTE_APPROVALS_SINCE, which only
names the release to update to, says 0.3.0 (there's no 0.2.139 stable).
Audited for a minor bump: 0.2.138's updater and the shipped betas compare
versions numerically with no major/minor or minimum-version rule (0.3.0 is
newer than 0.2.138 and every 0.2.139-beta.N, and a test says so); Windows'
version check is digits and dots; Linux's app/<version> and the beta\<v>
folder take any version; the macOS bundle version 0.3.0.9999 sorts above
0.2.139.N; templates compare by equality, as at every release; the edge,
relay and mesh carry no app-version gates.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
uploads::tests::chat_images_read_only_raster_files_inside_the_chat_folder
failed on macOS. It read a folder linked as the root (elsewhere/chat-folder
-> folder) by the folder's temp-dir name. On macOS that name is itself
behind a link (/var -> /private/var), so it is neither the name the chat
knows the folder by nor its real one; on Linux it is the real one, so CI
passed.
Not a product bug: a chat folder whose ancestors are links (/tmp, /var,
iCloud or Dropbox links) serves its images by the chat's name for it and
by its real name. The test now says so explicitly on both platforms (the
temp folder's own root, under /var on macOS; and the linked root), read
by the chat's name and the real one. The third alias stays refused on
purpose: accepting it means resolving prefixes of a path the agent chose,
which the jail avoids (autofs /net and Windows junctions reach hosts).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
local_first's online_runtime_shutdown_stops_edge_workers_and_retires_the_graph
failed every time ("engine graph still reachable after shutdown + drop").
CI never ran it (scripts/ci/test-core.sh lists the engine tests it runs).
After shutdown + drop the doc host stayed at 2 strong references for good;
tracking every DocHost clone named both:
- The version-change hook (zeron_update::set_before_restart, c004d547c)
is process-wide and captured the doc host and workspace strongly, so
every engine ever assembled in the process stayed alive. It now holds
them weakly and upgrades when it runs: only this process's live engine
restarts it (the CLI never sets a hook), and with its graph gone there
is nothing left to prepare.
- A cycle: the engine holds its plugins (sessions.set_plugins), the
plugins' agents hold their host (EngineAgentHost, 564da4414), and the
host holds the doc host, sessions and workspace. Plugins::shutdown now
lets go of that host, as shutdown already breaks the sessions <-> doc
host cycle. (The agents' sink holds the plugins weakly; left alone.)
Each alone still leaks (the test fails with either fix undone); with
both it passes, 5/5. A new restart_hook test (its own binary: the hook
is process-wide) shows the hook still prepares the running engine's
store and holds nothing after shutdown; with the old strong hook it fails.
The test's next check then failed on this Mac only: one `HEAD /` after
shutdown. lsof named the sender: the Zeron Engine already running on
the Mac, whose preview discovery probes this process's listeners (a
listener bound after shutdown got probed too). Not the engine under
test, so the counting edge leaves `HEAD /` out, as the client tests'
mock edge already does; the engine sends the edge no `HEAD /`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
Same gap as message_queue's (b6b79ab39): a turn revived on boot waits in
`ipc_port_ready` until the boot says it serves a port or none, and these
harnesses said neither, so each revival waited out the 10 s limit.
Found by measuring, not grep: a temporary probe logged every expiry of
that wait across all 64 engine test binaries. It fired in
cloud_killed_turn (4 tests), cloud_attachments and cloud_wake_update,
and nowhere else except the unit test of the limit itself. With the
fix it fires in none.
- cloud_killed_turn: 3 of its revival tests failed (the run came at
boot + 10 s against a 10 s wait); now 15/15 in 1.35 s, from 10.8 s.
a_revived_turn_waits_for_the_machines_logins checked nothing before
(the port wait alone held the run back); without its broker wait it
now fails at once ("a run started ahead of the broker").
- cloud_attachments, cloud_wake_update: 0/5 failures each.
- adapter_chaos_live (#[ignore], real providers; found by review, a
probe run skips it): restart_durability reboots onto a revived turn,
which waited 10 s too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
`RunEnvironment::prepare` gained `chat_id: Option<&str>` (8ea7bf8c1, accounts.pin); the
test's `Logins` broker still had the old three parameters (E0050), so
the whole file failed to build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
send_to_delivered_stays_flat_as_the_chat_grows compared wall-clock send
times in a 3,000-entry chat with a new one and failed under CI load
(4/10 under load locally, before and after beta.7's changes).
It guards c1168b6bf: the open chat's publish runs beside the drains, not
before them. The test now checks that ordering with no clock: it holds
the publish where it hands the transcript to its watchers (a held
`borrow()` of the watch holds `send_replace`), sends, and waits for the
agent to get the send while the publish is still held; released, the
publish lands. With c1168b6bf undone (publish awaited before the
drains) it fails 3/3; with it, it passes in 0.07 s, 0/10 under load.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
message_queue's restart test failed in CI ("timed out waiting for the
interrupted opening turn to be picked back up"). The engine was fine: a
turn revived on boot waits in `ipc_port_ready` until the boot says it
serves a port or none (deferred.rs always says one). The test engine said
neither, so every revival waited out the 10 s limit, racing the test's
own 10 s wait. Logs: resume at boot + 10.004 s when it passed, +10.009 s
when it failed.
assemble_at now calls `set_no_ipc_port()`. Restart test: 1-4/20 failed
alone, 0-2/10 under load before; 0/20 alone, 0/20 under 10 busy cores
after, and it runs in 9.4 s instead of 19 s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
On beta.6 the registry was ~half of the engine's remaining CPU and almost
all of its SQLite writes. Each change (about twice a second on a 5-device
account, mostly session-status rows) re-parsed every chat and session for
every list. Each local write saved the whole 2.56 MB JSON replica. And
the preview service re-read every chat on each scan.
1. Preview: the scan's chat list comes from the published watch channel
(lib.rs). No registry parse per scan; rescans stay event-driven.
2. Reads (crates/doc/src/registry/row_cache.rs): every mutation records
the (kind, id) whose overlay it may change:
- put_authoritative;
- the full replace in apply_state (every row);
- pending ops in enqueue_ops, coalesce_unsent, ack_batch and
set_local_only.
Typed reads (read_chats / read_sessions / read_devices) re-parse only
those rows. Tests check every cached read against a full read, so a
mutation path that forgets to record panics. Per-kind versions let
publish_lists rebuild and send only the lists whose kind changed.
Devices still go out on the presence tick and on relay-verified
presence.
3. Saves: a new row_deltas table (new migration). Each save appends what
changed since the last one (the changed authoritative rows, the
header, the small pending queue), chained by seq on the base whose
saved_at it names. A whole save comes only:
- when the deltas pass max(1 MiB, the base) or 512 rows;
- once the registry has been quiet for 30 s, and at the latest 5 min
after the oldest delta (a build without row deltas reads the base
alone, so what it can miss after a crash is bounded in time);
- at flush and shutdown;
- for the sidebar-import acknowledgement;
- before a restart into another version (stop deltas, save the
registry whole, then the chats and the WAL).
Loads (load_registry, also used by local_import) apply the clean
chain, stop at a gap or an undecodable delta, keep the pending writes
found past a break, and save whole next. append_row_delta refuses
when the base on disk isn't the one its token names.
Equal-terms A/B (fresh scratch store per binary, 300 chats, real mock
turns round-robin on 5 chats, list watches as the app, 5 min, providers
off, env -i):
- base 365383537: 249 whole registry saves (26.3 MB/min), engine CPU
4.5% / 3.6% / 4.4%;
- this change: 7 whole saves (0.74 MB/min) before the final budget; with
it, 2 whole saves + 236 row deltas = ~0.64 MB/min. Engine CPU 2.7% /
2.8%.
Tests (each fails on the old behaviour):
- a_session_status_stream_parses_only_the_rows_that_changed: 200 one-row
changes parse <= 200 rows, against 60,000 with full reads.
- cached_reads_match_full_reads_under_every_mutation: 3,000 random steps
of every mutation kind.
- a_session_status_stream_saves_and_publishes_only_what_changed (engine):
< 4 KB per change, no whole save, the chat list doesn't republish,
reload equals memory, flush compacts. With whole saves it fails at
573 KB.
- row_deltas_fold_into_a_whole_save_once_the_registry_is_quiet.
- a_registry_saved_as_deltas_loads_back_the_same,
a_session_status_change_saves_one_row_not_the_registry,
a_full_replace_needs_a_whole_save,
a_broken_delta_chain_keeps_its_pending_writes.
An independent review found no HIGH issues. Its two MEDIUM findings are
fixed: the time-bounded compaction plus the whole import
acknowledgement, and the relay presence republish. So are LOW 3, 4 and
6; the cache's cross-check now runs in tests only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
From the independent re-review of the previous commit:
- The waiter that kicks the sync dispatcher when a chat's last viewer
leaves held clones of the watch senders, so a viewer's stream outlived
a dropped handle (a cutover or delete) and never resubscribed. It now
ends, releasing them, as the handle drops. It also spawns on the
handle's own runtime when a view attaches from a plain thread.
- A socket request now signals contention only when it actually has to
wait (a failed try-acquire), closing the check-then-wait race. Contention
behind a descriptor-exhaustion pause keeps the dispatcher's timer armed,
since that pause ends on a clock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
The sync dispatcher and remote-wake delivery polled SQLite every 100 ms,
and dev-server discovery walked every user process every 2 s. Idle and
with nothing open, that was 0.3–1.2% CPU and ~85 context switches/s.
Sync dispatcher (doc_host.rs): a pass runs when something it serves
changes: a durable sync job or outbox row (new store change signals), a
sync request, a failed publication, a new handle, a chat's last viewer or
writer leaving, a socket waiter anywhere in the process, a teardown
ending, the registry's chats or its first sync. A 100 ms timer is armed
only while a pass leaves work in flight that moves with time or client
state: a connection catching up, owing a wake receipt or counting down
its idle grace, a client closing, a chat waiting for a slot,
reconciliation or a disk page still to go, a failed write to retry, a
pinned warm set over budget. Passes stay 100 ms apart, so admissions keep
their 4-per-100 ms bound. The fairness handoff, teardown joins and
cursor paging are unchanged.
Remote-wake delivery: wakes on sync-job changes, a delivery ending, or
the workspace being wired. The eight-slot yield keeps its cursor, so
eight dead hosts still can't starve a ninth chat.
Dev-server discovery: scans only the process trees Zeron started (each
process whose own origin marker names a chat or terminal hosted here,
plus their descendants), reading each process's environment once per
lifetime. With none alive, it parks until a run changes state, a terminal
opens, this device's chat folders change, or an open preview loses its
process. Otherwise it keeps its 2 s cadence.
Space git checks: git runs only when an input of its answer changed (the
.git entry, HEAD and the branch it names, config, packed-refs, shallow,
global/system config). Watcher rescans and repository churn cost a few
stats. A failed git call is never cached as the answer.
Measured on a scratch engine (release, symbols), 60 s idle: 0.45% → 0.03%
CPU, 68.8 → 7.3 context switches/s; the 30 s sample has no busy frame
left.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
A deleted chat's agent (claude --print and its MCP servers, ~550 MB on
staging) stayed warm under the engine until the 30-minute idle reaper.
The sessions engine now follows the chat list: when a chat's row goes,
by any path (Delete here or on another device, a Cloud parent's
children, a deleted project's sweep, voice), its run ends through
`terminate`, the Stop's teardown. Archiving keeps the run.
A deleted chat stays deleted: no claim, no status row and no dispatch
for a tombstoned chat, so a run ended mid-turn can't bring the row back
and a queued message can't start a new agent.
DeleteChat also deletes the chat's children on computers (subagents,
side chats) and theirs in turn; a computer's chat keeps its Cloud
delegates, as before. "Delete session?" says what goes with it, as the
host counts it (archived ones too); with nothing, it reads as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
1. Off a runtime, a change's hooks save inline. A save under way holds
the persister's write lock and waits in its export for the doc's
change lock, which the change holds while its hooks run: the inline
save no longer waits for it (it does nothing; the save under way takes
the change in, and the chat stays marked for the next). Same for an
inline request_flush. Test: an_inline_save_from_a_changes_hooks_never_
waits_for_a_save_under_way (deadlocks and times out with the old wait).
2. The client's ViewerSink::relay_export goes through SessionDoc::export
(an export commits what's pending; its events under the change lock).
3. The import marker is per doc: a read of another doc during an import
still asks Loro for that doc's pending changes. (Its uncommitted
changes also move its version, so the cache's version check already
read it whole; the test documents both.)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
An export first commits what's pending; that commit's events must be
delivered under the change lock like any other. SessionDoc::export (and
export_snapshot) hold it, and the engine's production exports go through
it: chat2_host's relay deltas and ChatPersistence's delta saves (merged
from zeron/engine-delta-snapshots).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
Coordinator's decision (no chunked format), plus the third review of B2.
Whole saves at quiet moments. Past the delta budget (a quarter of the
snapshot, at least 1 MiB, or 512 rows), a persister with a worker keeps
writing deltas and marks a compaction due. The worker folds them in once
the chat has had no change for 2 s (QUIET_FOR_COMPACTION), or at
eviction or shutdown as before. A hard cap (4x the budget) forces a
whole save even mid-stream, so deltas can't grow without bound. Offline
use (no worker: tools, tests) can't wait for quiet, so it folds at the
budget as before.
Test: a_streaming_chat_is_saved_whole_only_when_quiet_or_at_the_hard_cap.
~32 KB every 100 ms: past the budget, no whole save while commits
arrive; one within the quiet window; and the hard cap forces one
mid-stream. It fails if the budget forces whole saves with a worker.
Review item 3 (data loss). The M3 discard-and-adopt path loads a
pre-chat2 row, then starts a FRESH doc, and the persister adopted the
loaded version anyway. The fresh lineage was written as deltas on the
old row, whose epoch stayed < 2 (only whole saves stamp it), so after a
crash before compaction the next open discarded everything again.
LoadedBase now carries the row's epoch, and a persister adopts only an
epoch-2 row whose version the doc already contains.
Test: a_fresh_doc_never_continues_a_row_it_did_not_grow_from (the M3
shape, then a crash: the reopen has epoch 2 and the new content; plus an
unrelated doc on an epoch-2 row). It fails without the guard.
Review item 4. append_snapshot_delta takes an IMMEDIATE transaction (a
busy store waits out its busy timeout, not fails at the INSERT).
load_merged reads the row and its deltas in one read transaction.
flush_for_sleep holds the snapshot connection, then the main one, so
the WAL is empty at sleep.
Note (review item 5): with two connections, an outbox write during a
whole save longer than the 5 s busy timeout falls into the
failed-publication path, where it used to wait on the mutex. Nothing is
lost (the replay obligation holds), and quiet-time compaction makes such
saves rare.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
Review of df4eecfe0: the phone shares RegistryClient and stops beating in
the background on purpose (each beat wakes the radio). With a 'beating'
flag that never cleared, every background reconnect after a network change
sent a fresh beat and showed the phone online. The client now keeps when
the host last asked for presence; a (re)join beats at once only within
RegistryTuning::rejoin_beat_window (35 s, about two 15 s heartbeats).
Only that rejoin beat emits a Presence event; a steady own beat shows at
the host's next publish instead of pushing device rows every 15 s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
Second-pass review: Loro delivers a LOCAL commit's events after releasing
its own lock, so an import could land in between (measured: the import
shows in reads ~7 ms before its events arrive), and the version the
commit's callback recorded covered the import with only the commit's
entries: a read in that gap trusted a stale cache.
SessionDoc now holds a change lock (reentrant) through every commit and
import and the delivery of its events: all SessionDoc writes commit
through SessionDoc::commit, and the engine's room/relay imports and the
client's room imports go through SessionDoc::import*. A read takes the
lock only to capture the version and the changes recorded up to it.
On a thread inside an import, Loro holds its transaction lock until the
import's events are delivered; a read there skips asking for pending
changes (it would wait on that lock; none can be pending).
The kept bytes are atomics, so the engine's eviction weighs a chat
without waiting on its cache. The app's order check leaves out rows
without an id, as `known` does.
Test: a_read_between_an_overlapping_import_and_its_events_is_whole (a
probe starts the import while the commit's events are delivered and reads
from another thread in the gap): passes; without the change lock it gets
a stale read and fails.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
The store was one Mutex<Connection>, and every commit writes its outbox
row inside the commit callback (under the chat2 client lock). So each big
snapshot upsert (40-330 ms for a 50-60 MB chat) stalled every commit in
every chat: Wing's freeze-then-burst (found by 13eb2276).
1. Snapshot reads and writes get their own connection (snap_conn). An
outbox write no longer waits for the Rust mutex behind a whole save,
only for SQLite's single writer, and loads never block commits.
Measured (outbox_writes_stay_fast_while_a_whole_snapshot_saves, a
write every 5 ms during 50 MB whole saves): max wait 120-143 ms
before, about 64 ms now. Getting under a ~20 ms budget needs whole
saves written in small transactions; that is a separate change.
2. No whole save after reopening. A load that finds a clean base (no
deltas, or every delta applied on this base) offers it, and the next
ChatPersistence adopts it: deltas continue from the version on disk.
Before, every engine start made the first save of every hot chat
whole (47 MB for the largest). The offer never displaces a base this
process already tracks; any full write invalidates it as before; a
delta append also checks that the base row still exists (primary key
only, no blob read).
Tests:
- a_reopened_chat_saves_a_delta_not_the_whole_doc: with 0 and 3 earlier
deltas, the save after a restart is a delta, the reload equals memory
and has the newest cursor, and compaction still folds everything. It
fails without adoption ("a whole save after reopening").
- a_reopened_chat_saves_whole_when_its_disk_state_is_not_a_clean_base:
no adoption past a bad delta, or after a full write in between.
- a_store_from_before_deltas_migrates_and_reads_unchanged: now both
saves after loading the migrated snapshot are deltas.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
Third review of B:
1. The open path retired parked rows right after importing them into
memory, before the persister or change subscription existed, so
nothing marked the doc dirty. If the chat was evicted or the process
stopped before the next change, those ops were on disk nowhere. Now
the open replays them, marks the doc dirty, saves, and retires the
rows only if that save left the persister clean. Otherwise they stay
and replay at the next open. With no chat2 persister, they stay.
Test: opening_a_chat_after_a_lost_delta_row now reads the store
through a second connection with no change since the open: Q's ops
are there. It fails if the rows retire at once ("the parked ops were
retired before any save held them").
2. base_saved_at and seq were added by editing the snapshot_deltas
migration, so a dev DB from an earlier build failed every delta
insert and load. The table is back to its first shape, and each
column is a new "ADD COLUMN IF MISSING" migration, which migrate()
checks with PRAGMA table_info (pre-release DBs may already have the
column). Old rows (base_saved_at 0, seq 0) claim no cursor and go to
the parked inbox. Test: stores_from_earlier_delta_schemas_open_and_work
covers all three pre-release shapes. It fails with the columns never
added ("no such column: base_saved_at").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>