# Changelog

## 1.2.4 (2026-03-31)

### Bug Fixes

- **Finalize guard ordering**: `_finalized` flag in `SimpleStreamingTracker.finalize()` is now set *after* event emission, so `finalize_on_abandon()` can retry if event construction fails.
- **Patch kwargs forwarding**: `PatchedOpenAI`, `PatchedAsyncOpenAI`, `PatchedAnthropic`, and `PatchedAzureOpenAI` now correctly forward all non-Amplitude kwargs (e.g. `base_url`, `headers`) to the underlying provider wrapper.
- **AsyncAzureOpenAI error message**: `wrap()` rejection message now accurately recommends sync `AzureOpenAI` with `wrap()` or `patch_azure_openai()` instead of incorrectly suggesting `patch()`.
- **Abandoned stream model resolution**: `finalize_on_abandon()` now prefers the response-resolved model name (captured from chunks) over the caller-supplied fallback, matching normal-path behavior.

## 1.2.3 (2026-03-31)

### Bug Fixes

- **P1 — Streaming `GeneratorExit` finalization**: All streaming generators (OpenAI, Anthropic, Gemini — sync and async) now use `finalize_on_abandon()` with an idempotent `finalize()`. If a consumer breaks early or closes the generator, tracking data is still emitted with `[Agent] Stream Abandoned = true`.
- **P2 — Gemini provider normalization**: `_normalize_provider_for_genai_prices("gemini")` now correctly returns `"google"`, enabling accurate cost calculation for Gemini models.
- **`wrap()` rejects `AsyncAzureOpenAI`**: `wrap()` now raises `AmplitudeAIWrapError` for `openai.AsyncAzureOpenAI` instances instead of silently misrouting them through the `AsyncOpenAI` path.

### Improvements

- **`SimpleStreamingTracker.finalize()` is idempotent**: Second and subsequent calls are silent no-ops, eliminating the risk of double-tracking.
- **`finalize_on_abandon()` helper**: New method on `SimpleStreamingTracker` encapsulates the abandoned-stream finalization pattern, reducing code duplication across all 6 streaming methods.
- **`[Agent] Stream Abandoned` event property**: When a streaming response is abandoned (consumer broke early or generator closed), the tracking event includes this property for analytics visibility.

## 1.2.2 (2026-03-30)

### Features

- **CLI `--print-guide` flag**: `amplitude-ai --print-guide` prints the full instrumentation guide to stdout.
- **Opinionated documentation**: README now recommends full-instrumentation golden path for both coding-agent and manual workflows.
- **Session lifecycle clarification**: Documented that `track_session_end()` is optional and that the server auto-closes sessions after 30 minutes of inactivity.
- **`tiktoken` made optional**: Token counting gracefully degrades when `tiktoken` is not installed.
- **`AsyncOpenAI` support**: Full async OpenAI client wrapper with streaming support.
