Skip to content

bug: a refusal reply with null content throws in the parser and loses its token usage #82

Description

@JNK234

Problem

OpenAICompatibleProvider.parseProviderResponse reads message("content").str unconditionally. OpenAI's structured-output refusals return content: null with a refusal string and a full usage block. The parser throws before parseUsage runs, so the extension reports a parse failure and records neither the call nor its tokens, even though the provider billed them. Same shape can appear on any OpenAI-compatible provider.

Found by a Codex review on 2026-09-08. The parser assumption predates today's changes; the accounting consequence is new with #78.

Fix

Treat missing or null content as an empty string, carry the refusal text on the response (or surface it as the content with a clear marker), parse usage regardless, and let the calling primitive decide what to do with a refusal after recordUsage.

Test

A canned refusal body in UsageParsingSpec asserting usage is parsed, plus a tests.txt case asserting the call is counted.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions