Repository navigation
Conversation
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummarySpeeds up OpenCode’s first-reply lookup without changing which reply each prompt counts toward.
Reviews (3) · Last reviewed commit: "Seek to the reply a prompt books, instea..." · Reviewed by Greptile |
|
I read the diff, the surrounding OpenCode scanner, and the base branch’s contributor rules at GPT-6 in Codex (reasoning effort not exposed) was the only model to review the code in this session. No code-review second opinion or tests ran, and the unused disposable worker was destroyed. No code or labels changed. Verification is waiting on classification; this is an incomplete review, with no defect established. |
|
GPT-6 in Codex (effort not exposed) checked this head on a disposable ISO worker. A separate reproduction exercised both The CLI suite and all 44 agent-usage test files passed. Across the full run and retries with the worker's installed mise tools and UTF-8 locale, the 437-file shell suite completed without remaining failures; six files retained skipped hardware, optional-tool, locale or translation checks. Opus 5.5 High and muse-wonder via pi (thinking high) found no current correctness defect and agreed with the query analysis; independence is not guaranteed. No code changes were needed. Verification is recorded, but GitHub's |
The scan pairs each typed prompt with the first reply after it. Its condition was an OR over the ordering column, which SQLite cannot turn into an index range: the search stayed constrained by session_id alone, so every prompt read forward through all the rows left in its session. Booking was therefore quadratic in the session's length, and every collector that reads opencode's store paid it again on each refresh. Adding the lower bound the OR already implies lets the index seek from the prompt's own position. The pairs booked are unchanged; only the work to find them changes. On a 3.3 GB opencode.db whose largest session holds 51,560 rows, the query drops from 159 s to 1.1 s, and a full usage refresh from minutes on every core to about ten seconds. Rebased onto the agents-panel rework: the booking query now lives at its relocated site in scan_opencode, and the regression test now lives in the shared collector suite, where the per-agent scanner tests consolidated. It counts SQLite VM work through set_progress_handler: 100k steps with the seek, 18.1M with the walk.
ab59a44 to
6e57f87
Compare
|
GPT-6 in Codex (effort not exposed) checked the rebased head The CLI suite passed. Of 255 shell test files, 254 completed without failures, including the shared collector and provider-partition tests; three files retained locale, translation or battery-dependent skips. Opus 5.5 High and muse-wonder via pi (thinking high) found no actionable query or regression-test defect and agreed with the analysis; independence is not guaranteed. No code changes were needed, and the worker was destroyed. Verification of the query is recorded. The remaining blockers are the full-suite failure and maintainer approval for GitHub’s |
What changes
Rebased onto the agents-panel rework.
scan_opencodepairs each typed prompt with the first reply after it. Itscondition was an
ORover the ordering column, and SQLite can't turn thatinto an index range:
Only
session_idis constrained, so each prompt read forward through everyremaining row of its session, and booking was quadratic in the session's
length.
Long sessions are ordinary. The
opencode.dbthis was found on is 3.3 GB,and its largest session holds 51,560 rows (5,884 prompts, 45,373 replies)
of a 1.2 GB
session_messagetable. About a dozen collectors read that storeon each refresh, so one Agents panel refresh pinned twelve cores for minutes
and left 35 processes behind.
Adding the lower bound the
ORalready implies lets the index seek from theprompt's own position:
for session_id, reply_id, created_at, typed_at in conn.execute( "SELECT u.session_id, (SELECT a.id FROM session_message a WHERE a.session_id = u.session_id AND a.type = 'assistant'" + f" AND a.{order} >= u.{order}" f" AND (a.{order} > u.{order} OR (a.{order} = u.{order} AND a.id > u.id)) ORDER BY a.{order}, a.id LIMIT 1),"The pairs booked are unchanged — only the work to find them changes.
Verification
On that 3.3 GB database:
omarchy agent usage-update --forceThe reorg (#19904) moved the per-agent scanner tests into the shared
collector suite, so the regression test lives in
agent-usage-shared-test.sh, where the opencode tests already do. It buildsa 1500-prompt session with opencode's own index on
(session_id, seq), andcounts the SQLite VM work through
set_progress_handler, so the check doesn'tdepend on machine speed:
It fails on the old query (18.1M steps) and passes on the new one (100k steps,
threshold 1M). The shared, partition, update, and agents-panel tests all pass.
Screenshots
No visible change: the panel renders the same records, only the scan behind
them is faster.