Skip to content

fix: serve/web runs never persist turn metrics or context estimates#837

Closed
sam-saffron-jarvis wants to merge 1 commit into
SamSaffron:mainfrom
sam-saffron-jarvis:feat/codereview-e8d0aa8d
Closed

fix: serve/web runs never persist turn metrics or context estimates#837
sam-saffron-jarvis wants to merge 1 commit into
SamSaffron:mainfrom
sam-saffron-jarvis:feat/codereview-e8d0aa8d

Conversation

@sam-saffron-jarvis

Copy link
Copy Markdown
Contributor

What changed

  • Updated cmd/serve_runtime.go so the existing SetTurnCompletedCallback now persists per-turn metrics for serve/web runs via store.UpdateMetrics(...).
  • Persisted the engine context-estimate baseline on normal turn completion via store.UpdateContextEstimate(...), matching the existing CLI/TUI/Telegram behavior.
  • Updated the in-memory sessionMeta counters and persisted context estimate when those writes succeed so active serve sessions stay consistent with stored session state.
  • Added a regression test in cmd/serve_runtime_test.go that exercises a multi-turn tool run and verifies both metrics and context estimates are persisted.

Why this is high-value

Serve/web sessions were successfully appending transcript rows but silently leaving session accounting stale on normal completion. That meant:

  • llm_turns, tool_calls, and token totals could stay zero or outdated
  • last_total_tokens / last_message_count were not saved for resumed web sessions
  • user-visible stats and any usage/cost reporting based on session rows became incorrect
  • resumed sessions could start with a bad context estimate even though other surfaces already persisted it correctly

This fix is small, targeted, and aligns serve/web with already-shipped persistence behavior in ask/TUI/Telegram.

Validation

  • Added regression test: go test ./cmd -run TestServeRuntimeRunPersistsTurnMetricsAndContextEstimate -count=1
  • Ran gofmt -w cmd/serve_runtime.go cmd/serve_runtime_test.go
  • Ran go build ./...
  • Ran go test ./...
  • Ran git diff --stat and git diff --check

@SamSaffron SamSaffron closed this Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants