Repository navigation
Costs: a filtered summary reads only the filtered visits' records - #79
Merged
Merged
Conversation
The totals, unpriced and billing CTEs aggregated every record the floor holds before the filter applied, so the cost of one run took seconds and grew with the floor's history. The filter now picks the visits first (scoped) and the record CTEs read only those visits by primary key.
|
Lore is reviewing this PR — ea22228e-f7cc-46c0-bed2-18c82f5df791. Submit a review that requests changes to have Lore push a fix for it. Comment |
There was a problem hiding this comment.
Lore review — Approved
Scopes CostsStore.summary record CTEs to the filtered visits first so GET /assembly-runs/{id} and filtered GET /costs queries read only matching visits' station_run_records.
Must fix (0) · Consider (0) · Nits (0)
Reviewed by gemini-4-argon
Submit a review that requests changes to have Lore push a fix for it. Comment @lore review to re-run the review.
Posted by floor, visit f1728f07-2274-45a1-9293-e408c22a3181.
This was referenced Nov 14, 2026
Merged
gedaiu
added a commit
to re-cinq/lore
that referenced
this pull request
Nov 14, 2026
…ecked in lore-api (#4617) First half of making the run page, the run list and the Loops board fast. Measured on production on 2026-11-14: a run page's transcript and inspector arrive 11 to 26 seconds after the click, because every browser read goes through a Next proxy that re-reads the whole run (cost included) only to learn its repo. A read that takes 0.1 s at lore-api takes 8.4 s through the proxy. This PR is the lore-api side and changes nothing a person sees yet. The web UI moves onto it in a second PR, once this one is deployed and checked. **What lore-api gains** - The live socket (`/api/ws`) reads the `lore_session` cookie at the upgrade and knows the person. A cookie socket from any origin but the UI's is refused with 403. - A `request` / `response` message pair: the browser asks for a route by method and path and lore-api runs it in-process as that person, so the route's own bearer check, scope, validation and rate limit apply. `/api/auth/`, `/api/webhook`, `/api/ws` and any path that leaves `/api/` are answered 404. - `run` and `runs` channels open without a minted token for a person who may read the run's repository. - Run routes (`/api/assembly-runs/{id}/…` and the older `/api/assembly-lines/{id}/…`) refuse a person whose session does not list the run's repository. This is the check the Next proxy made, and the follow-up ADR-053 named. - `GET /api/assembly-runs/{id}/pull-files`: a run's changed files by run id, so the browser never names a repo and pull request itself. - Cancel and run-node take the person from the session, not from the body. - One floor read serves a burst: `floor.runs.get` is shared for 3 seconds, so a page's run, nodes and upgrade reads make one floor request. - The Loops board's GitHub reads answer the kept value at once for up to 10 minutes while one refresh runs in the background. Cold, they held the board for 4 to 6 seconds. - A new ingress entry routes `lore.gcp.re-cinq.com/api/ws` to lore-api. Nothing uses it until the second PR points `LORE_WS_URL` there. **Left out on purpose** - Repo checks on lore-api routes other than the run routes. Over the socket a person can ask for any route, exactly as their token already can over HTTP. - Session tokens still carry the `admin` scope (ADR-053). - The token-based channel opens stay, for tabs loaded before the second PR. **To check after deploy** - TLS on `lore.gcp.re-cinq.com`: the new ingress is in the `lore-api` namespace, so cert-manager issues a second certificate for the same host. Related: re-cinq/floor#79 (the cost query that made a single run read slow, released as floor v0.5.2). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gedaiu
added a commit
to re-cinq/lore
that referenced
this pull request
Nov 14, 2026
#4622) Second half of the run page speed work; #4617 was the lore-api side and is deployed. The browser's reads on the run page, the run list and the Loops board's live follower now go over the tab's one live socket straight to lore-api, as the signed-in person. Before, each read went through a Next proxy route that re-read the whole run first to check access, which turned a 0.1 s read into 8 s when the page fired four at once. **What changes** - The socket client gains `request(method, path, body)`: it sends a `request`, resolves on the matching `response`, waits for the connection when it is not up, sends a pending GET again after a reconnect, rejects any other method on a drop, and times out after 30 s. - `liveFetch(path)` wraps that as a `Response`, so callers changed one line. A 401 sends the person to sign in. - Every browser caller of `/api/assembly-runs/…` uses it: events, transcript, bag, definition of done, visit events and model calls, blob previews, node logs, the diff drawer, and the cancel, run-node and upgrade buttons. - `run` and `runs` channels open on the person's session. The server actions that minted their tokens are gone (the run one took 11 s). - The run list loads its next page over the socket. - The run page starts its run, nodes and upgrade reads together. - `LORE_WS_URL` is the UI's own host, so the session cookie rides the upgrade. The ingress entry for it shipped in #4617. **Deleted** - The 12 Next routes under `app/api/assembly-runs/[id]/` and their tests, and the helpers only they used. **Behaviour to know** - With no live socket configured, the run page shows its server-rendered graph marked Offline and reads no history: there is no HTTP fallback any more. The fallback that polled history after the socket gave up now asks over the socket too, which wakes it again. - Callers see lore-api's real 401 and 403; the proxy used to turn both into 502. **Left out on purpose** - The other 13 Next proxy routes, the plan page (its channels keep their minted tokens) and every server-rendered page. Related: #4617, re-cinq/floor#79 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
GET /assembly-runs/{id}took 2 to 7 seconds because the cost summary aggregated everyllm_callrecord on the floor before filtering to the one run. Every reader of a single run paid it, and Lore's run page asks for a run about ten times per load.The summary now builds a
scopedCTE first (the visits the filter keeps) and thetotals,unpricedandbillingCTEs read only those visits' records, through the table's primary key. Results are unchanged: the 18 existing cost tests pass untouched, plus one new test with two runs.Measured on a seeded database (150 runs, 6,000 records), one run's summary:
station_run_recordsaccessThe
/metricsrollups (costSeries,missingCostByLine) are unfiltered by design and their SQL is unchanged.Closes #52
Related: re-cinq/lore run page speed work
🤖 Generated with Claude Code