Skip to content

Early-accepted compactions do not return their usage #695

@ethanndickson

Description

@ethanndickson

When accepting a compaction early, the stream's usage is not returned:

// Get usage and duration metadata (usage may be undefined if aborted early)
const { usage, duration } = await this.getStreamMetadata(streamInfo);

This means all we're able to display to the user is the historical context usage & cost. We aren't able to increment it.

Before interrupted compaction:

Image

After interrupted compaction:

Image

The model becomes unknown too, as we don't create a usageHistory item with the model of the last message unless we know the usage of it:

if (msg.metadata?.usage) {
// Use the model from this specific message (not global)
const model = msg.metadata.model ?? fallbackModel ?? "unknown";
const usage = createDisplayUsage(msg.metadata.usage, model, msg.metadata.providerMetadata);
if (usage) {
usageHistory.push(usage);
}

export function createDisplayUsage(
usage: LanguageModelV2Usage | undefined,
model: string,
providerMetadata?: Record<string, unknown>
): ChatUsageDisplay | undefined {
if (!usage) return undefined;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions