Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/rovo-dev/analytics/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ export namespace Track {
};

// TODO: rovodev metadata fields here are different from other events, reconcile later?
export type PromptWarningReason = 'rate_limit';

export type PromptWarning = {
action: 'rovoDevPromptWarning';
subject: 'atlascode';
attributes: {
rovoDevEnv: RovoDevEnv;
appInstanceId: string;
sessionId: string;
promptId: string;
reason: PromptWarningReason;
title?: string;
};
};

export type PerformanceEvent = {
action: 'performanceEvent';
subject: 'atlascode';
Expand Down Expand Up @@ -285,4 +300,5 @@ export type TrackEvent =
| Track.ReplayCompleted
| Track.PerformanceEvent
| Track.LocalServerPromptReceived
| Track.PromptCompleted;
| Track.PromptCompleted
| Track.PromptWarning;
68 changes: 68 additions & 0 deletions src/rovo-dev/rovoDevChatProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1260,4 +1260,72 @@ describe('RovoDevChatProvider', () => {
});
});
});

describe('rovoDevPromptWarning (rate limit)', () => {
beforeEach(() => {
chatProvider = new RovoDevChatProvider(true, mockTelemetryProvider);
chatProvider.setWebview(mockWebview);
chatProvider['_currentPromptId'] = 'prompt-A';
mockTelemetryProvider.fireTelemetryEvent.mockClear();
});

it('detects rate-limit warnings by title or message (case-insensitive)', () => {
expect(chatProvider['isRateLimitWarning']({ title: 'Rate limit exceeded' })).toBe(true);
expect(chatProvider['isRateLimitWarning']({ message: "We've hit a RATE LIMIT" })).toBe(true);
expect(chatProvider['isRateLimitWarning']({ title: 'Heads up', message: 'Model switched' })).toBe(false);
expect(chatProvider['isRateLimitWarning']({ title: 'current rate', message: 'limit hit' })).toBe(false);
expect(chatProvider['isRateLimitWarning']({})).toBe(false);
});

it('emits reason=rate_limit (with title), can fire repeatedly, and omits absent title', () => {
chatProvider['firePromptWarning']('rate_limit', 'Rate limit exceeded');
expect(mockTelemetryProvider.fireTelemetryEvent).toHaveBeenCalledWith({
action: 'rovoDevPromptWarning',
subject: 'atlascode',
attributes: { promptId: 'prompt-A', reason: 'rate_limit', title: 'Rate limit exceeded' },
});

chatProvider['firePromptWarning']('rate_limit');
expect(mockTelemetryProvider.fireTelemetryEvent).toHaveBeenCalledTimes(2);
expect(mockTelemetryProvider.fireTelemetryEvent.mock.calls[1][0].attributes).toEqual({
promptId: 'prompt-A',
reason: 'rate_limit',
});
});

it('does not emit outside Boysenberry mode or without a current promptId', () => {
const ideProvider = new RovoDevChatProvider(false, mockTelemetryProvider);
ideProvider['_currentPromptId'] = 'prompt-ide';
ideProvider['firePromptWarning']('rate_limit', 'Rate limit exceeded');

chatProvider['_currentPromptId'] = '';
chatProvider['firePromptWarning']('rate_limit', 'Rate limit exceeded');

expect(mockTelemetryProvider.fireTelemetryEvent).not.toHaveBeenCalled();
});

it('fires only for rate-limit chat warnings, never for other warnings or replay', async () => {
await chatProvider['processRovoDevResponse']('chat', {
event_kind: 'warning',
message: 'Some models are slow',
title: 'Heads up',
} as any);
await chatProvider['processRovoDevResponse']('replay', {
event_kind: 'warning',
message: "We'll try again in 10 seconds.",
title: 'Rate limit exceeded',
} as any);
expect(mockTelemetryProvider.fireTelemetryEvent).not.toHaveBeenCalled();

await chatProvider['processRovoDevResponse']('chat', {
event_kind: 'warning',
message: "We'll try again in 10 seconds.",
title: 'Rate limit exceeded',
} as any);
expect(mockTelemetryProvider.fireTelemetryEvent).toHaveBeenCalledTimes(1);
const call = mockTelemetryProvider.fireTelemetryEvent.mock.calls[0][0];
expect(call.action).toBe('rovoDevPromptWarning');
expect((call.attributes as { reason?: string }).reason).toBe('rate_limit');
});
});
});
32 changes: 32 additions & 0 deletions src/rovo-dev/rovoDevChatProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,10 @@ export class RovoDevChatProvider {
}

case 'warning': {
if (sourceApi !== 'replay' && this.isRateLimitWarning(response)) {
this.firePromptWarning('rate_limit', response.title);
}

const { text, link } = this.parseExceptionMessage(response.message);
await webview.postMessage({
type: RovoDevProviderMessageType.ShowDialog,
Expand Down Expand Up @@ -1201,6 +1205,34 @@ export class RovoDevChatProvider {
});
}

private isRateLimitWarning(response: { title?: string; message?: string }): boolean {
return (
!!response.title?.toLowerCase().includes('rate limit') ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Maintainability - Best Practices

Consider extracting the string 'rate limit' into a constant to avoid magic strings and improve maintainability.

Details

📖 Explanation: Using a named constant makes the code more maintainable and reduces the risk of typos when the same string is used in multiple places.

Uses AI. Verify results. Give Feedback

!!response.message?.toLowerCase().includes('rate limit')
);
}

private firePromptWarning(reason: Track.PromptWarningReason, title?: string): void {
if (!this._isBoysenberry) {
return;
}

const promptId = this._currentPromptId;
if (!promptId) {
return;
}

this._telemetryProvider.fireTelemetryEvent({
action: 'rovoDevPromptWarning',
subject: 'atlascode',
attributes: {
promptId,
reason,
...(title !== undefined ? { title } : {}),
},
});
}

private async processError(
error: Error,
{
Expand Down
4 changes: 3 additions & 1 deletion src/rovo-dev/rovoDevTelemetryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export type TelemetryEvent =
| PartialEvent<Track.DeleteSessionClicked>
| PartialEvent<Track.ReplayCompleted>
| PartialEvent<Track.LocalServerPromptReceived>
| PartialEvent<Track.PromptCompleted>;
| PartialEvent<Track.PromptCompleted>
| PartialEvent<Track.PromptWarning>;

export type TelemetryScreenEvent = 'rovoDevSessionHistoryPicker';

Expand Down Expand Up @@ -139,6 +140,7 @@ export class RovoDevTelemetryProvider {
eventId === 'atlascode_rovoDevFileChangedAction' ||
eventId === 'rovoDevCreatePrButton_clicked' ||
eventId === 'atlascode_rovoDevRestartProcessAction' || // We want to log every restart attempt
eventId === 'atlascode_rovoDevPromptWarning' ||
// Otherwise, only allow if not fired yet
!this._firedTelemetryForCurrentPrompt[eventId]
);
Expand Down
Loading