-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(desktop): avoid fault reset journal double-clear #10019
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
Merged
Git-on-my-level
merged 1 commit into
BasedHardware:main
from
Git-on-my-level:fix/fault-reset-double-clear-v12082
Jul 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.github/scripts/product_file_line_count_ratchet_baseline/desktop-swift-providers.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 53 additions & 2 deletions
55
desktop/macos/Desktop/Sources/Providers/ChatProvider+HarnessReset.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,72 @@ | ||
| import Foundation | ||
|
|
||
| extension ChatProvider { | ||
| /// Harness-only chat reset that awaits backend deletion before returning. | ||
| /// Returns an error message when backend deletion fails so E2E flows don't | ||
| /// proceed against stale persisted messages. | ||
| func automationResetChatForHarness() async -> String? { | ||
| guard AppBuild.isNonProduction else { return nil } | ||
| return await resetChatForAuthorizedHarness() | ||
| } | ||
|
|
||
| /// Completes a harness reset after its non-production automation entrypoint | ||
| /// has established eligibility. The main-chat transaction sets | ||
| /// `defaultJournalAlreadyCleared` only after its authoritative owner-scoped | ||
| /// control clear has succeeded. | ||
| func resetChatForAuthorizedHarness(defaultJournalAlreadyCleared: Bool = false) async -> String? { | ||
| isClearing = true | ||
| defer { isClearing = false } | ||
|
|
||
| if isInDefaultChat { | ||
| let runtimeChatId = mainChatRuntimeChatId(sessionId: nil) | ||
| let surface = AgentSurfaceReference.mainChat(chatId: runtimeChatId) | ||
| AgentRuntimeStatusStore.shared.clear(surface: surface) | ||
| if !defaultJournalAlreadyCleared { | ||
| guard await kernelTurnProjection.clear(surface: surface) else { | ||
| return "failed to clear default kernel journal" | ||
| } | ||
| } | ||
| } else { | ||
| let sessionToDelete = currentSession | ||
| if let session = sessionToDelete { | ||
| let surface = AgentSurfaceReference.mainChat(chatId: session.id) | ||
| AgentRuntimeStatusStore.shared.clear(surface: surface) | ||
| guard await kernelTurnProjection.clear(surface: surface) else { | ||
| return "failed to clear session kernel journal" | ||
| } | ||
| } | ||
| if let session = sessionToDelete { | ||
| sessions.removeAll { $0.id == session.id } | ||
| } | ||
| currentSession = nil | ||
| messages = [] | ||
| resetMessagesPagination() | ||
| _ = await createNewSession() | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| /// Reset isolation must clear the same kernel-owned surface the flow will | ||
| /// exercise. Fault bundles intentionally have no authenticated owner, so | ||
| /// establish a temporary non-production owner for this transaction rather | ||
| /// than bypassing the owner boundary or carrying a synthetic session forward. | ||
| func automationResetMainChatForHarness() async -> String? { | ||
| guard AppBuild.isNonProduction else { return nil } | ||
| return await performMainChatHarnessResetTransaction() | ||
| } | ||
|
|
||
| /// Performs the owner-scoped reset transaction after the automation entrypoint | ||
| /// has established that the bundle is non-production. | ||
| func performMainChatHarnessResetTransaction() async -> String? { | ||
| let bundleScope = (Bundle.main.bundleIdentifier ?? "desktop") | ||
| .replacingOccurrences(of: ".", with: "-") | ||
| let resetOwnerID = "desktop-harness-reset-\(bundleScope)" | ||
| return await RuntimeOwnerIdentity.withAutomationOwnerIfMissing(resetOwnerID) { [self] in | ||
| let clear = await automationClearOwnerSurfaceState(chatId: "default") | ||
| let clear = await clearOwnerSurfaceStateForAuthorizedHarness(chatId: "default") | ||
| if let error = clear["error"] { | ||
| return error | ||
| } | ||
| return await automationResetChatForHarness() | ||
| return await resetChatForAuthorizedHarness(defaultJournalAlreadyCleared: true) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
desktop/macos/changelog/unreleased/20260719-fault-reset-double-clear.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "change": "Improved beta chat recovery when authentication fault checks run" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When a test/fault flow runs while an app is selected,
mainChatRuntimeChatId(sessionId: nil)resolves the visible default chat todefault|<appId>, but the preceding owner clear only targetschatId: "default". PassingdefaultJournalAlreadyCleared: truehere then skipskernelTurnProjection.clearfor the actual app-scoped surface, andresetJournalProjectionignores the default-surface clear because it does not matchmainChatSurfaceReference(), soreset_main_chatcan report success while leaving the selected app chat/journal stale.Useful? React with 👍 / 👎.