Repository navigation
feat: mark ai chat writes in item history and meter chat turns - #292
stefan-ernst merged 7 commits into
Conversation
|
This PR has merge conflicts that need to be resolved before it can be merged. Please rebase on the latest |
|
Merge conflicts have been resolved. |
|
@valentimarco - thanks for the PR! I optimized the loading of the history tab to avoid a performance bottleneck on bigger instances. The merge conflict is also resolved. I will further test it but it looks good so far! |
|
This PR has merge conflicts that need to be resolved before it can be merged. Please rebase on the latest |
eee8354 to
f695c08
Compare
The item history read joined an aggregate of the entire llm_usage table on
every request. That subquery is not scoped to the item, so it scanned the
whole metering table regardless of which item was opened and degraded
linearly with usage volume (always on SQLite, and on Postgres once the
planner picks a hash plan over a merge join).
Keep the metered detail off the history response and fetch it per run:
- Drop model/cost_usd/total_tokens from ItemHistory and the runTelemetry
join; the history response is a single-table read carrying only source
and agent_run_id.
- Add Model to RunUsageTotals (MIN(model) over the run) so the existing
indexed /agent-runs/{run_id}/usage endpoint is the one source of
model/tokens/cost for both the history tooltip and the agent log.
- Fetch that endpoint lazily when the marker is hovered, scoped to the
newest 20 runs so a long history cannot fan out into a request per row.
A chat turn writes one aggregated llm_usage row, so TotalsForRun's COUNT(*) reported one call even when the agent loop made several provider round-trips; the broker's per-call rows reported the real count. Store the count on the row (defaulting to one for existing and per-call rows) and sum it, so the usage endpoint, chat response, and history tooltip agree on the number of calls behind a run.
f695c08 to
ae35695
Compare
|
Merge conflicts have been resolved. |
|
This PR has merge conflicts that need to be resolved before it can be merged. Please rebase on the latest |
|
heads up - I will merge it before 0.9.0 ships. Its just a bit busy on main so I will merge it once the helpdesk features are settled |
Resolve conflicts so AI provenance and the newer history actor attribution coexist: - item history carries actor_kind/actor_portal_customer_id alongside source/agent_run_id in the entry, insert, and read projection - keep main's full migration catalog and append the three history source/agent-run and llm_usage calls migrations - initialize the ItemHistory group with both actor and agent fields
|
Merge conflicts have been resolved. |
Resolve #282
I also added 2 commit related to the docker build
here the result in ui (AI Chat is the name of the tester)
