Skip to content

Commit

Permalink
Report cell execution status to Foyle. (#1745)
Browse files Browse the repository at this point in the history
* This updates the extension to report the status of the cell execution to Foyle when
  reporting execution events.

* This is highly valuable signal for the AI. This will help us from learning from
  broken/invalid commands.

* Fix jlewi/foyle#310

Co-authored-by: Sebastian Tiedtke <sebastiantiedtke@gmail.com>
  • Loading branch information
jlewi and sourishkrout authored Oct 25, 2024
1 parent ce0e743 commit c1fa5c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/extension/ai/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
LogEventsRequest,
LogEventType,
LogEvent,
LogEvent_ExecuteStatus,
} from '@buf/jlewi_foyle.bufbuild_es/foyle/v1alpha1/agent_pb'
import * as vscode from 'vscode'
import { ulid } from 'ulidx'
Expand All @@ -17,7 +18,7 @@ import * as converters from './converters'
// Interface for the event reporter
// This allows us to swap in a null op logger when AI isn't enabled
export interface IEventReporter {
reportExecution(cell: vscode.NotebookCell): Promise<void>
reportExecution(cell: vscode.NotebookCell, status: boolean): Promise<void>
reportEvents(events: LogEvent[]): Promise<void>
}

Expand All @@ -31,7 +32,7 @@ export class EventReporter implements IEventReporter {
this.log = getLogger('AIEventReporter')
}

async reportExecution(cell: vscode.NotebookCell) {
async reportExecution(cell: vscode.NotebookCell, executionSuccess: boolean) {
const contextCells: vscode.NotebookCell[] = []

// Include some previous cells as context.
Expand All @@ -58,6 +59,12 @@ export class EventReporter implements IEventReporter {
event.type = LogEventType.EXECUTE
event.cells = cells
event.contextId = SessionManager.getManager().getID()

if (executionSuccess) {
event.executeStatus = LogEvent_ExecuteStatus.SUCCEEDED
} else {
event.executeStatus = LogEvent_ExecuteStatus.FAILED
}
return this.reportEvents([event])
}

Expand All @@ -77,7 +84,7 @@ export class EventReporter implements IEventReporter {

// NullOpEventReporter is a null op implementation of the event reporter
export class NullOpEventReporter implements IEventReporter {
async reportExecution(_cell: vscode.NotebookCell) {
async reportExecution(_cell: vscode.NotebookCell, _status: boolean) {
// Do nothing
}

Expand Down
8 changes: 4 additions & 4 deletions src/extension/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,6 @@ export class Kernel implements Disposable {
}

TelemetryReporter.sendTelemetryEvent('cell.startExecute')
// todo(sebastian): rewrite to use non-blocking impl
const execCellReport = getEventReporter().reportExecution(cell)
runmeExec.start(Date.now())

const annotations = getAnnotations(cell)
Expand Down Expand Up @@ -825,10 +823,12 @@ export class Kernel implements Disposable {
successfulCellExecution = false
log.error('Error executing cell', e.message)
window.showErrorMessage(e.message)
} finally {
await execCellReport
}

// todo(sebastian): rewrite to use non-blocking impl
const execCellReport = getEventReporter().reportExecution(cell, successfulCellExecution)
await execCellReport

TelemetryReporter.sendTelemetryEvent('cell.endExecute', {
'cell.success': successfulCellExecution?.toString(),
'cell.mimeType': annotations.mimeType,
Expand Down

0 comments on commit c1fa5c9

Please sign in to comment.