Repository navigation
feat(serve): paginated transcript read GET /sessions/{id}/entries - #544
Merged
Merged
Conversation
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
2 of 3 tasks
ajianaz
added a commit
that referenced
this pull request
Nov 10, 2026
) ## What Second of three parts of #524 (UI epic #523): `POST /sessions {"resume": "<id>"}` on `tole serve` reopens an existing session, so a UI client can pick a session up again after a serve restart (the live map is in memory; the JSONL is what survives). Part 1 (`GET /sessions/{id}/entries`) is merged (#544). Part 3 (SSE events) follows. Refs #524, does not close it. ## Why `POST /sessions` only creates, and `GET /sessions` lists only live sessions, so a client cannot reopen history it can now read. The request shape was agreed with the owner on 2026-11-10. ## Changes - `serve.rs`: `resume_session` + `open_serve_session`. Create and resume now share the approver, `open_session` and admission code (extracted from the create path; behavior of creating a session is unchanged, covered by the existing tests). - The id is validated (`is_valid_session_id`) and only joined into the session directory (`--sessions-dir`, else `<cwd>/.tole/sessions`); the client never supplies a path. `cwd` goes through the same jail-of-jails check as a new session (`403` outside it), and a session is found only under the workspace it was created in (`404` otherwise). - **Already live**: `200 {"resumed": false, "alreadyLive": true, "busy": <bool>}`. It is checked first and nothing is reopened or replaced: the writer lock is held by this very process (a second open would be refused as locked), and a running turn must not be disturbed. A client that reconnects mid-turn gets its id and the `busy` flag. - `404` no such file; `400` bad id or a non-string `resume`; `409` another process (a TUI, a second serve) holds the session's writer lock; `503` at the live-session cap with every session busy (unchanged rule). - A resumed session uses the same `QueueApprover`: non-preauthorized Writes queue for a remote decision exactly as for a new session. Resuming grants no authority; the token is the same. - Docs in the same PR (AGENTS.md §7): README status line, `docs/mobile-control.md` (route table and a Resume by id section, and the "not readable until resumed" note from part 1), `docs/epics.md`, `docs/daemon-design.md`, CHANGELOG, `serve.rs` header. ## Testing - [x] `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo check -p tole-cli --no-default-features`, `cargo test --workspace` (1163 passed) - [ ] Local `cora review --staged`: not run (cora is not installed in this environment); the CI Cora Review job is the verdict. - [x] 3 new e2e tests against the real `tole serve` binary (same file and harness as the transcript tests): - a session is gone from a restarted serve (`GET …/entries` is a 404), `resume` brings it back with its full history, a new prompt extends the same log; - resuming a live session is a no-op even mid-turn (`alreadyLive`, `busy: true`), and the 2.5 s turn still completes normally; - refusals: `../etc/passwd`, empty and non-string ids (400), an unknown id (404), `cwd: "/"` (403), a jailed sibling directory (404 for a session that is not live), and a second serve process over the same workspace while the first holds the lock (409, nothing opened), then 200 once the holder is gone. - Mutation: skipping the live-session check makes the live-session test fail. ## Limits - Resume does not replay an unfinished turn by itself: a session that was mid-turn when the server died resumes into whatever state its log holds, and the client continues with a prompt (the existing resume rules apply). - A live session ignores a mismatching `cwd` in the request (it is already open under its own workspace). ## Related Issues Refs #524, part of #523. --- _Generated by [Claude Code](https://claude.ai/code/session_01GwJr9GzLbDFeXo3HZHZpyP)_ Co-authored-by: Claude <[email protected]>
3 of 4 tasks
ajianaz
added a commit
that referenced
this pull request
Nov 10, 2026
## What Third and last part of #524 (UI epic #523): `GET /sessions/{id}/events?after=<seq>`, a Server-Sent Events stream so a graphical client can show a session live. Parts 1 and 2 (transcript read #544, resume-by-id #545) are merged. This completes #524. Closes #524. ## Why `POST /sessions/{id}/prompt` blocks until the turn ends, so a UI could not show streamed text, tool cards or approval requests as they happen. Design choices were agreed with the owner on 2026-11-10: SSE, durable frames from the log plus best-effort ephemeral frames, and a separate cap of 8 streams. ## Changes - `crates/tole-cli/src/events.rs` (new, lib), pure and unit-tested: - SSE framing; **durable** `entry` frames use the entry's `seq` as the SSE `id` (so `Last-Event-ID` and `?after=` replay losslessly), **ephemeral** frames carry no id so a reconnect can never skip a real entry. - `Bus` / `BusRegistry` / `BusObserver`: fan-out of a turn's `TurnObserver` callbacks (`text_delta`, `reasoning`, `tool_started`, `tool_finished`) to open streams through a **bounded, non-blocking** queue per stream; a full queue drops the frame, counts it and the stream says `resync`. A slow client can never slow a turn. - `EntryTail`: follows the session file by `seq` (one `stat` while unchanged; a read-only replay when it changed, a torn tail is skipped, never truncated), so it works while a turn holds the live storage lock. Writes that land between the stat and the replay are picked up next poll, never missed (seq filters duplicates). - `ApprovalWatch`: `approval_requested` / `approval_resolved` frames from the existing approvals queue (a late joiner sees what is pending; old decisions are not replayed). - `StreamLimiter`: at most 8 open streams (`429` beyond that), freed on drop. - `Heartbeat`: a pure clock that is only reset by a real write (injected time, unit-tested); `TOLE_SERVE_HEARTBEAT_SECS` (1 to 3600, default 15) overrides the interval, e.g. behind a proxy with a short idle timeout. - `serve.rs`: `Last-Event-ID` is parsed; the stream is served before normal routing and owns its connection (`ready` marks the end of the replay, then durable entries, approvals and ephemeral frames, a heartbeat comment after 15 s without a write, and `closed` when the session leaves the live map). Streams count within the 32-connection cap but cannot starve `/approvals` and `/prompt`. Approval frames go out before the durable entries of the same pass, so a decision is announced ahead of its effects. - The prompt route attaches an observer **only while a stream is open on that session**. Attaching an observer turns on provider streaming, so with nobody watching a turn runs exactly as before streams existed (zero change for existing REST users). Consequence, documented: a stream opened mid-turn gets durable entries but no text deltas for that turn. - Tests: the serve process, provider mock and a small SSE client moved into a shared `tests/serve_harness` (the entries/resume tests from #544/#545 use it too). - Docs in the same PR (AGENTS.md §7): README status line, `docs/mobile-control.md` (route table and an Event stream section with the frame table, replay semantics, limits and the browser `EventSource` caveat), `docs/epics.md`, `docs/daemon-design.md`, `docs/threat-model.md` (new Event streams section), CHANGELOG, `serve.rs` header. ## Not included (stated, not hidden) - An observer for the turn that resumes after an approval `allow`: that path (`resume_turn_with_cancel`) has no observer variant in `tole-core`, so adding one is a core change beyond this issue. Its entries (the final answer) still arrive as durable frames; only live text/tool frames are missing for it. - A stream token for browser `EventSource` (cannot send `Authorization`): left to the web client (#529). - A log index: each change replays the session file, so a very large session costs more per change. ## Testing - [x] `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo check -p tole-cli --no-default-features`, `cargo test --workspace` (1178 passed) - [ ] Local `cora review --staged`: not run (cora is not installed in this environment); the CI Cora Review job is the verdict. - [x] 10 unit tests (`events`): frame format and escaping, ephemeral shapes, bus fan-out/drop counting/unsubscribe, observer only while watched, limiter, approval diff (late joiner, resolve, expiry, decided-between-polls), tail (each entry once, torn tail, unchanged = no replay, start after a seq), the heartbeat clock (only a real write resets it) and its interval parsing. - [x] 5 e2e tests against the real `tole serve` binary: replay then follow a live turn (entries equal the stored log, ids are seqs, ordered, no duplicates, a `text_delta` arrives, the prompt answer is unchanged); reconnect with `Last-Event-ID` and with `?after=` gets exactly the entries it missed, no stray frames, `after` beats a stale header; 401/404/400 and the cap (8 open, the 9th is 429, `/sessions` and `/approvals` still answer); approval flow (`approval_requested`, allow, `approval_resolved` before the resumed turn's answer, the work executed); an idle stream heartbeats (interval set to 1 s). - Mutations, each caught: no observer attached (live-turn test), `seq >=` in the tail (duplicates: e2e + unit), cap off by one (e2e + unit), an empty approvals pass resetting the heartbeat clock (the bug Cora found: heartbeat e2e times out). ## Related Issues Closes #524, part of #523. Follow-ups in the epic: #525, #526. --- _Generated by [Claude Code](https://claude.ai/code/session_01GwJr9GzLbDFeXo3HZHZpyP)_ --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
First of three parts of #524 (UI epic #523):
GET /sessions/{id}/entries?after=<seq>&limit=<n>ontole serve, a paginated transcript read so a graphical client that connects late or reconnects can render history. The other two parts (resume-by-id, SSE event stream) are separate PRs. Refs #524, does not close it.Why
A UI client has no way to read a session's history today.
GET /sessions/{id}/statusonly returns counts. This is the lowest-risk piece of #524 (read-only, additive) and gives clients history now. The split (entries, then resume, then SSE) and the open design choices (resume shapePOST /sessions {"resume": "<id>"}, serde structs without a schema dependency yet, a separate stream cap of 8 for SSE) were agreed with the owner on 2026-11-10.Changes
crates/tole-cli/src/protocol.rs(new, lib): the wire types.EntriesPage {id, entries, nextAfter, hasMore, lastSeq}(camelCase), query parsing (afterdefault 0,limitdefault 100, clamped to 500, junk is a 400) andentries_page. Entries are exactly the log'sEntryvalues, so a client sees whattole resumereplays; nothing is reformatted.JsonlStorage::open_read_only(a torn tail is skipped and never truncated), not the live storage handle: a running turn holds that lock for its whole duration, and the transcript has to stay readable meanwhile.SessionStategains the filepathfor this.hasMorecan therefore be true with fewer thanlimitentries.serve.rs: splits the query string off the path before matching the session action (entries?after=5is theentriesaction); the existing status route is unchanged (tested). Auth is the existing bearer token.docs/mobile-control.md(route table and a Transcript read section),docs/daemon-design.md(owner un-parked the serve-face part, the socket daemon stays parked),docs/epics.md, CHANGELOG,serve.rsheader.Limits (stated, not hidden)
seqis not dense, so clients must page withnextAfter.mobile-control.md.Testing
cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo check -p tole-cli --no-default-features,cargo test --workspace(1160 passed)cora review --staged: not run (cora is not installed in this environment); the CI Cora Review job is the verdict.tole servebinary with a mock provider: paging two at a time equals the replayed JSONL (andstatusstill works); 401 without the token, 404 unknown session, 400 forafter=x,after=-1,limit=0,limit=many, and an over-ceilinglimitclamps; the transcript is readable in under 1.5 s while a 3 s turn is in flight.seq <= aftertoseq < afterfails 3 unit tests.Related Issues
Refs #524, part of #523.
Generated by Claude Code