Change:
<!-- Do Not Delete This! bugreporttemplate --<!-- Please read our Rules of Conduct: --<!-- Read our guide about submitting issues: --<!-- Search existing issues to avoid creating duplicates. --<!-- Test using the latest Insiders build to see if your issue has already been fixed: --<!-- Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. --<!-- Launch with to check. --Does this issue occur when all extensions are disabled?: Yes <!-- If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. --<!-- Issues caused by an extension need to be reported directly to the extension publisher. The 'Help Report Issue' dialog can assist with this. --- VS Code Version: 1.73.0-insider OS Version: Windows_NT x64 10.0. Auto Save by onFocusChange does not sync internal cache when direct quitting by 'X' button. Steps to Reproduce: settings: "Files: Auto Save" =onFocusChange a text file and save it somewhere. the file a little more. But this time, do not save or change focus and just press 'X' button directly to quit. the text file again with vscode. to save the file. Now you can see this error message: "Failed to save '...': The content of the file is newer." <img width="341" alt="image" src="https://user-"
That is weird, we trigger auto save on shutdown unless auto save is turned off: Does this still reproduce in all projects?
Oh nice I can reproduce, looks really like a bug.
Great catch!
Thank you for your response and effort on this issue!
<!-- AUTHORVERIFICATIONREQUEST --This bug has been fixed in the latest release of ! you can help us out by commenting if things are now working as expected. If things still don't seem right, please ensure you're on version of Insiders (today's or later - you can use in the command palette to check), and leave a comment letting us know what isn't working as expected. Happy Coding!
/verified

Discussion:
// acknowledged to shutdown and then might end up with partial backups // written to disk, or even empty backups or deletes after writes. // (https://github.com/microsoft/vscode/issues/138055) this.cancelBackupOperations(); // For the duration of the shutdown handling, suspend backup operations // and only resume after we have handled backups. Similar to above, we // do not want to trigger backup tracking during our shutdown handling // but we must resume, in case of a veto afterwards. const { resume } = this.suspendBackupOperations(); try {

// If auto save is enabled, save all non-untitled working copies // and then check again for dirty copies if (this.filesConfigurationService.getAutoSaveMode() !== AutoSaveMode.OFF) { // Save all dirty working copies

return this.handleDirtyBeforeShutdown(remainingDirtyWorkingCopies, reason); } <del> return false; // no veto (there are no remaining dirty working copies) </del> <ins> return this.noVeto([...dirtyWorkingCopies]); // no veto (dirty auto-saved) </ins> } // Auto save is not enabled

// Since a backup did not happen, we have to confirm for // the working copies that did not successfully backup try { return await this.confirmBeforeShutdown(remainingDirtyWorkingCopies); } catch (error) {

// First save through the editor service if we save all to benefit // from some extras like switching to untitled dirty editors before saving. let result: boolean | undefined = undefined; if (typeof arg1 === 'boolean' || dirtyWorkingCopies.length === this.workingCopyService.dirtyCount) { result = await this.editorService.saveAll({ includeUntitled: typeof arg1 === 'boolean' ? arg1 : true, ...saveOptions });

}, localize('revertBeforeShutdown', "Reverting editors with unsaved changes is taking a bit longer...")); } <del> private async noVeto(backupsToDiscard: IWorkingCopyIdentifier[]): Promise<boolean> { // Discard backups from working copies the // user either saved or reverted await this.discardBackupsBeforeShutdown(backupsToDiscard); return false; // no veto (no dirty) } private async onBeforeShutdownWithoutDirty(): Promise<boolean> { </del> <ins> private onBeforeShutdownWithoutDirty(): Promise<boolean> { </ins> // We are about to shutdown without dirty editors // and will discard any backups that are still

// future. Since we do not restore workspace/folder // windows with backups, this is fine. <del> await this.discardBackupsBeforeShutdown({ except: this.contextService.getWorkbenchState() === WorkbenchState.EMPTY ? [] : Array.from(this.unrestoredBackups) }); </del> <ins> return this.noVeto({ except: this.contextService.getWorkbenchState() === WorkbenchState.EMPTY ? [] : Array.from(this.unrestoredBackups) }); } private noVeto(backupsToDiscard: IWorkingCopyIdentifier[]): Promise<boolean>; private noVeto(backupsToKeep: { except: IWorkingCopyIdentifier[] }): Promise<boolean>; private async noVeto(arg1: IWorkingCopyIdentifier[] | { except: IWorkingCopyIdentifier[] }): Promise<boolean> { // Discard backups from working copies the // user either saved or reverted await this.discardBackupsBeforeShutdown(arg1); </ins> return false; // no veto (no dirty) } private discardBackupsBeforeShutdown(backupsToDiscard: IWorkingCopyIdentifier[]): Promise<void>; private discardBackupsBeforeShutdown(backupsToKeep: { except: IWorkingCopyIdentifier[] }): Promise<void>; <ins> private discardBackupsBeforeShutdown(backupsToDiscardOrKeep: IWorkingCopyIdentifier[] | { except: IWorkingCopyIdentifier[] }): Promise<void>; </ins> private async discardBackupsBeforeShutdown(arg1: IWorkingCopyIdentifier[] | { except: IWorkingCopyIdentifier[] }): Promise<void> { // We never discard any backups before we are ready // and have resolved all backups that exist. This // is important to not loose backups that have not // been handled. if (!this.isReady) { return; }

// // However, we never want to discard backups that we know // were not restored in the session. try { if (Array.isArray(arg1)) { await Promises.settled(arg1.map(workingCopy => this.workingCopyBackupService.discardBackup(workingCopy)));