Skip to content

Fix Addie performance metrics SQL and data storage#617

Merged
bokelley merged 1 commit into
mainfrom
bokelley/addie-perf-storage
Jan 5, 2026
Merged

Fix Addie performance metrics SQL and data storage#617
bokelley merged 1 commit into
mainfrom
bokelley/addie-perf-storage

Conversation

@bokelley

@bokelley bokelley commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix PostgreSQL ROUND() function calls with FILTER clause by wrapping aggregate expressions in parentheses before casting to numeric
  • Add performance data (latency, tokens, timing) to reaction handler
  • Add error handling for reaction message logging
  • Add logging when streaming completes without done event
  • Change || to ?? (nullish coalescing) to preserve 0 values for tokens

Root Cause

The Performance tab in the Addie admin was showing an internal server error. The SQL queries were failing with:

function round(double precision, integer) does not exist

PostgreSQL's ROUND(value, precision) requires the first argument to be numeric, not double precision. The queries were using:

ROUND(AVG(latency_ms) FILTER (WHERE role = 'assistant')::numeric, 0)

But the ::numeric cast wasn't being applied correctly to the aggregate result - it was parsing ambiguously with the FILTER clause. The fix is to wrap the aggregate in parentheses:

ROUND((AVG(latency_ms) FILTER (WHERE role = 'assistant'))::numeric, 0)

Test plan

  • Verified SQL syntax works directly in PostgreSQL
  • TypeScript compiles without errors
  • All 179 unit tests pass
  • Verify Performance tab loads in production after deploy

🤖 Generated with Claude Code

- Fix PostgreSQL ROUND() function calls with FILTER clause by wrapping
  aggregate expressions in parentheses before casting to numeric
- Add performance data (latency, tokens, timing) to reaction handler
- Add error handling for reaction message logging
- Add logging when streaming completes without done event
- Change || to ?? (nullish coalescing) to preserve 0 values for tokens

The main bug was SQL queries failing with "function round(double precision,
integer) does not exist" because ROUND() requires numeric type, and the
::numeric cast wasn't being applied to the full aggregate expression.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bokelley bokelley merged commit 26c9198 into main Jan 5, 2026
6 checks passed
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.

1 participant