mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-09 16:59:43 +02:00
perf(capture): a grid tile's full capture reads no more history than it keeps
GET /api/sessions/:id/terminal?full=1 captured the whole tmux history (capture-pane -S -<history limit>, 100,000 lines by default) and cut it to `tail` only afterwards, all of it synchronous on the server's event loop. A grid tile keeps TILE_SCROLLBACK lines plus its screen, so the rest was captured to be thrown away, once per tile on every grid open, restore and deploy reconnect. The route now takes an optional `lines=<n>` (an integer of at least 1, clamped to the configured history limit) and passes it as the capture's history bound (the existing historyLimitLines, so -S -<n>); absent or malformed, the limit itself, so every existing caller gets the same capture as before. Only full captures read it: the visible-frame path (a shell tile's `tail=` load) reads no history and is untouched. The capture still ends with its RELATIVE cursor move back to the caret, still counts as a full capture (isFullCapture: the line-deleting transforms stay off) and still reports captureCols/captureRows. Grid tiles (boundedLoad) send lines=<scrollback + rows> on every full capture of theirs: a TUI load and a shell history pull. The split's Pane B asks for everything, as before. Measured: - A real haiku Claude pane on tileperf (about 3k lines of history): bounded captures (lines=50, 500, 2000, 100000) against the unbounded one, 4 PASS 0 FAIL: each a line-aligned suffix of it, ending in the same relative cursor move (ESC[4A CR ESC[2C), same source (mux-full-history) and capture geometry. Capture time there 72 ms both ways, that history being shorter than the tile's bound. As a grid tile (it sent lines=10047) its screen matched the pane row for row, 47 of 47 at the pane's own 77x47, caret on the composer. - Six tiles restoring with Claude-style loads (full=1&tail=1MiB forced on shells with about 19k lines of tmux history each, above the tile's bound; n=3+3 interleaved, load 4.2 to 7.2): capture per tile med 219 ms [194 to 294] -> 155 ms [127 to 211]; server event-loop delay in the capture window, max med 262 -> 201 ms; all painted 4.5 -> 3.6 s. At checkpoint 1 a 30k-line history cost 713 ms per capture (event loop blocked up to 765 ms each); the bound caps that at the tile's size. Tests: the route passes lines= through, clamps it, ignores every malformed form and leaves the visible-frame capture exactly as it was; a bounded capture keeps its rows and ends in the cursor restore; grid tiles send it on full captures and the split's Pane B does not. Mutation-checked six ways (lines ignored, no clamp, a lenient parse, lines on the visible path, the tile sending none, Pane B sending it). Documented in docs/api-reference.md (/api/v1 is public). Scope: PR 2 (the grid's loads; server route plus terminal-tile.js). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -445,6 +445,20 @@ count against the same 16, not 16 of each. An abandoned request no longer holds
|
||||
slot, because the routes release the waiter when the client disconnects, but a
|
||||
client that opens many concurrent waits against one session will still hit the cap.
|
||||
|
||||
## Terminal capture (`GET /api/v1/sessions/:id/terminal`)
|
||||
|
||||
What a session's terminal shows, for a client to replay: `data.terminalBuffer`,
|
||||
with `source` (`mux-visible`, `mux-full-history` or `history`), `truncated`,
|
||||
`truncationReason`, `fullSize`, and `captureCols`/`captureRows` when the pane's
|
||||
geometry was read. The capture runs synchronous tmux calls on the server; the
|
||||
`Server-Timing` header reports `capture`, `prepare` and `total`.
|
||||
|
||||
| Query | Meaning |
|
||||
|---|---|
|
||||
| `full=1` | tmux's scrollback, not only the visible frame (`source: 'mux-full-history'`), ending with a relative cursor move back to the pane's caret. |
|
||||
| `tail=<bytes>` | Keep the newest `<bytes>` of the result (`truncationReason: 'tail'` when it cut). |
|
||||
| `lines=<n>` | With `full=1` only: read at most `<n>` lines of tmux history above the visible frame. An integer of at least 1, clamped to the configured history limit; absent or malformed, the whole limit (100,000 lines by default), as before. `truncated` and `truncationReason` describe byte cuts only, not this bound. Without it a full capture reads all of that history before `tail` cuts it, so a client that keeps a fixed number of lines (the tile grid sends its xterm's scrollback plus its rows) should send it. |
|
||||
|
||||
## Session lineage (`parentSessionId`)
|
||||
|
||||
A create request may name the session that spawned it, which the web UI draws as a
|
||||
|
||||
Reference in New Issue
Block a user