fix: allow compact retry after failed session compaction (#53875)

This commit is contained in:
scoootscooob
2026-03-24 11:23:42 -07:00
committed by GitHub
parent 6bef8deda9
commit 3a4cc89c53
2 changed files with 51 additions and 1 deletions

View File

@@ -646,7 +646,6 @@ public final class OpenClawChatViewModel {
} }
self.isCompacting = true self.isCompacting = true
self.lastCompactAt = Date()
self.isLoading = true self.isLoading = true
self.errorText = nil self.errorText = nil
defer { defer {
@@ -665,6 +664,7 @@ public final class OpenClawChatViewModel {
return return
} }
self.lastCompactAt = Date()
await self.bootstrap() await self.bootstrap()
} }

View File

@@ -221,6 +221,19 @@ private actor AsyncGate {
} }
} }
private actor AsyncCounter {
private var value: Int
init(_ initialValue: Int = 0) {
self.value = initialValue
}
func increment() -> Int {
self.value += 1
return self.value
}
}
private actor TestChatTransportState { private actor TestChatTransportState {
var historyCallCount: Int = 0 var historyCallCount: Int = 0
var sessionsCallCount: Int = 0 var sessionsCallCount: Int = 0
@@ -1033,6 +1046,43 @@ extension TestChatTransportState {
#expect(await MainActor.run { vm.errorText } == "Please wait before compacting this session again.") #expect(await MainActor.run { vm.errorText } == "Please wait before compacting this session again.")
} }
@Test func compactTriggerAllowsImmediateRetryAfterFailure() async throws {
let history = historyPayload()
let attemptCount = AsyncCounter()
let (transport, vm) = await makeViewModel(
historyResponses: [history],
compactSessionHook: { _ in
let next = await attemptCount.increment()
if next == 1 {
throw NSError(
domain: "TestCompact",
code: 42,
userInfo: [NSLocalizedDescriptionKey: "temporary failure"])
}
})
try await loadAndWaitBootstrap(vm: vm)
await MainActor.run {
vm.input = "/compact"
vm.send()
}
try await waitUntil("first compact attempted") {
await transport.compactSessionKeys() == ["main"]
}
#expect(await MainActor.run { vm.errorText } == "Unable to compact the session. Please try again.")
await MainActor.run {
vm.input = "/compact"
vm.send()
}
try await waitUntil("second compact attempted") {
await transport.compactSessionKeys() == ["main", "main"]
}
#expect(await MainActor.run { vm.errorText } == nil)
}
@Test func bootstrapsModelSelectionFromSessionAndDefaults() async throws { @Test func bootstrapsModelSelectionFromSessionAndDefaults() async throws {
let now = Date().timeIntervalSince1970 * 1000 let now = Date().timeIntervalSince1970 * 1000
let history = historyPayload() let history = historyPayload()