-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger GhostCells On Cell Execution #1744
Conversation
894d57d
to
38e589f
Compare
@sourishkrout I'm noticing that in some cases the output doesn't get included in the Foyle request. Is this an async issue? By which I mean _doExecuteCell has been returned but the updates to the cellOutputItems haven't been applied by the time the AI fetches the document to send it. The cell gets read here vscode-runme/src/extension/ai/ghost.ts Line 109 in 90fcc5b
If the cell updates are applied asynchronously then I think there could be a race condition. |
…tors; that doesn't work. probably because the outputs aren't text editors.
…output appears to get sent at least if the cell is non-interactive.
…lls is no longer working.
…ctive cells is no longer working." This reverts commit 2d650a6.
@sourishkrout this is ready for a review. |
branch: jlewi/ghost_markup stateful#1744 Trigger GhostCells On Cell Execution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ LGTM
Is this still an issue? There is likely a chance of a race. I can't tell exactly when and where from the top of my head, though. |
* Fix * Cleanup. * Update the comment. * Try to use onDidChangeActiveTextEditors and onDidChangeVisibleTextEditors; that doesn't work. probably because the outputs aren't text editors. * Start hacking on using the notebook change event. * Success we appear to be successfully trigger when output updates and output appears to get sent at least if the cell is non-interactive. * Add comment. * Comment out changes to try to see why execution in non-interactive cells is no longer working. * Revert "Comment out changes to try to see why execution in non-interactive cells is no longer working." This reverts commit 2d650a6. * Cleanup. * Revert changes to trigger completions on doExecute. It seems redundant. * Revert examples * Revert changes to contributing.md * Add lock file --------- Co-authored-by: Sebastian Tiedtke <sebastiantiedtke@gmail.com>
Problem
Right now we trigger completion generation in response to onDidChangeTextDocument
vscode-runme/src/extension/ai/manager.ts
Line 57 in 90fcc5b
That doesn't appear to trigger in the event a user executes a cell or in response to cell output change. I assume this is because the cell outputs aren't textDocuments.
Our handler is filtering by scheme vscode-notebook-cell here https://github.com/stateful/vscode-runme/blob/90fcc5b60322b4fe34be714ac120a5794004f837/src/extension/ai/ghost.ts#L308C40-L308C60
but I added some logging and it doesn't look like that is causing update events to output cells to be dropped.
Solution
We use
vscode.workspace.onDidChangeNotebookDocument
event. This appears to be invoked for all changes to the document. We can filter that event stream to look for changes to the output items.One advantage of using this approach is that it looks to fire if the output is changing. For example if you have a long running command,
Then we want to retrigger completions when the output changes because have new information for the AI.
Record The Trigger
To enable better monitoring and troubleshooting, I've introduced an ENUM which records the event that triggers the completion. This gets attached to the request and gets logged by Foyle. This should be helpful for debugging why events were generated.
Interactive vs. Non-interactive cells
For non-interactive cells the output is included in the requests as expected. For interactive cells it is not. I suspect that is due to jlewi/foyle#286
Resolve Errors:
Occasionally I see errors like the following
I don't know if that's related to this PR. I don't think my changes should be trying to modify output items. The stacktrace indicates its coming from other parts of Runme.
Alternative solutions
I initially tried trigger suggestions from Runme's _doExecute function. _doExecute is already using the AI eventReporter to report execution. So we can just modify EventReporter.reportExecution to trigger suggestion generation by sending a cell event to the streamCreator that manages the stream of suggestions.
The problem I found with that approach is that it seems like the requests to Foyle didn't always include the actual value of stdout. I suspect there might be a race condition. Furthermore, I don't believe that approach would periodically retrigger completions in the event of a long running command where the output is being updated.
Fix jlewi/foyle#309