Fix(notebook edit): Fix edit_notebook_file silently failing and repeated "file already exists" errors - #329524
Fix(notebook edit): Fix edit_notebook_file silently failing and repeated "file already exists" errors#329524George Zhao (CreatorZZY) wants to merge 16 commits into
Conversation
…ession entry creation
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Remove unused variable validIds from test case.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Attempts to improve notebook edit reliability and stale cell-ID recovery.
Changes:
- Restricts missing-file fallback to
FILE_NOT_FOUNDerrors. - Includes current notebook cell IDs in invalid-ID errors.
- Adds invalid cell-ID tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
chatEditingSession.ts |
Changes file-creation fallback handling. |
editNotebookTool.tsx |
Enriches invalid cell-ID errors. |
editNotebookTool.spec.tsx |
Tests enriched error messages. |
|
Benjamin Christopher Simmonds (@benibenj) could we please get some attention on this one? |
Fixes #327473
Problem
The built-in Copilot agent tool
edit_notebook_fileoften reports success but applies no changes when editing an existing notebook, while creating a brand-new notebook works fine. Two distinct root causes sit behind this behavior:1.
_createModifiedFileEntrymisclassifies failures and produces repeated "file already exists" errorsIn
ChatEditingSession._createModifiedFileEntry, thecatchblock assumes any failure fromdoCreate(ChatEditKind.Modified)means the file does not exist, then falls back to creating it viabulkEditService.apply({ edits: [{ newResource: resource }] })— withoutoverwrite: true. When the file does exist (e.g. the original failure was a notebook model resolution error over SSH Remote), this throwsFILE_MODIFIED_SINCE, which repeats on every streaming chunk iteration (roughly every ~10 s), flooding the chat output and logs.Bug 2: Stale cell IDs produce non-actionable errors
When the model obtains cell IDs via
copilot_getNotebookSummary, then the notebook is modified beforeedit_notebook_fileis invoked, the old cell IDs are stale and no longer present in the cell-ID map. The tool correctly rejects the request, but the error message does not include the currently valid cell IDs, forcing the model to take an extra tool call before it can self-correct.Fix
src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.tsawait this._fileService.exists(notebookUri).FILE_MODIFIED_SINCE"file already exists" loop.extensions/copilot/src/extension/tools/node/editNotebookTool.tsxgetInvalidCellErrorMessagenow accepts an optionalNotebookDocumentparameter. When a notebook is supplied, the error message includes the list of currently valid cell IDs, so the model can retry immediately with a correct ID instead of doing an extra tool call.Impact
Known limitations
Version history
Testing
chatEditingService.test.tsto cover the new exists-branch in_createModifiedFileEntry.Checklist
Fixes #327473(auto-links and closes the issue on merge).@microsoft-github-policy-service agree).