mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
fix: allow compact retry after failed session compaction (#53875)
This commit is contained in:
@@ -646,7 +646,6 @@ public final class OpenClawChatViewModel {
|
||||
}
|
||||
|
||||
self.isCompacting = true
|
||||
self.lastCompactAt = Date()
|
||||
self.isLoading = true
|
||||
self.errorText = nil
|
||||
defer {
|
||||
@@ -665,6 +664,7 @@ public final class OpenClawChatViewModel {
|
||||
return
|
||||
}
|
||||
|
||||
self.lastCompactAt = Date()
|
||||
await self.bootstrap()
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
var historyCallCount: 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.")
|
||||
}
|
||||
|
||||
@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 {
|
||||
let now = Date().timeIntervalSince1970 * 1000
|
||||
let history = historyPayload()
|
||||
|
||||
Reference in New Issue
Block a user