Issue #3615557: Record a streamed chat call once instead of twice

Closes #3615557 https://www.drupal.org/project/ai_metering/issues/3615557

AiPostGenerateSubscriber bound the same handler to both PostGenerateResponseEvent and PostStreamingResponseEvent, so a streamed call fired both and wrote two ai_metering_usage rows: one size-estimated (pre-consumption), one with the real final tokens (post-consumption). Skip the pre-consumption event for streamed output and let the streaming event be the sole source of truth.

An update hook merges historical duplicate rows, corrects quota already over-consumed against them, and re-rolls any month whose monthly rollup had already completed before the update ran, so past-month dashboards stop serving the doubled totals too.

AI assistance

Yes.

Merge request reports

Loading