Skip to content

Add provider retries and request metadata - #24

Merged
rafaeelricco merged 5 commits into
mainfrom
adding-retry-and-request-meta
May 9, 2026
Merged

Add provider retries and request metadata#24
rafaeelricco merged 5 commits into
mainfrom
adding-retry-and-request-meta

Conversation

@rafaeelricco

Copy link
Copy Markdown
Owner

Motivation

Add retry handling and richer request metadata after commit message generation.

What's New

LLM Request Metadata

  • GeneratedContent wraps generated text with LlmRequestMetadata for model, effort, duration, and token usage.
  • Provider adapters return ProviderGeneratedContent so the router can attach shared request metadata.
  • OpenAI, Gemini, and Anthropic token usage maps into a shared TokenUsage shape with optional counts.

Provider Reliability

  • OpenAI and Anthropic clients use SDK-native maxRetries: 3 and timeout: 120_000.
  • Gemini API-key calls use SDK retry options and timeout through httpOptions.
  • Gemini OAuth calls switch from streamed SSE parsing to generateContent JSON parsing for metadata support.

Commit And Push Notes

  • Commit-only flow renders a Committed note with commit metadata and LLM request metadata.
  • Commit-and-push flow carries request metadata through upstream, publish, and force-with-lease paths.
  • Push notes show model, effort, request duration, and token counts when the provider returns usage data.

Testing & Feedback

  • Verified pnpm run typecheck.
  • Verified pnpm run lint:ci.
  • Review provider auth paths for OpenAI, Gemini, and Anthropic.
  • Review commit-only and commit-and-push note rendering with and without token metadata.
  • Review Gemini OAuth response parsing against the REST generateContent payload.

If you find any bugs or have recommendations for improvements, please open an issue and assign it to me.

- Introduce `GeneratedContent`, `LlmRequestMetadata`, `TokenUsage`, and `ProviderGeneratedContent` types to expose request duration and token usage.
- Add `withRequestMetadata` helper to wrap provider responses with timing information.
- Update `generateContent`, `generateCommitMessage`, and `refineCommitMessage` to return `GeneratedContent` instead of plain strings.
- Thread `GeneratedContent` through the commit/refine/interact flow so model, duration, and token usage are preserved end-to-end.
- Extend `LlmRequestMetadata` with `ModelRequestMetadata` capturing provider, model, and effort.
- Capture token usage from Anthropic, Gemini, and OpenAI provider responses and return `ProviderGeneratedContent`.
- Add `renderCommitNote` and extend `renderPushNote` to show model, request duration, and token counts.
- Introduce `withTransientRetry` helper in `src/infra/llm/retry.ts` and apply it to Anthropic API key and setup-token calls.
- Configure Anthropic client with `maxRetries: 3` and a 120s timeout, and wrap errors with `cause` for retry classification.
- Delete `src/infra/llm/retry.ts` and drop `withTransientRetry` wrappers from both Anthropic auth paths.
- Add `maxRetries: 3` and 120s timeout to OpenAI clients for API key and OAuth flows.
- Configure Gemini `GoogleGenAI` with 120s timeout and 3 retry attempts via `httpOptions`.
- Switch Gemini API key path from streamed iteration to a single `generateContent` call.
- Switch Gemini OAuth path from `:streamGenerateContent?alt=sse` to `:generateContent` and parse the JSON response directly.
- Replace `extractSSEEvent` and `accumulateSSEContent` with `parseOAuthResponse`, and share mapping via new `extractGeminiText` and `toGeneratedContent` helpers.
@rafaeelricco rafaeelricco self-assigned this May 9, 2026
- Replace global `npm install -g pnpm` with `corepack enable` in PR validation workflow.
- Use `pnpm install --frozen-lockfile` in CI to ensure reproducible installs.
- Pin `packageManager` to `pnpm@10.33.0` in `package.json`.
- Add `pnpm-workspace.yaml` defining the root package and allowing builds for `esbuild` and `protobufjs`.
@rafaeelricco
rafaeelricco merged commit 379bc9d into main May 9, 2026
4 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