Skip to content

Sessions: turns, forks and event replays no longer load a whole session or log (#254) - #1102

Merged
abu-aska merged 7 commits into
mainfrom
perf/sessions-hot-paths-254
Nov 2, 2026
Merged

abu-aska merged 7 commits into
mainfrom
perf/sessions-hot-paths-254

Conversation

@ahrazzle

@ahrazzle ahrazzle commented Nov 2, 2026

Copy link
Copy Markdown
Member

Each turn decoded every message of its session twice, or three times with learning on. A fork wrote one transaction per copied message. The hub's replay, exo trace and /handoff read the whole event log at once. Over stdio, events.subscribe also built a reply with every event and then dropped it.

Now a turn counts and tails its session in SQL, a fork is one transaction, and event reads with no bound go 1,000 events at a time. Results are the same as before.

Part of #254 (W2-4). W1-5 landed in #442. What remains is the context transcript tail, which is draft #903. This branch carries the same last_messages helper as that draft, word for word and in the same place, so the two merge cleanly.

Finding 1: a turn decoded its whole session twice

  • Repro: on main, one turn on a 1,300-message session decodes 2,587 messages.
  • Cause: Loop._turn loaded the whole session to count the user turns it passes to memory, then loaded it all again to keep the last 40 messages for the memory checkpoint. /handoff also loaded the whole thread to count user turns. With learning on, which is the default once a principal store exists, the chat capture after each turn loaded the session a third time to keep its last 12 messages. A review loaded it for its last 6.
  • Change: SessionStore.user_turns counts in SQL with the old rule: a user message counts unless its context note is one Python reads as true (a note of "", 0, false, null, [] or {} still counts). SessionStore.last_messages reads the newest rows through the (session, seq) index. The loop and /handoff use them. Learning's chat capture and review digest read their tail through Learner.last_messages, which uses the same helper.
  • Tests: tests/core/test_session_hot_paths_254.py. Both helpers equal the full load on sessions with notes of every kind and an undone tail. A turn on a 1,300-message session decodes at most 45 messages, with the same turn number and checkpoint. /handoff gives the same count without a whole-thread load.
  • Tests: tests/learn/test_learn_signals.py. On a 302-message thread that ends with a correction, the capture records the same verdict after decoding at most 12 messages, and the digest decodes at most 6.

Finding 2: a fork wrote one transaction per copy

  • Repro: on main, a fork that fails at its 30th copy leaves a new session with 29 copies. A 5,000-message fork takes 2.9 s.
  • Cause: SessionStore.fork wrote each copy through append_message, each in its own write transaction, and each summary in another statement.
  • Change: the fork runs in one write transaction. The session goes through the same insert as create_session. Every copy is built as append_message built it, and the copies, search rows and summaries are written with executemany. A failure rolls it all back.
  • Tests: tests/core/test_fork_one_transaction_254.py. The new fork equals the old one row by row (data bytes, seq, copy_pos, search text, summaries) for thread, scheduled and private parents, with and without a fork point. A fork is one transaction, and a failed fork leaves no row behind.

Finding 3: event reads with no bound read the whole log

  • Repro: on main, a client that subscribes from seq 0 on a home with 100,000 events waits 733 ms for its first event, and the core holds all 100,000 (88 MB at the peak).
  • Cause: the hub's replay (SqliteLog.read), trace and /handoff called events_since with a limit of 2^30. A Subscription then copied that list into its backlog.
  • Change: SessionStore.iter_events reads 1,000 events at a time and stops at the newest seq at the call, so it returns what one read at the call returned. It reads the first page at once, so a bad since still fails when the caller asks. The three callers use it.
  • Subscriptions: a Subscription takes the log's iterator as its backlog through the new Hub.replay, which Hub.since also lists. The queue is still registered before the backlog is read, so there is still no gap and no repeat. The one-shot events.subscribe reply still carries the whole replay, as the protocol says.
  • A read that also keeps events of no session (with_global, the hub's replay) is now two index searches joined by UNION ALL. Its OR form sorted every later event on each call, so reading page by page would grow with the square of the log.
  • Tests: tests/core/test_event_paging_254.py. iter_events equals one unbounded read for each filter. The replay test from docs/OPTIMIZATION.md W2-4 subscribes from seq 0 across three pages while live events publish, and every seq arrives once, in order.
  • More tests in the same file: subscribing decodes at most one page before the first event. Trace and /handoff never ask for more than one page. One page with global events costs the same at 2,000 events and at 20,000. A filter put in Hub.replay reaches both Hub.since and a subscription's backlog.

Finding 4: a stdio subscribe still read the whole log

Found while checking finding 3.

  • Repro: with findings 1 to 3 fixed, a stdio client that subscribes from seq 0 on 3,000 events still makes the core decode 4,000 events before the first one goes out: the whole one-shot reply, then one page.
  • Cause: the stdio transport sent events.subscribe through the dispatcher. Its one-shot reply decoded every event and made a dict of each. The transport then dropped that reply and streamed from a Subscription.
  • Change: the transport decodes the line itself and opens the Subscription at once. A since the log cannot read still gets the same typed internal reply, and the transport lives on. A Subscription whose first read fails now takes its queue back out of the hub, so no queue is left to fill with later events.
  • Tests: tests/core/test_event_paging_254.py. A stdio subscribe from seq 0 sends its first event after one page is decoded, and every event arrives once, in order. A since past SQLite's range gets the typed reply and leaves no queue in the hub.

Benchmarks

Local runs on the file store in WAL mode, from a script that is not part of the suite:

Case Before After
10,000-message session: count of user turns 196 ms 7.8 ms
10,000-message session: last 40 messages 190 ms 0.9 ms
Fork of a 5,000-message session 2.9 s 0.25 s
100,000 events: subscribe from seq 0 to the first event 733 ms, 88 MB peak 7 ms, 0.9 MB peak
100,000 events: read them all 0.74 s, 88 MB peak 0.74 s, 1.6 MB peak

Each test fails without its fix

With the source of all seven commits undone at once (main 6ec085b's src with this branch's tests), 14 of the 25 tests fail. The 11 that pass are the nine fork equivalence cases, the replay test and the stdio typed-reply test. Main already meets those: they check that the new code keeps main's results.

Each part was also undone alone, with the tests kept:

  • The count and tail commit undone: 4 failed (the two helper tests, the turn test and the /handoff count).
  • The fork commit undone: 2 failed (one transaction, and a failed fork leaves nothing).
  • The paging commit undone: 5 failed.
  • One call site at a time: the loop count, the loop tail, the /handoff count, the /handoff task events, SqliteLog.read, a Subscription that lists its whole backlog, and the OR form of the global page each fail 1 test. Trace fails 2.
  • The stdio change undone: the stdio test fails, with 4,000 events decoded before the first one goes out, against a bound of 1,000.
  • The Subscription cleanup undone: the typed-reply test fails, because a queue is left in the hub.
  • A backlog read from the log directly instead of Hub.replay: the new replay test fails, because the backlog skips the filter that Hub.since applies.
  • The learning change undone: the new learning test fails, with all 302 messages decoded against a bound of 12.

The equivalence tests and the replay test pass on the old code too, as they should.

Overlap with open PRs

Checked by trial merges without the CHANGELOG union driver, on the PR heads as of 2026-11-02 03:20 UTC.

Checks (local)

On 55f3593 (main 6ec085b), with the worktree's src first on the path and a temporary HOME and EXO_HOME:

  • Full root suite: 21,485 passed, 209 skipped, 40 xfailed, 2 failed. Both failures are wall-clock caps in gate tests, at a load average near 8.5 on 4 CPUs. A long sudo chain took 10.5 s against a 10 s cap in tests/security/test_gate_sudo_shell_stdin.py, and a YAML flow value passed the 5 s cap in tests/security/test_gate_yaml_progress_981.py. Run again on the same head, both files pass (313 passed). This branch does not touch the gate.
  • The new and changed test files (the three tests/core/*_254.py files and tests/learn/test_learn_signals.py): 50 passed.
  • Related tests (tests/protocol, tests/trace, tests/learn, the jobs and seat tests, and two security files): 502 passed, 2 xfailed.
  • tests/docs: 49 passed. The core budget test passes.
  • Plugins: exo-context 171 passed. exo-bus 50 passed. exo-command 393 passed, 135 skipped.
  • ruff: clean. check_types on Python 3.11: the branch matches its baseline at 221 diagnostics. The one it resolves, the wait_for argument type in Subscription.next, is pruned from the baseline, which has one entry fewer than main's.
  • No gate file changed, so gate_diff was not run.
  • The branch sits on main 6ec085b, so a merge without the CHANGELOG union driver is clean.

Core lines

The branch counts 16,122 core lines, 1,309 above the floor of 14,813. That is 86 more than main's 16,036: sessions.py grows by 63, server/app.py by 12, server/engine.py by 10, and trace.py by 1. D-083 sets no ceiling, so nothing else changes. The structure caps hold: 39 of 39 inward imports and 8 of 8 private-state reads.

User guide: none. Developer guide: none.


Generated by Claude Code

Each turn decoded every message of its session twice. Loop._turn counted
the user turns it passes to memory by loading the whole session, and the
memory checkpoint loaded it all again to keep the last 40 messages.
/handoff counted user turns the same way. The cost grew with the session.

SessionStore.user_turns now counts in SQL with the same rule: a user
message counts unless its context note is one Python reads as true.
SessionStore.last_messages reads only the newest rows through the
(session, seq) index. Its text and place match draft #903, so the two
merge cleanly. Results are unchanged: the tests compare both helpers
with the full load on sessions with notes of every falsy and truthy
kind and an undone tail, and a turn on a 1,300-message session now
decodes at most 45 messages.

User guide: none. Developer guide: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
SessionStore.fork wrote each copied message through append_message, so
every copy took its own write transaction, its own seq lookup and its
own session update, and each summary took another statement. A large
fork was slow, and a fork that failed partway left a new session that
held only part of the thread.

The fork now runs in one write transaction. It adds the session through
the same insert as create_session, builds every copy the way
append_message did, and writes the copies, their search rows and the
summaries that still fit with executemany. A failure rolls all of it
back. The tests compare the new fork with the old one row by row (data
bytes, seq, copy_pos, search text, summaries) for thread, scheduled and
private parents, with and without a fork point.

User guide: none. Developer guide: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
The hub's replay (SqliteLog.read), trace and /handoff called
events_since with a limit of 2^30, so one read decoded every matching
event at once. A Subscription then copied that list into its backlog,
so a client that subscribed from seq 0 waited for the whole log and the
core held all of it until the client caught up.

SessionStore.iter_events reads 1,000 events at a time by seq and stops
at the newest seq at the call, so it returns what one read at the call
returned. It reads the first page at once, so a bad since still fails
when the caller asks. The three callers use it, and a Subscription keeps
the log's iterator as its backlog. The queue is still registered before
the backlog is read, so the no-gap, no-repeat promise holds. The replay
test subscribes from seq 0 across three pages while live events publish
and gets every seq once, in order.

A read that also keeps the events of no session (with_global, the hub's
replay) is now two index searches joined by UNION ALL. Its OR form made
SQLite sort every later event of the session on each call, so a read
page by page would have grown with the square of the log. With the
change, 100,000 events read page by page in the same 0.74 s as one
unbounded read, with 1.6 MB at the peak instead of 88 MB.

In Subscription.next the event now reads as Event | None from its first
assignment, which matches the queue, so the one mypy diagnostic there
is gone and the type baseline drops it.

User guide: none. Developer guide: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
Two parts of the #254 W2-4 change had no test that fails without them.
/handoff could go back to loading the whole thread to count its user
turns, and the tests would still pass: they checked only the count the
loop passes to memory. The events_since read that also keeps events of
no session could go back to its OR form, which sorts every later event
on each call, and the tests would still pass, because both forms return
the same rows.

The first new test runs /handoff on a 30-turn thread and checks that it
counts the same user turns without a whole-thread messages() load. The
second counts SQLite's steps for one 10-event page at 2,000 events and
again at 20,000: the UNION ALL form costs the same both times, and the
OR form grew tenfold. Each test fails with its part of the change
undone.

User guide: none. Developer guide: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
The stdio transport sent events.subscribe through the dispatcher,
whose one-shot reply decodes every event since the cursor and turns
each into a dict. The transport then dropped that reply and streamed
from a Subscription. So a stdio client that subscribed from seq 0
still made the core decode the whole log at once, and paging the
Subscription's backlog did not help it.

The transport now decodes the line itself and opens the Subscription
at once. The Subscription reads its first page there, so a since the
log cannot read still gets the same typed "internal" reply and the
transport lives on. The feed takes that Subscription and opens a new
one only after a stream ends for lag, as before. Every other command
still goes through the dispatcher.

A Subscription whose first read fails now takes its queue back out of
the hub. Before, the queue stayed registered and filled with every
later event until the lag rule dropped it.

The new tests subscribe over stdio from seq 0 on 3,000 events: the
first event goes out after one page is decoded, where main decoded
4,000. A since past SQLite's range gets the typed reply and leaves no
queue in the hub.

User guide: none. Developer guide: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
After the paging change, a Subscription read its backlog from the log
directly, while Hub.since read the same events through the hub. Open
PR #946, and the PRs stacked on it, filter what the hub replays by
session owner in Hub.since, and a Subscription there takes its backlog
from Hub.since. Merged with this branch in either order, git joins the
two with only an import-line conflict, and the backlog would then skip
the owner filter without anyone seeing it.

Hub.replay now hands out the log's iterator, Hub.since lists it, and a
Subscription takes its backlog from it. A rule on what the hub replays
has one place, and #946's change to Hub.since now meets this one on
the same line, where whoever merges second sees it.

The new test puts a filter in Hub.replay and checks that Hub.since and
a subscription's backlog both apply it, across more than one page. It
fails with the backlog read from the log directly.

User guide: none. Developer guide: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
Learning is on by default once a principal store exists. After every
turn, its on_turn_end hook records corrections from the chat, and that
loaded the whole session to keep its last 12 messages. A review loaded
the whole session to keep its last 6 for its digest. So even with the
loop's own count and tail in SQL, each turn still decoded every
message of its session once.

Learner.last_messages reads the newest rows through the session
store's last_messages, the same helper the loop uses. A store without
that helper gets the old full read and its tail, so results do not
change. The chat capture and the review digest use it.

The new test runs both on a 302-message thread whose last message is
a correction. The capture records the same verdict after decoding at
most 12 messages, and the digest decodes at most 6. Main decoded all
302 each time.

User guide: none. Developer guide: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T03:25:47.063660Z 55f3593 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@abu-aska abu-aska left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: approve. Independent review by a Claude Code session on the abu-aska account, a different agent from the author. Reviewed at 55f35930. Tests and probes run, every finding re-checked.

What works

  • Same results as main. I built one store on main through the public API: 3 sessions of 1,300 messages (plain, thread, private) with notes and undone turns, plus 3,500 events across 3 sessions and no session. Main's full reads and the head's user_turns, last_messages and iter_events gave 237 digest lines, and cmp printed IDENTICAL.
    • That covers 216 event reads (135,808 events): since from 0 to 9,999 across page edges, each session and None, with_global on and off, and skip of (), message.delta and notice.
    • It also covers tails of 1, 6, 12, 40, 999 and 5,000 messages, and the turn counts (358, 350, 342).
  • Turn count rule. Over 15 note values (missing, None, "", 0, 0.0, False, [], {}, "threads", True, [0], {"a": 1}, 1e-400, NaN, inf), user_turns equals main's Python count for every value except NaN (see Nits).
  • Forks are faster and leave nothing on failure. Fork times, main against head:
    • Plain session, 5,000 messages: 3.90 s and 1.29 s.
    • Agent thread, 20,000 messages with 20 KB tool results: 20.77 s and 9.15 s.
    • Agent thread, 50,000 messages: 32.19 s and 4.40 s.
    • A fork that runs out of pages (PRAGMA max_page_count): main leaves 1 child with 94 copies. The head leaves 0 children and 0 copies, and integrity_check is ok.
  • A second probe with fixed ids made 26 forks (812 messages, 769 search rows, 87 summaries) and found the main and head tables byte-identical.
  • The stdio typed reply holds when the first page fails. With an undecodable row at seq 500, both trees send c1 an internal reply and answer the next command.
  • The new cleanup fixes a queue left on main. Main's SSE subscribe left 1 queue when its first read failed. The head leaves 0.
  • The paging tests have teeth. Two in-memory mutants were caught: SqliteLog.read put back to one unbounded read fails 2 tests, and the union page without its outer LIMIT fails 1.
  • CI: all 10 check runs succeed on 55f35930.

Should fix

1. A large fork holds the write lock for its whole run, so another process fails with database is locked.

  • Repro: scripts/lockhold.py forks in one process. A second process polls BEGIN IMMEDIATE and opens a SessionStore 1 s after the fork starts. The parents were built through the public API.
    • Plain session, 20,000 messages, 4,995 summaries. Head: fork 17.48 s, no write lock for 17.29 s, and the second open failed after 5.02 s with OperationalError: database is locked. Main: fork 31.05 s, longest wait 0.75 s, and the open succeeded after 0.03 s.
    • Agent thread, 20,000 messages with 20 KB tool results. Head: fork 9.15 s, no write lock for 7.19 s, and the open failed after 5.01 s. Main: longest wait 0.41 s, and the open succeeded after 0.13 s.
    • Agent thread, 50,000 messages. Head: no write lock for 3.96 s, and the open waited 2.94 s before it succeeded. Main: the open succeeded after 0.00 s.
  • Cause: all of fork runs inside _tx's BEGIN IMMEDIATE. That includes reading and re-encoding every row and the correlated summaries query. On the 20,000-message plain session, that query alone took 14.68 s of the transaction. _open keeps Python's default 5 s busy timeout, so other seats on the same home and CLI commands give up.
  • Fix:
    • Read the rows, build the copies and select the summaries before BEGIN IMMEDIATE, for example in a _read snapshot. Inside the write transaction, check that the parent's rows up to upto are unchanged, then insert.
    • Make the summaries selection one pass: find the first hidden or missing seq once, then take the summaries that end before it.
    • Add a test that a second SessionStore opens during a fork of a few thousand messages.

2. A replay read that fails after the first page leaves a stdio client subscribed and silent.

  • Repro: scripts/stdio_badrow.py builds 3,000 events, sets the body of seq 1,500 to {}, and runs serve_lines: subscribe since 0, a live publish, session.list, then EOF.
    • Main: c1 gets internal with ValueError: Notice: Notice.__init__() missing 1 required positional argument. c2 gets its reply.
    • Head: c1 gets subscribed: true, then 1,000 events (last seq 1,000). The live event never arrives, and serve_lines raises ValueError from its EOF flush.
  • A bare Subscription that catches the error and calls next() again skips the other 1,999 backlog events and returns live seq 3,001. A finished generator reads as an empty backlog. No consumer in the tree retries today.
  • Cause: only the first page is read at subscribe. A later page fails inside the pump task, which closes its queue and sends nothing.
  • Fix: in pump, catch Exception and send a typed failure for the subscribe, or a notice, before ending. Guard the EOF flush the same way. In Subscription.next, when the backlog raises, drop the queue and keep raising, or end the stream with Closed so the client resumes with since. Add a test with an undecodable row on page 2.

3. The tests do not pin two of the claimed properties.

  • I ran in-memory mutants as pytest plugins against the three tests/core/*_254.py files, tests/learn/test_learn_signals.py and tests/trace. Each mutant below passes them all (146 passed, 2 xfailed):
    • fork writes its summaries after the transaction, as autocommit statements. test_a_failed_fork_leaves_nothing fails at the 30th copy, before any copy is inserted, so it rolls back only the session row.
    • iter_events applies skip to the first page only. Trace's turn-end read passes skip to drop the delta and tool-output events on every page.
  • A third mutant, the union page without its outer LIMIT, is caught only by the cost test, through its len(...) == 10 check.
  • Fix: make a fork fail at its last write (for example a TEMP trigger that raises on INSERT INTO summaries) and check all four counts. Add an equivalence case with mixed event types and a skip that spans pages. Add a case where both union branches hold more than one page.

Nits

  • A NaN note counts as a turn. json.dumps writes NaN as a bare NaN, and SQLite's json_extract reads it as null. So user_turns gives 2 where main's count gives 1 (scripts/notes.py). Nothing writes a note other than "threads" or "private" today. Name the NaN case in the user_turns docstring and in the PR body's statement of the rule.
  • A fork on a full disk now reports the wrong error. scripts/diskfull.py on the head raises cannot rollback - no transaction is active, with database or disk is full only as its context. Main raised the disk-full error itself. SQLite has already rolled back, and _tx runs ROLLBACK anyway. Roll back only if self._db.in_transaction, as __init__ does. The data is clean.
  • stdio subscribe registers its queue before the reply write. If that write raises (BrokenPipeError), the queue stays in the hub: 1 queue on the head, 0 on main (scripts/stdio_gone.py). MAX_LAG drops it later, and the stdio core exits on that error anyway. Start the pump before the reply, or close sub when the write fails.
  • iter_events does not check page. page=0 raises IndexError on the first next. page=-1 reads all 25 events in one page, then raises IndexError. No caller passes page. Raise ValueError as last_messages does for its limit.
  • Docs and PR body:
    • docs/OPTIMIZATION.md row #254 cites trace.py:540 and diagnostics.py:155. The calls are at trace.py:541 and diagnostics.py:154. Naming the functions would not drift.
    • The D-010 amendment's Tests list leaves out tests/learn/test_learn_signals.py, the only test of the Learner.last_messages change. The docs/DOCS-MAP.md row names 5 of the 9 changed src files. It leaves out core/engine.py, core/trace.py, diagnostics.py, learn/review.py and learn/signals.py.
    • The PR body says SqliteLog.read undone fails 1 test. It fails 2 (test_subscribe_from_zero_holds_one_page and the stdio test).

Notes

  • Peak memory of a large fork is higher. On the 20,000-message agent thread with 100 MB of message data, the fork grew peak RSS by 629 MB on the head and 401 MB on main. Both load the whole range. Reading in pages inside the transaction would bound it.
  • Undo and the turn count use different rules (already on main). undo treats a note of "" as a note (IS NULL). The count treats it as a turn. undo(1) on ask, reply, empty-note, reply removes 3 rows on both trees, and the count goes from 2 to 1.
  • A subscriber mid-replay at shutdown reads the store after engine.close(). serve() closes the hub, then the engine, then the servers. On the head, the later backlog pages read SQLite.
    • scripts/shutdown.py: the file store reopens its connection ("open again after close: True"). A :memory: store raises ProgrammingError after 1,000 events. Main delivers all 2,500 from memory on both.
    • Production uses the file store, and the process exits next.

Checks

  • python -c 'import exo; print(exo.__file__)' under each tree's PYTHONPATH: .../main/src/exo/__init__.py and .../w1102/src/exo/__init__.py. SQLite 3.45.1.
  • pytest -q -p no:cacheprovider tests/core/test_session_hot_paths_254.py tests/core/test_fork_one_transaction_254.py tests/core/test_event_paging_254.py tests/learn/test_learn_signals.py tests/learn/test_learn_review.py tests/protocol tests/trace on the head: 314 passed, 2 xfailed in 49.45 s.
  • pytest -q -p no:cacheprovider tests/core tests/learn tests/docs on the head: 1423 passed, 2 skipped in 135.27 s.
  • Mutants (pytest -p <plugin>) on the three tests/core/*_254.py files, tests/learn/test_learn_signals.py and tests/trace: fork summaries after the transaction 146 passed, 2 xfailed. skip on the first page only 146 passed, 2 xfailed. No outer LIMIT 1 failed, 145 passed, 2 xfailed.
  • The SqliteLog.read mutant on the three *_254.py files and the learning test only: 2 failed, 48 passed.
  • scripts/equiv.py: main and head digests identical (237 lines, 216 event reads, 135,808 events).
  • scripts/notes.py: 1 difference in 15 note values (NaN).
  • scripts/lockhold.py, scripts/forkmem.py, scripts/diskfull.py, scripts/stdio_badrow.py, scripts/stdio_gone.py, scripts/shutdown.py and scripts/pagearg.py on both trees: outputs as quoted above.
  • CI on 55f35930: 10 of 10 check runs succeed.
  • The scripts/*.py probes are local to this review and not part of the repository. Each ran under each tree's PYTHONPATH with a fresh temporary HOME and EXO_HOME. The large parents were copied per run, so main and the head forked the same rows.

Generated by Claude Code

@abu-aska abu-aska left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified

  • user_turns SQL matches the old Python rule across the falsy/truthy cases: missing, null, false, 0, 0.0 and "" count; a non-empty note does not. The string "[]" is not confused with the JSON array []: the array/object arm requires json_type to be array or object, so a string "[]" still does not count, while a real [] or {} does. The new tests pin exactly these values, plus an undone tail.
  • last_messages reads only the newest rows through the (session, seq) index and returns them in transcript order; messages() on main already filters hidden=0, so the hidden=0 filter matches the old reads.
  • Fork rewrite keeps the old behaviour: hidden rows are excluded by both the old messages() call and the new query, copies are renumbered 1..n, agent-log pos stays unset for fork copies (meta local=fork), and the summaries copy uses the same end_seq rule. Atomicity holds: copy runs inside _tx (BEGIN IMMEDIATE, ROLLBACK on any exception), and the session row, message copies, FTS rows and summaries commit together.
  • iter_events pages at 1,000 and stops at the newest seq at call time, so a long read holds one page; the with_global UNION ALL takes the top page of each stream before merging, which cannot drop or repeat a seq.
  • Server side: Subscription still registers its queue before the backlog is read, and __anext__ closes the queue when the stream ends for lag, so the new pump resubscribe does not leak queues. The dispatch/decode split preserves the old failure shape (None, typed failure) for undecodable lines, and the stdio subscribe path still answers a bad since with a typed reply instead of killing the feed.
  • Landing rules: CHANGELOG, DECISIONS (D-010 amendment) and DOCS-MAP updated in the same change, plus three new test files and the mypy baseline refreshed; types and lint pass.

Non-blocking notes

  • last_messages(limit=0) returns [] while the old messages()[-0:] slice would have returned everything. No caller passes 0 (40, 12, 6), so this does not block, but the helper's contract should stay "at most limit" rather than slice-like.
  • Issue #1103 (the one-shot events.subscribe reply) is deliberately left out of this PR and stays open; it needs a protocol decision, so it is not a gap in this change.

Verdict

Approve. The hot-path reads are equivalent to the old ones, the fork is now atomic without changing what it copies, and the paging is bounded as claimed.

@abu-aska
abu-aska merged commit 53226fb into main Nov 2, 2026
10 checks passed

ahrazzle commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

This merged before the findings in review 5732419504 were fixed, so two of them are now on main. A large fork holds the write lock for its whole run, so another process that opens the store fails with "database is locked". A replay read that fails after its first page leaves a stdio subscriber subscribed and silent.

I am fixing both in a follow-up PR from main, with the tests the review asked for, its nits, and the last_messages(limit=0) note from 5732449717. I will link it here.


Generated by Claude Code

abu-aska pushed a commit that referenced this pull request Nov 2, 2026
Brings #1089 (the gate reads what printf or echo -e pipes into a
shell, #1047) and #1102 (session hot paths read in SQL and pages,
#254). GitHub reported a conflict in CHANGELOG.md, where those PRs
and this branch each add lines at the top of Fixed. All lines are
kept. Every other file merged on its own.

Tests: tests/docs, tests/test_merge_attributes.py andntests/core/test_event_paging_254.py: 64 passed. test_browser_startup.pynand test_csp_web.py with headless Chromium 141: 32 passed.
User guide impact: none.
Developer guide impact: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SWwciAkq4F3SjfvXMYh8Lp
abu-aska pushed a commit that referenced this pull request Nov 2, 2026
Brings #1089 (the gate reads what printf or echo -e pipes into a
shell, #1047) and #1102 (session hot paths read in SQL and pages,
#254). GitHub reported a conflict in CHANGELOG.md, where those PRs
and this branch each add lines at the top of Fixed. All lines are
kept. Every other file merged on its own.

Tests: tests/docs, tests/test_merge_attributes.py andntests/core/test_event_paging_254.py: 64 passed.ntest_provider_retry_web.py with headless Chromium 141: 25 passed.
User guide impact: none.
Developer guide impact: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SWwciAkq4F3SjfvXMYh8Lp
abu-aska pushed a commit that referenced this pull request Nov 2, 2026
Brings #1089 (the gate reads what printf or echo -e pipes into a
shell, #1047) and #1102 (session hot paths read in SQL and pages,
#254). GitHub reported a conflict in CHANGELOG.md, where #1089 and
this branch each add a line at the top of Fixed. Both lines are kept.

src/exo/gate.py, DECISIONS.md, docs/GATE.md and docs/DOCS-MAP.md
merged on their own. The branch's gate.py diff against main has the
same added and removed lines as 9bf1ba3 against 6ec085b.

Tests: the #867 and #1047 gate test files, tests/docs and
tests/test_merge_attributes.py: 453 passed. tests/security and
tests/test_gate_diff.py: 17765 passed, 117 skipped, 36 xfailed.
plugins/exo-gate: 2868 passed, 17 xfailed.
gate_diff against main 53226fb, built-in --no-variants: 1,405,976
pairs, lowered 0, tightened 0, errors 0. Aimed --only-corpus: the
#867 loop rows inside printf, printf %b, echo -e and sudo -s pipes,
escaped and plain, 4,440 actions x 101 policies (the 88 built-in and
13 with /dev*, /proc* and *store* target rules) = 448,440 pairs,
lowered 0, tightened 9,370, errors 0. An escaped loop pair piped
through printf or echo -e now denies under deny: [target:/proc*] as
the plain pair does, where main asks.
ruff and git diff --check: clean.
User guide impact: none.
Developer guide impact: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SWwciAkq4F3SjfvXMYh8Lp
ahrazzle pushed a commit that referenced this pull request Nov 2, 2026
Main gained #1102 (sessions hot paths, #254) and #1106 (context build
reads, #262) since this branch's base. Two docs files conflicted, and
each side's text is kept whole:

- DECISIONS.md: D-010 now ends with this branch's 2026-10-31 amendment
  (#263) and then main's 2026-11-01 amendment (#254), in date order.
- docs/OPTIMIZATION.md: the #262 row is main's (#1106) and the #263 row
  is this branch's. Each side changed only its own row.

CHANGELOG.md, docs/DOCS-MAP.md and src/exo/core/engine.py merged
without a conflict.

User guide impact: none.
Developer guide impact: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5

ahrazzle commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

The follow-up is #1115, and issue #1114 records the two regressions it fixes. A fork now builds its copies on a read snapshot and holds the write lock for under 0.5 s, and a replay page that fails ends a stdio subscribe with a typed reply. It also has the tests review 5732419504 asked for, its nits, and the last_messages(limit=0) contract from 5732449717.


Generated by Claude Code

ahrazzle pushed a commit that referenced this pull request Nov 3, 2026
Main adds #1089 (gate printf escapes), #1102 (session hot paths, #254),
#1101 (Providers redraw in the web view), #1106 (each summary tree read
once, #262), #1105 (one HTTP client per event loop, #263), #1107
(browser startup labels) and #1108 (tasks.list active filter, #997).

src/exo/core/engine.py needed a hand resolution. This branch moved
stop_channels into the close-step tuple. #1105 appended
self.router.aclose to the same tuple. The tuple keeps both:
stop_channels first and router.aclose last. So the router's HTTP
clients close with the other transports, before the bounded wait for
turns and tool workers. The other engine.py hunks from #1102 and #1108
merged on their own.

src/exo/harness_runtime.py: #1108 makes the engine call
agents.list(session, active=...), and the terminal now sends
tasks.list with active set. DisabledDelegator.list did not take
active, so with delegation off that command failed with a TypeError.
It now takes active and still returns an empty list.

tests/test_harness_runtime.py checks both the method and tasks.list
through the dispatcher. Both checks fail without the fix.

docs/HARNESS.md: step 2 of the shutdown order now says that close also
closes the HTTP clients the model router made.

User guide impact: none. Developer guide impact: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
ahrazzle pushed a commit that referenced this pull request Nov 3, 2026
This branch is stacked on #500. It takes #500's new head 73ff5a8, which
merges main 21e964c (#1089, #1102, #1101, #1106, #1105, #1107 and
#1108) on top of the 293e477 merge. No file needed a hand resolution
here.

- #500's head resolved src/exo/core/engine.py by hand. Its close-step
  tuple keeps stop_channels first and main's router.aclose last. It
  also lets DisabledDelegator.list take #1108's active argument. This
  branch changes neither file.
- src/exo/gate.py merged on its own. #1089 adds a second reading of a
  call when a shell reads what printf or echo -e writes. This branch's
  te1: rule is its own branch of _classify_call for tool_output. It
  reads no shell line, so neither changes the other.
- src/exo/core/sessions.py merged on its own. #1102 makes a fork one
  transaction and pages the event read. This branch changes
  update_meta, in other lines. The store's lock is reentrant, so this
  branch's metadata callback can still read the store.
- src/exo/core/context.py merged on its own. #1106 reads each summary
  tree once per call. This branch changes one docstring there. Its
  EvidenceContext calls the wrapped context's build, and the tree does
  those reads inside its own build.
- src/exo/core/agents/delegate.py merged on its own. #1108 changes
  list. This branch changes how a child's context is made.
- DECISIONS.md, docs/DOCS-MAP.md, docs/DEVELOPER-GUIDE.md and
  CHANGELOG.md merged on their own.

User guide impact: none. Developer guide impact: none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDoXr7oqhY27xUfi67tUd5
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.

3 participants