perf(sessions): clip task in the query, not after SELECT * (v0.292.4) - #535
Merged
Conversation
GET /api/sessions has always shipped `task` clipped to 240 chars, but the server still SELECT *'d every session's FULL prompt out of SQLite — up to 53 KB/row on instawp, 2.1 MB materialised per 1.5s poll — only for server.ts to throw it away. listSessions/listArchivedSessions now take an optional taskClip; the list endpoint passes LIST_CLIP and the SELECT projects substr(task,1,241) AS task (schema-derived column list), so SQLite stops materialising the overflow text. Measured on a live instawp snapshot (950 rows): task bytes 2.10 MB → 201 KB, raw query 5.23 → 3.53 ms (-33%), full listSessions(owner) 13.3 → 11.1 ms (-17%) per poll, plus ~1.9 MB less string allocation each tick. Output is byte-identical — clipText still runs as the ellipsis-preserving finisher on the ≤241-char string (verified across all 950 rows, 746 of them >240). Internal callers that read the whole prompt (sessionsForAgent, Cockpit context) pass no clip and keep the full SELECT *. Follow-on to #530/#532/#533; pagination (the structural fix) still open. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
vikasprogrammer
force-pushed
the
feat/sessions-substr
branch
from
August 3, 2026 07:52
3f02186 to
1354f39
Compare
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.
Problem
GET /api/sessionshas shippedtaskclipped toLIST_CLIP(240) since #525 — but the server stillSELECT *'d every session's full prompt out of SQLite first, only forserver.tsto clip it. On instawp that's up to 53 KB per row, 2.1 MB materialised per poll, every 1.5 s, per tab. #530/#532 killed the bytes on the wire and the client render; this cuts the server-side materialisation that #533 left as the remainingSELECT *cost.Change
listSessions/listArchivedSessionstake an optionaltaskClip. The list endpoint passesLIST_CLIP; the SELECT then projectssubstr(task,1,241) AS taskvia a schema-derived column list (PRAGMA table_info, cached), so SQLite stops materialising the overflow text. Internal callers that read the whole prompt (sessionsForAgent→ the session-detail "other runs" meta + search; the Cockpit workspace context) pass no clip and keep the fullSELECT *.clipTextin the handler is untouched — it now runs as the ellipsis-preserving finisher on the ≤241-char string, so the wire output is byte-identical to before.Measured (live instawp snapshot, 950 rows)
listSessions(owner)Plus ~1.9 MB less string allocation per 1.5 s tick.
Verification
taskoutput vs the oldSELECT *+clipTextpath across all 950 rows (746 of them >240 chars, all retain the ellipsis);substrhonoured (0 rows >241); column set unchanged.TerminalManager.listSessions(dist code) on the snapshot.npm run test:governance(18/18) green.Still open
Pagination —
/api/sessionsis still unbounded (~950 rows). That's the structural fix; this is the last easy win on the current shape.🤖 Generated with Claude Code